Linux, SSD and swap

This article suggests not to create a swap space on an SSD drive in order to reduce its wear. On the other hand, it suggested here that swap space positively affects performance.

Would it be a better option to drop swap? Or maybe some swappiness tweaks could let us have the cake and eat it. The device is ASUS T200TA, the only sure drive is a 32GB eMMC (the HDD is detachable) and has only 2GB RAM.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Note that Linux gained a zRAM feature sometime in the past few years. It’s a compressed ramdisk that can be used for swap space, i.e. to compress inactive memory content. The Gentoo Wiki entry on it claims it can achieve a compression ratio of around 3:1.

It sounds worth considering for any desktop with less than ideal ram (4GB is ideal for most current desktop environments). Microsoft started doing the same in Windows 8 (plus Windows Phone at some point, also some Android phones use zRAM).

zRAM requires some manual configuration, but at least for Ubuntu there are packages that will set it up automatically. You might need to investigate a little if you want to run normal swap as well with a lower priority (and whether that works well at all?!). The zram-config package is available from the ubuntu repos. Apparently Fedora 21 will enable zRAM automatically if you have 2GB or less.

Method 2

If performance is good – you’re not having to wait while switching between apps, with the disk thrashing and the activity LED solid on – then there isn’t going to be a lot of wear to worry about either.

You could allocate a 2G space for swap at install time, and later tune the partition/swap size down e.g with GNOME Disks. Personally I would try 512M or 1G to start with. I assume you’re not thinking about hibernation (which would usually want 2G+ swap).

Then I could see how much swap I used, and if I hit problems with out-of-memory or slowdowns with full swap. I confess I’m not sure how I’d distinguish thrashing the swap (too much active apps, enabled by too much swap) v.s. the cache (not enough swap to page out inactive app memory). In both cases you’d see the disk light on and pretty full swap. Maybe vmstat 1 and watch the swap column, if I could test a problem case reliably.

I would be cautious about 2GB swap on an eMMC (lower performance than expensive SSDs). Linux desktop memory management has a somewhat checkered history, and the swapping won’t have been designed for eMMC.

If you use all that swap you may find the machine’s become literally unusable anyway. Running out of memory can be better because you get the machine back without rebooting. Though it may kill programs you wanted & expected to survive.

My GNOME shell with a few apps has about 1G “used” (swapable) plus 1G+ “cached” (read-only data/code, can just be re-read from filesystem).

If you had punted 1G to swap, how long would it take to swap all that back, given your eMMC? (GNOME Disks can benchmark partitions for you :). E.g. 10 seconds to read it? Then if you’re swapping the previous working set out at the same time, the (slower) writes on the eMMC are going to take even longer. Doesn’t sound great to me.

One small reason for swap is tmpfs. My /run accumulates a meg or so, I doubt all needs to be in ram.

Method 3

I wouldn’t bother and go ahead with a 2GB swap partition.
You must always have some swap especially with “only” 2GB RAM which is rather sufficient with Linux and a light DE like LXDE or Xfce as long as you do have 2GB swap (or if you don’t use any browser, don’t compile anything or do anything that eat a lot of RAM!).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x