In my relentless pursuit of trying to coax more performance out of my Lemmy instance I read that PostgreSQL heavily relies on the OSs disk cache for read performance. I’ve got 16 GB of RAM and two hdds in RAID 1. I’ve PostgreSQL configured to use 12 GB of RAM and I’ve zram swap set up with 8 GB.
But according to htop PostgreSQL is using only about 4 GB. My swap gets hardly touched. And read performance is awful. Opening my profile regularly times out. Only when it’s worked once does it load quickly until I don’t touch it again for half an hour or so.
Now, my theory is that the zram actually takes available RAM away from the disk cache, thus slowing the whole system down. My googling couldn’t bring me the answer because it only showed me how to set up zram in the first place.
Does anyone know if my theory is correct?
It’s a useful way of squeezing out a few GB more. Worked wonders on my starved Steam Deck and allowed me to play Cities Skylines smoothly and without crashes.
But on a DB heavy server that is apparently not a good idea. I’ve switched to a swap file.
There are definitely some unoptimised queries and missing indexes. Lemmy 1.0 will supposedly fix a lot of them.
If you put swap in zram, you are paging from RAM to RAM. May as well just not use swap and save the cycles.
The point is compression.
% zramctl NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram8 zstd 3.5G 293.4M 189.2M 192.5M [SWAP] /dev/zram7 zstd 3.5G 282.1M 187.5M 192M [SWAP] /dev/zram6 zstd 3.5G 284.6M 189.4M 192.9M [SWAP] /dev/zram5 zstd 3.5G 297.8M 197.3M 200.1M [SWAP] /dev/zram4 zstd 3.5G 304.9M 202.9M 206.7M [SWAP] /dev/zram3 zstd 3.5G 300.7M 201.9M 204.6M [SWAP] /dev/zram2 zstd 3.5G 311.3M 207.2M 210.6M [SWAP] /dev/zram1 zstd 3.5G 307.9M 210.5M 213.3M [SWAP] /dev/zram0 zstd <not used for swap>
zswap is specifically built to this end and far better suited to it.
zram is great, but it is simply a ramdisk and inappropriate to ops task. It cannot dynamically grow/shrink or deal with hot/cold pages.
zswap
is not better than modernzram
in any way. And you can set up the latter with writeback anyway.But that’s not OP’s problem since “swap gets hardly touched” in OP’s case.