Yeah, I’ve seen that exact article,
“Even though they claim that this feature improves system responsiveness, in reality, Memory Compression slows everything down.”
Yeah, totally, a bunch of engineers created a feature to slow down a system. And this, in his mind, makes total sense.
Actually, after reading a few of his musings years ago, I’ve blocked that resource from appearing in my search results with uBlacklist . (highly recommend this plugin – works with most search engines, and over time will make your search experience much better by eliminating spammy content farms from appearing in your search results)
Anyway, very briefly:
Memory is managed in blocks, called “pages”. If the applications or OS services need more ram than available, the page manager saves the least recently used pages to disk, to free up space in ram for new allocations. Then, if the application whose data has been paged out to disk tries to read that data – an exception, called Page Fault, is generated – because that page is no longer in ram. That is intercepted, additional memory is freed (likely by moving pages belonging to other apps to disk), requested pages from disk are read back into ram, and the read request is retried, this time succeeding.
Because this involves reads from disk – it’s very slow.
When memory compression is enabled, instead of paging data to disk to free space, data is compressed in-place, with a very fast compression algorithm like LZO, LZ4, or ZSTD. This has virtually no impact on CPU utilization, any modern CPU won’t even notice extra workload.
Compressing memory, however, is orders of magnitudes faster than writing and reading stuff to disk. Hence, if your system is under such stress that it has to keep paging in and out all the time, enabling memory compression will help improve performance.
So worrying about extra CPU cycles is moot: the alternative is to have the CPU be stalled on an IO request waiting for the read from disk, for orders of magnitude longer.
My second point was, however, that if you find your system struggling to find free ram – it does not matter what you do, it’s too late, you need to add more physical ram, because you want to have free unused ram available for file system cache.
Wouldn’t this make the statement in the article advising to disable memory compression and add ram instead true? No. Because there is no reason to disable memory compression. Depending on the implementation, compressing old very infrequently used pages in ram can help free up even more ram, for the benefit of the disk cache, that ultimately significantly improves performance.