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?

  • Björn Tantau@swg-empire.deOP
    link
    fedilink
    arrow-up
    3
    ·
    1 day ago

    Why would you reserve ram for swap???

    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.

    Monitor queries to ensure you’re not seeing table scans due to missing indexes.

    There are definitely some unoptimised queries and missing indexes. Lemmy 1.0 will supposedly fix a lot of them.

    • non_burglar@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      17 hours ago

      If you put swap in zram, you are paging from RAM to RAM. May as well just not use swap and save the cycles.

      • BB_C@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        16 hours ago

        The point is compression.

        % swapon
        NAME           TYPE      SIZE USED  PRIO
        /dev/nvme0n1p2 partition   8G   0B     5
        /dev/sda2      partition  32G   0B    -2
        /dev/zram1     partition 3.5G 1.8G 32767
        /dev/zram2     partition 3.5G 1.8G 32767
        /dev/zram3     partition 3.5G 1.8G 32767
        /dev/zram4     partition 3.5G 1.8G 32767
        /dev/zram5     partition 3.5G 1.8G 32767
        /dev/zram6     partition 3.5G 1.8G 32767
        /dev/zram7     partition 3.5G 1.8G 32767
        /dev/zram8     partition 3.5G 1.8G 32767
        
        % 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>
        
        • non_burglar@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          16 hours ago

          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.

          • BB_C@programming.dev
            link
            fedilink
            arrow-up
            2
            ·
            16 hours ago

            zswap is not better than modern zram 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.