Configuring zram and zswap parameters for optimal performance

I am currently using 16gb ram + zram + zswap (with 50gb dedicated swap partition) on an intel machine and would like to get opinion on the strategy to employ when adjust the configuration parameters for zram and zswap for optimal performance. Below are the available parameters for each:

Am open to any other feedback pertaining to this. Heres how I currently get both zswap and zram setup:

{ config, pkgs, ... }:


{
systemd.services.zswap = {
  description = "Enable ZSwap, set to LZ4 and Z3FOLD";
  enable = true;
  wantedBy = [ "basic.target" ];
  path = [ pkgs.bash ];
  serviceConfig = {
    ExecStart = ''${pkgs.bash}/bin/bash -c 'cd /sys/module/zswap/parameters&& \
    echo 1 > enabled&& \
    echo 20 > max_pool_percent&& \
    echo lz4 > compressor&& \
    echo z3fold > zpool'
    '';
  Type = "oneshot";
  };
};

  zramSwap.enable = true;

}
  1. Use either zram or zswap but not both. See Zram - LinuxReviews
  2. Personally I played around with this years ago and ultimately decided to stick with zram, as it’s simpler, won’t wear out the SSD, and it’s very fast.
    This is as easy as:
  zramSwap = {
    enable = true;
    algorithm = "zstd";
    memoryPercent = 30;
  };

No extra services needed.
YMMV but give it a try.

2 Likes

@mausch Thanks man will experiment with it. The only thing in my case is I have a 50gb swap partition for hibernation so would make sense to use zswap to leverage on that partition. But I agree that both should not be used at the same time after doing abit of my own research.