Hello everyone. Last week I didn’t do any coding in my free time, but I was messing around with various optimizations on my computers, so I’m going to tell you about them.
My work laptop currently has 16 GB of RAM onboard. As it turns out, 16 GB is already quite little in 2025. Docker, Electron, and IntelliJ were eating up all the memory. Therefore, I started thinking about how to maximize memory optimization on Linux.
ZSWAP
I consider this optimization extremely useful and keep it permanently enabled. The essence of the optimization is that the swap file is stored on the disk in a compressed state. It would be convenient if Linux turned this optimization on by default for all computers meeting minimum system requirements, but unfortunately, it doesn’t.
ZRAM
A questionable optimization; I didn’t like it. There are two reasons:
- First, you have to allocate a certain fixed amount of memory for ZRAM. How much? No one knows. You can do 30%, 50%, or 70%. But how much [exactly]? It turns out ZRAM ends up reducing my overall available memory slightly.
- Second, if you already have ZSWAP, why add ZRAM on top of it? Besides, they conflict with each other, and incorrect statistics are shown when both are enabled.
Kernel Same Page Merging (KSM)
A very subtle optimization that is quite difficult to configure. Memory pages with identical content are merged into one. It occurred to me that this optimization should be very useful because Electron apps and browser tabs all run on WebKit, so they could all be merged… But in practice, we get 500 MB of compression on 20 GB of memory. That’s about 2.5%. On one hand, it’s small. On the other hand, free memory comes from nowhere—pretty cool, right? I’m keeping this optimization enabled for now. However, when the laptop is running on battery, this optimization makes no sense because it loads the CPU in the background.
BTRFS
There is automatic compression for the filesystem. Unfortunately, there is no simple way to enable it via a GUI; you have to dig into the terminal. (In Windows, it can be done with one click in disk properties). I enabled compression for my entire drive, and the profit is quite decent.
Summary:
- ZSWAP 🟢 always enable, except for very old, weak computers.
- ZRAM 🟡 optional, but is it necessary?
- KSM 🟡 optional, but only not on laptops [on battery].
- BTRFS 🟢 always enable compression, except for very old, weak computers, of course.
That’s all for now. This week I plan to push myself on LeetCode 🥵💻 and reach problem number 200.