Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a netbook with a very slow (especially on writes) SSD, would it be a good idea to go without swap? The way I see it is that code and unmodified pages will still be swapped (re-read) but I won't be writing anything. Plus, I was also thinking about disabling file-system cache in order to free up some more memory and have a bit more control on when the disk is accessed.

Your thoughts?

EDIT: I agree that disabling fs cache would increase disk access, however what matters most to me is to minimize disk writes, which shouldn't be affected I believe. Is there any way to keep fs cache and at the same time forcing writes immediately (let's say I want to prevent data loss on a power failure)? Also it is worth noting that being it a netbook physical ram is limited to 1.5Gb

share|improve this question
7  
Without swap, instead of things being "slower" when your RAM is exhausted, they will crash. Without filesystem cache, the disk will be accessed more, not less. –  jordanm Nov 6 '12 at 16:42

6 Answers 6

No swap means that applications will crash if you run out of RAM. With swap, you get a warning because your system gets slow first.

No swap also means that application memory cannot be swapped out to make room for disk cache. On a typical system, there are several rarely-needed background processes or parts of processes that aren't needed for large periods of time. It is better for performance to let these pages be swapped out to make room for more disk cache.

If you solely want to minimize disk writes, then disabling swap is a step in the right direction. This will usually reduce performance: second-guessing the kernel when it comes to that is almost always counterproductive. Minimizing disk writes to prolong the lifetime of an SSD is largely illusory: it would take an unusual amount of activity to have the drive start becoming read-only before it fails for some other old-age reason or becomes utterly obsolete.

Swap is necessary for hibernation. You need to have at least as much swap as the virtual memory occupied by application data at the time of hibernation (i.e. the “-/+ buffers/cache” line of the free output), plus a few megabytes for the kernel .

share|improve this answer
    
About the rarely needed processes (or part of processes), won't the swapper just unload them for memory and reload them from disk on page fault? If it works like I think it does there should be no difference between reading them from the original file or from the swap. –  capitano666 Nov 8 '12 at 17:43
    
@capitano666 That's what happens for data read from a file (including code). That doesn't get swapped (because it would be pointless to write something to swap when it's already on the disk). I meant the runtime data, i.e. the process's read-write memory, which isn't disk-backed. –  Gilles Nov 8 '12 at 18:04

I have an hp mini 1000 netbook which I have been using for a few years now (3, maybe 4) which has a very early model 8GB ssd and 1GB of ram.

I have always opted to not use a swap partition in order to minimise disk writes and it has never caused me issues despite rather heavy compiling (I work as a developer and often compile the Linux kernel).

However I do use a minimal window manager and not many large applications (most of my work is from the terminal) so this has probably helped.

There is a great article on the archwiki covering this topic.

share|improve this answer
    
Thanks, this is actually my profile (except for the fact that I managed to upgrade to 1.5Gb of ram). Maybe for heavy compiling I would consider the possibility to create a temporary swapfile just to be protected from out of memory kills. My real issue is the fact that the damned disk hangs the whole system while doing a big write. –  capitano666 Nov 8 '12 at 17:47

Just so you have an answer from someone who experienced it - I hacked my prototype chrome book with Ubuntu and later Bodhi linux, and did not use swap on it (since it only had a 16gig drive). It had 2gb of ram, and never gave me an issue, be it browsing, compiling android kernels, or using Eclipse.

That being said, if your hard drive is bigger, then I suggest just using some swap. Ram is cheap, but SSD's aren't exactly expensive today either. I think it's still very beneficial.

share|improve this answer
    
Sadly I'm limited in both ram and disk by the netbook's motherboard and form factor. –  capitano666 Nov 8 '12 at 18:22
    
well bodhi did fantastic on my chromebook with 2/16. It looks good and it's very customizable despite its small footprint on ram and disk. –  Drake Clarris Nov 8 '12 at 19:02

Compiling some C++ applications may easily use huge amounts of memory, which makes swapping handy, even on modern computers.

share|improve this answer
1  
I can also add that without swap, compiling large applications can result in the kernel asking you to consider sacrificing your child: "Out of memory: Kill process 4135 (firefox) score 119 or sacrifice child", "Killed process 4135 (firefox) total-vm:1407964kB, anon-rss:481936kB, file-rss:168kB" –  Alexander Nov 9 '12 at 1:31

These days swap is largely an anachronism. I recommend not running with swap ever. Ram is cheap and disk is slow and the that slowness has become so great these days ( disks have only tripled in speed while ram has become 100 times faster ) that if you do ever actually start swapping the system will become unusable. If you don't have enough ram to run what you want to run, you just need to add more, not swap to disk.

You also can't disable the fs cache and it only uses memory that otherwise is free.

share|improve this answer
    
Unfortunately I'm unable to increase RAM above 1.5Gb, I whould have specified this constraint. About the "only uses memory that otherwise is free", as far as I'm aware Linux tries to maximize memory usage by filling it asap, am I wrong? –  capitano666 Nov 6 '12 at 16:59
    
Swap is required to suspend. –  jordanm Nov 6 '12 at 18:17
2  
@jordanm, no, it is only required to hibernate, not suspend. –  psusi Nov 6 '12 at 18:45
1  
@capitano666, yes, that would be wrong. The kernel tries to cache recently accessed files using whatever memory is otherwise not in use. –  psusi Nov 6 '12 at 18:46
    
I agree. If you have to use swap, there is something wrong. That thing going wrong, could be java, though ;-/ –  Nils Nov 7 '12 at 21:40

Without swap, applications will be killed (rather than being swapped) if you run out of memory; you will also have more slowdown if you disable filesystem caching, as it will need to read the disk more.

As for the swap requirement, you might be able to avoid it (or use a small swap) if you max out the RAM on your machine.

share|improve this answer
    
I'm actually ok with applications being killed, that happens anyway once the swap is full. What matters most to me is minimize disk writes. –  capitano666 Nov 6 '12 at 17:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.