Tmpfs not swapping to zram when reaching fullness

My scenario is that I am building with makepkg at /tmp/makepkg (mounted as tmpfs with default options). I have 32GB ram installed, default options for tmpfs (so 16GB in size therefore) and 16GB zram with higher swap-prio mounted.
I also set vm.swappiness=160. Documentation for sysctl.vm.swappiness [0] says:

For in-memory swap, like zram or zswap, as well as hybrid setups that have swap on faster devices than the filesystem, values beyond 100 can be considered. For example, if the random IO against the swap device is on average 2x faster than IO from the filesystem, swappiness should be 133 (x + 2x = 200, 2x = 133.33).

Therefore I can calculate recommended swappiness with zram as:
swappiness = 200 * io_ram / (io_disc + io_ram)

With the system data from inxi:

inxi output
 ▲ ~ sudo inxi -zxxxSDmja
System:
  Kernel: 5.15.8-1-NAIAD x86_64 bits: 64 compiler: clang v: 13.0.0
  Desktop: GNOME 41.2 tk: GTK 3.24.30 wm: gnome-shell dm: GDM 41.0
    Distro: Manjaro Linux base: Arch Linux
Memory:
  RAM: total: 31.32 GiB used: 19.14 GiB (61.1%)
  Array-1: capacity: 128 GiB slots: 2 EC: None max-module-size: 64 GiB
    note: est.
  Device-1: DIMM_A1 size: 16 GiB speed: 3600 MT/s type: DDR4
    detail: synchronous unbuffered (unregistered) bus-width: 64 bits
    total: 64 bits manufacturer: Crucial Technology
    part-no: BL16G36C16U4B.M8FB1 serial: <filter>
  Device-2: DIMM_B1 size: 16 GiB speed: 3600 MT/s type: DDR4
    detail: synchronous unbuffered (unregistered) bus-width: 64 bits
    total: 64 bits manufacturer: Crucial Technology
    part-no: BL16G36C16U4B.M8FB1 serial: <filter>
Drives:
  Local Storage: total: 1.82 TiB used: 537.75 GiB (28.9%)
  ID-1: /dev/nvme0n1 maj-min: 259:3 vendor: Samsung model: SSD 980 PRO 1TB
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B
    speed: 63.2 Gb/s lanes: 4 type: SSD serial: <filter> rev: 3B2QGXA7
    temp: 53.9 C scheme: GPT
  SMART: yes health: PASSED on: 44d 10h cycles: 343
    read-units: 16,141,433 [8.26 TB] written-units: 11,729,206 [6.00 TB]
  ID-2: /dev/nvme1n1 maj-min: 259:0 vendor: Samsung model: SSD 980 PRO 1TB
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B
    speed: 63.2 Gb/s lanes: 4 type: SSD serial: <filter> rev: 3B2QGXA7
    temp: 52.9 C scheme: GPT
  SMART: yes health: PASSED on: 63 hrs cycles: 343
    read-units: 1,945,923 [996 GB] written-units: 5,414,104 [2.77 TB]
Swap:
  Kernel: swappiness: 160 (default 60) cache-pressure: 100 (default)
  ID-1: swap-1 type: file size: 16 GiB used: 0 KiB (0.0%) priority: 10
    file: /swapfile
  ID-2: swap-2 type: zram size: 15.66 GiB used: 251 MiB (1.6%)
    priority: 100 dev: /dev/zram0

I get io_ram = 3600 MT/s = 230.4 Gb/s and io_disc = 63.2 Gb/s, therefore:
swappiness = 200 * 230.4 / (230.4 + 63.2) = 156.9482289 ~= 160

My problem now is that I still run into a No space left on device error during build (in this case I tried building linux515 package), while free says that swap is unused / has 32Gi free.
My expectation here would be that kernel starts swapping from the tmpfs into zram before it runs out of memory, kernel documentation for tmpfs [1] also indicates support for this.

Please advice if I have setup error or simply an understanding problem here. Thank you.


[0] https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/vm.rst#swappiness
[1] https://www.kernel.org/doc/html/latest/filesystems/tmpfs.html

Even if you would see swapping, the tmpfs size still only is 16GB and would not change. If your build fills up those 16GB no ammount of swapping would help - the device would still be full.

1 Like

Yes that makes sense, increasing the tmpfs to (mem_size + swap_size) works, and it starts swapping once mem_size is reached. No idea why I did not think of this first myself, an understanding problem afterall :slight_smile:
Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.