Why don't Linux distributions enable zswap or zram by default, especially when swap space is on an SSD?
#linux #ram #computermemory #swapspace #zswap #zram #ramcompression #swapcompression #ssd #flashstorage
Why don't Linux distributions enable zswap or zram by default, especially when swap space is on an SSD?
#linux #ram #computermemory #swapspace #zswap #zram #ramcompression #swapcompression #ssd #flashstorage
interesting discussion on the odd fact that in Linux we have #zram aka #zramswap (compressed swap in memory) and #zswap (compressed swap buffer in memory which decompresses the data before evicting it to a disk-based backing store if memory is getting low enough), without having simple compressed swap on disk:
https://unix.stackexchange.com/questions/740334/how-to-compress-disk-swap
Recently, I've been experiencing some lag (ie. opening Ghostty terminals) when browsing, playing RuneScape, and watching YouTube videos (all at the same time) on my Ubuntu laptop.
At first, I thought it could be due to the overhead of snaps (both Ghostty and Epiphany, my browser, are snaps), but after some monitoring with HTOP, I realized that I was using a lot of memory... particularly when watching YouTube videos in Epiphany and playing RuneScape at the same time. In fact, I was using so much memory I was hitting swap.
I didn't think this should have been a huge deal, however, because I had enabled zswap with lz4 compression (Ubuntu does not appear to support zstd). After looking at the parameters under /sys/module/zswap/parameters/, however, I noticed that my zpool was zbud, which is the default on Ubuntu.
Well it turns out that zbud... is not very effective and is in fact being deprecated:
https://www.spinics.net/lists/kernel/msg5527878.html
I decided to switch over to zsmalloc with the following in my /etc/default/grub:
GRUB_CMDLINE_LINUX="zswap.enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=25 zswap.zpool=zsmalloc"
With this change, zswap appears to be much more effective and I have not experienced as much (if any) lag in terms of being able to open up Ghostty terminals while browsing, playing RuneScape, and watching YouTube videos.
Some various performance improvements for Debian 12 Bookworm
Here some various improvements I implemented on some of my Debian 12 Bookworm servers in order to improve performance.
zswap: use zsmalloc allocator with newer kernel
If your system has little memory, you might be using zswap already. When memory is getting full, the system will try to swap out less used data from memory to a compressed swap in memory instead of writing it immediately to a […]
https://blog.frehi.be/2024/11/29/some-various-performance-improvements-for-debian-12-bookworm/
Enabled #zswap with #lz4 compression on my #ubuntu machines today:
1. Add "zswap.enabled=1 zswap.compressor=lz4" to "GRUB_CMDLINE_LINUX" in /etc/default/grub
2. Run "update-grub"
3. Add "lz4" and "lz4_compress" to "/etc/initramfs-tools/modules"
4. Run "update-initramfs -u"
After a reboot, you can check "dmesg | grep zswap" or "grep -r . /sys/module/zswap/parameters/"
I had already enabled zswap on my VPS machines, so now I wanted to add this to my bare metal machines.
Комфортная работа в Linux. ZRAM и гибернация — особенности взаимодействия
Далеко не все работающие на сегодняшний день компьютеры и ноутбуки имеют объём оперативной памяти, гарантированно перекрывающий потребности возложенных на них задач. Для ноутбуков среднего и нижнего ценовых сегментов типовой задачей может быть работа с большим количеством открытых вкладок браузера, для более дорогих ноутбуков или системных блоков — ресурсоёмкие игры, рендеринг, видеомонтаж, для серверов — базы данных и прочие требовательные к RAM задачи. Когда RAM близка к заполнению, данные неактивных в данный момент приложений начинают выгружаться из неё на диск, в файл или раздел подкачки. Когда при запуске ещё одного приложения, открытии файла или вкладки браузера, потребуется срочно освободить нужный для этого действия объём оперативной памяти, пауза в работе компьютера может быть заметна, даже когда в системе стоит SSD. На HDD же, в случае запуска ресурсоёмкого приложения, подкачка может приостановить работу и на несколько десятков секунд. Кроме того, постоянная подкачка на SSD приводит к его ускоренному износу, что с учётом цены SSD, также не лучшее решение. Если типовые задачи вашего компьютера требуют в 2-3 раза больше оперативной памяти, чем стоит в системе, наилучшим решением будет её увеличение. Если установить больше памяти невозможно технически (самый, пожалуй, острый пример — нетбуки на процессоре Atom с максимально возможным объёмом RAM 2 Гб) — ресурсоёмкие задачи лучше перенести на более мощный аппарат, а этот использовать только для офисно-браузерных задач (отдать детям или родителям). В случае же менее значительной нехватки (в пределах половины имеющегося объёма RAM), есть возможность улучшить ситуацию.
This is the power of zswap!
A before and after screenshot of the same operation running with high swap usage on one of our hypervisors with RAM constraints.
@yayroos Might depend on what are your RAM and swap specs. In my experience there's stuff that Linux will never, *ever* release once it lands on swap, in particular if your uptime is long enough to include eg.: system libraries getting updated.
The one change people tend to recommend is lowering vm.swappiness to *prevent* too much stuff from landing into swap in the first place, and from what I recall Ubuntu's swappiness default is unusually high. Can't recall the file where the setting is but I'm gonna bet it's /etc/sysctl.conf .
Another advice depending on the RAM and swap is to enable #zswap (compressed swap) but IIRC that doesn't help much unless you are filling already about half of your swap during your normal workflow anyway. Debian and Arch have decent instructions to enable it, but I don't know if Ubuntu benefits from adjusting them.
To be clear I had working #zswap setups before, they just stopped working.
6.4 changed several things (remove frontswap, cgroups support, inclusion in /proc/meminfo), but I saw no changes in the patches in documentation about how to activate it. Maybe I'm just missing some memcg wizardry.
And all info I found about zswap predates 6.4 so I don't know if it's unchanged on purpose, or just "not updated yet".
https://www.reddit.com/r/linux/comments/11dkhz7/zswap_vs_zram_in_2023_whats_the_actual_practical/
>#zswap vs #zram in 2023, what's the actual practical difference?
Interesting discussion on this eternal debate.
It's done my head in for years, but typically i lean to no swap partition/file, then use `systemd-swap`.
$> sudo blkid | grep z
/dev/zram5: ... TYPE="swap"
/dev/zram3: ... TYPE="swap"
/dev/zram1: ... TYPE="swap"
/dev/zram6: ... TYPE="swap"
/dev/zram4: ...TYPE="swap"
/dev/zram2: ... TYPE="swap"
/dev/zram0: ... TYPE="swap"
/dev/zram7: ... TYPE="swap"
:arch:
Ubuntu Brings Full Desktop to Raspberry Pi 4 2GB RAM
Want to run the full Ubuntu desktop on a Raspberry Pi 4 with 2GB of RAM? Well, now you can. Ubuntu already supports the Raspberry Pi 4 Model B 4GB and 8GB versions (and has done since the Ubuntu 20.10 release). Now the team building the distro plan to go further by supporting the Raspberry Pi 4 2GB model too (which costs around £40, if you’re considering one). However, making Ubuntu run decently on devices with modest amounts of memory is difficult. Enter zswap, Ubuntu’s ‘secret weapon’ in targeting low-memory Pis with the full-blown Ubuntu experience. Most Ubuntu systems come :sys_more_orange:
#Dev #RaspberryPi #RaspberryPi4 #Ubuntu22_04Lts #Zswap
:sys_omgubuntu: https://www.omgubuntu.co.uk/2022/01/ubuntu-on-raspberry-pi-4-2gb-zswap