/etc insider

since 1999 (and still editing)

Dealing with tight RAM on Linux

| Comments

Well, as the title suggest you can do something to have smoother experience when you just can’t plug more RAM into your laptop or desktop.

From the ground up it’s the choice of the distro and architecture: prefer x86, not x86_64. If you had tried x86 and x86_64 versions of your distro on same laptop with 2 GB you already know that advice. x86_64 is superior technology, no doubts, but alas its drawback binaries are noticeable bigger and their memory apetite is bigger too.

Use swap, so anything that can be swapped out due to inactivity, would be swapped out. Don’t use big swap partition with memory overcommit setting. Swap is good for RAM saving, but disk thrashing due to swap can last way too long so you lose your nerve and may even come up with a vain desire to turn off the swap altogether.

Optimize things that can’t be swapped out. Some kernel sub-systems can be taught to be less memory-wasting, for e. g.:


being given as kernel’s parameter would save some RAM indeed.

Try using pre-swap compressing in RAM:

zswap.enabled=1 zswap.compressor=deflate

ZSWAP allocates some pre-disk-swap buffer in RAM (its size can be configured too), and to make this RAM-effective its content should be compressed, otherwise there’s no point, right? The better it’s compressed, the more sense there’s to “waste” RAM for that buffer, so that’s why I recommend using deflate compression method. Generally, processors became way too fast for long time and if you have any opportunity to trade CPU cycles for cutting down disk activity, go for it! No need for LZO or LZ4 if you really want to hit disks less often.

Use UltraKSM. People who read this blog should be already aware of that. It’s a pity uKSM doesn’t get its way into vanilla kernel yet, but you know where to get it.

Use alternative memory allocators system-wide. For e. g., you can try jemalloc which is known for its great memory fragmentation durability that makes sense over the time. You may have noticed that over the time your system can become more and more sluggish. Should you only re-start your session and things can be faster again. With jemalloc you can find those restarts are needed less frequently.