Hello everyone. Last week I didn't code during my free time, but I tinkered with various optimizations on my computers, so let's talk about those.
My work laptop currently has 16GB of RAM onboard. As it turns out, 16GB in 2025 is already considered low. Docker, Electron, and IntelliJ ate up all the memory. So I thought about how to maximize memory optimization on Linux.
ZSWAP
I believe this is the most useful optimization, and I keep it enabled all the time. The idea behind it is that the swap file is stored on the disk in compressed format. It would be convenient if Linux automatically enabled this optimization for all computers meeting minimum system requirements, but that's not the case.
ZRAM
I found this optimization questionable and didn't like it. There are two reasons:
- First, you have to allocate a fixed amount of memory for ZRAM. How much? No one knows. It could be 30%, 50%, or 70%. But giving up some of my total RAM reduces the effectiveness of ZSWAP.
- Second, if ZSWAP is already enabled, then why use ZRAM as well? They conflict, and the statistics show incorrect values when both are active.
Kernel Same Page Merging (KSM)
A very clever optimization that's hard to configure. Pages of memory with identical content are merged into one. I thought this should be incredibly useful since programs on Electron and browser tabs all run on Webkit, so combining them would make sense... But in practice, I only get about 500MB compression out of 20GB of RAM, which is only 2.5%. While that's not much, it's nice to have extra free memory.
I'm keeping this optimization enabled for now but if my laptop runs on battery power, it doesn't make sense as it loads the CPU in the background.
BTRFS
There's automatic compression for the file system. Unfortunately, there's no simple way to enable it through the GUI; you have to use the terminal (which is easy in Windows where you can do this with a single click in disk properties). I enabled compression on my entire disk and saw a significant gain.
Conclusion:
- ZSWAP ✅ Always enable, except for very old and underpowered computers
- ZRAM 🚫 Maybe, but is it really needed?
- KSM 🚫 Only if you're not using a laptop on battery power
- BTRFS ✅ Always enable compression, again except for very old and underpowered computers
That's all for now. This week I plan to focus on LeetCode 🥵💻 and aim to reach problem number 200.