Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"this disables swap entirely, which I think is virtuous" -- sigh.

Swap isn't some artifact from the days of 640k, used only because memory is expensive. Shit is always stored on disk; swap just allows that shit to be unused pages of active programs rather than actively used pages of files on disk.

Without swap, you force the kernel to prioritize cold code paths of rarely used daemons over, say, your web browser's cache. That's just dumb.



For a desktop with sufficient amount of memory swap is just bad from my experiences. When i was using swap on my desktop system, which i usually have running 24/7, i'd often come back in the morning to find that linux decided to swap out my X session or something stupid like that. How much of my 16GB memory will a "rarely used daemon" use? Insignificant compared to how annoying it is to have to wait for your interactive applications to be swapped in when that happens.


It sounds like you had a process running over night that needed enough memory to force X (or whatever) to swap. Without the swap, that memory-hungry process would presumably have run less optimally (if it got memory allocation failures and adjusted its behavior to utilize less memory) or it would have simply died. It's not so clear that having processes die because they can't get memory is better than having something else run slowly, in general.

Edit: Possible caveat: Maybe whatever was running overnight did a lot of disk I/O and the OS decided to cache it at the expense of moving idle processes to swap (not sure if Linux does that or not).


"Maybe whatever was running overnight did a lot of disk I/O and the OS decided to cache it at the expense of moving idle processes to swap (not sure if Linux does that or not)."

In my experience (Ubuntu 9.10, kernal 2.6.31), with the default settings it does not do this during intensive disk I/O unless there is very little free memory to start with.

In other words, if the system is not low on memory to start with, I can start a bunch of processes that read and/or write multiple terabytes of data and when I come back the next morning little or no additional swap will have been consumed.


How much swap space should you allocate for e.g. 16GB RAM?

Every reference I've read suggests there's no need for swap space once you have more than ~2GB of RAM, but I find that extremely hard to believe.


I find this an interesting, common, conceptual misunderstanding.

When somebody asks this question, he always thinks this way:

- I have a system "A" with x GB of ram, with y GB of swap. - I have a system "B" with x+y GB of ram, and no swap, because it has all the virtual memory A is using.

well, the problem is that one should not compare system B with system A, he should compare system B with system C:

- I have a system "C", with x+y GB of ram, and z of swap.

system C will perform potentially better than B.

The generic explanation is that the kernel may decide that it's better to swap out some data, and use the space for caching purposes. This is a concept, that within limits, it's not related to the amount of RAM.


As long as 'z' is not proportional to x or y that might be fine. If you consider 'z' as a percentage of your RAM then you'll notice that your expensive server with lots of RAM is way slower than a cheap one with small RAM and smaller swap, just because it takes less time for the kernel to fill the swap and finally kill the offending process.


I'd allocate swap on the order of how much RAM your applications use. So if they need 2 GB of RAM to be comfortable, 1-4 GB of swap will give them room to be paged out when necessary. In most situations disk space is cheap, so erring on the side of too much won't hurt.


If you plan to hibernate, I believe you need at least 16GB of swap (i.e. the amount of memory you have).


You don't need swap as big as the amount of memory to hibernate. https://wiki.archlinux.org/index.php/Suspend_and_Hibernate#H...


I turned off swap on my desktop. Even if you have a lot of RAM swap just becomes an annoyance during development. Sooner or later you have some runaway process eating up all the memory. If the system starts swapping it will take a long time to recover (unless you're lucky enough to hit Ctrl-C within a few seconds and the app responds to it). Even with swap off there are long pauses when the system is low on memory, maybe it just waits too much before the OOM killer kicks in, but its more usable than with swap on.


Unless you care about latency. Just because an indexer ran through my hard drive doesn't mean I should have to wait 60+ seconds next time I log in for everything to page back into memory.


I haven't had this experience in 10 years of using a desktop system that updates the locate DB every night.


Since we are sharing Anecdata, my experience is quite the opposite of yours. SSDs might be the middle path here.


Nah, I cultivate Chrome tabs. After sleeping my computer for a month, playing games, running VM's, doing clojure programming, etc; I found switching to an old Chrome tab or maximizing that Clojure book I hadn't looked at in 3 weeks would cause quite the pause. This is with SSD's all the way down.


locate indexer cronjob should never be enabled on a production box. Problem solved.


If you think swap introduces latency, you need to learn a lot about memory management.


So, if your working set (files, application memory, etc) fits in memory, how does swap not introduce latency?


Some pages of memory in your working set may be rarely used. If so, then allocating physical pages of memory may be a waste. The kernel may be able to get better performance by using those pages for the disk cache - decreasing latency by hitting the disk less.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: