Skip to content

Commit 4dcbed7

Browse files
dhhclaude
andcommitted
Tune swap on zram instead of leaving it at kernel defaults
Omarchy installed zram-generator but never shipped a config for it, so the only zram tuning any machine had was whatever the ISO wrote once, and the VM sysctls were untouched kernel defaults aimed at spinning disks. The generator's own default caps the device at 4G, which on a large machine sends reclaim to the hibernation swapfile far earlier than it needs to go. Ship min(ram / 2, 8192) instead, matching what Fedora settles on, and state the priority explicitly since it has to sit above the pri=0 that omarchy-hibernation-setup gives the disk swapfile. The four sysctls follow from swap being RAM rather than a disk. swappiness above 100 says evicting an anonymous page beats dropping a page-cache page that would have to be read back, which is true once swap is compressed memory. page-cluster drops to one page per fault because the default of 8 buys readahead for a seek zram doesn't have and pays a decompression for each page. Zeroing watermark_boost_factor stops fragmentation from producing reclaim bursts while memory is still free, and raising watermark_scale_factor gives kswapd room to reclaim in the background instead of letting allocations stall in direct reclaim. The last two are what actually addresses the stutter people notice and misread as swap being used too eagerly: proactive swapping to zram is the cure, and synchronous direct reclaim is the disease. Every ISO-installed machine already has an unowned zram-generator.conf, which pacman would refuse to overwrite, so both upgrade paths need it listed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent c6ad614 commit 4dcbed7

5 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎bin/omarchy-update-system-pkgs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ sudo env OMARCHY_UPDATE_PACMAN=1 pacman -Syu --noconfirm \
3737
--overwrite '/etc/systemd/system/plocate-updatedb.service.d/ac-only.conf' \
3838
--overwrite '/etc/systemd/system.conf.d/20-omarchy-nofile.conf' \
3939
--overwrite '/etc/systemd/user.conf.d/20-omarchy-nofile.conf' \
40+
--overwrite '/etc/systemd/zram-generator.conf' \
4041
--overwrite '/usr/lib/systemd/system-sleep/unmount-fuse' \
4142
--overwrite '/usr/share/plymouth/themes/omarchy/*' \
4243
--overwrite '/usr/share/sddm/hyprland.lua' \

‎bin/omarchy-upgrade-to-quattro‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ run_final_system_package_upgrade() {
10871087
--overwrite '/etc/systemd/system/plocate-updatedb.service.d/ac-only.conf' \
10881088
--overwrite '/etc/systemd/system.conf.d/20-omarchy-nofile.conf' \
10891089
--overwrite '/etc/systemd/user.conf.d/20-omarchy-nofile.conf' \
1090+
--overwrite '/etc/systemd/zram-generator.conf' \
10901091
--overwrite '/usr/lib/systemd/system-sleep/unmount-fuse' \
10911092
--overwrite '/usr/share/plymouth/themes/omarchy/*' \
10921093
--overwrite '/usr/share/sddm/hyprland.lua' \
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
11
# Solve common flakiness with SSH (MTU discovery on flaky links).
22
net.ipv4.tcp_mtu_probing=1
3+
4+
# Tune reclaim for swap on zram, which is orders of magnitude faster than the
5+
# disk swapfile these defaults assume.
6+
7+
# Anything above 100 tells the kernel that evicting an anonymous page is
8+
# cheaper than dropping a page-cache page it would have to re-read from disk.
9+
# With a compressed RAM device that is true, so the disk-era default of 60
10+
# leaves the page cache starved.
11+
vm.swappiness=180
12+
13+
# Read one page per swap-in fault. The default of 8 pays for a seek that zram
14+
# doesn't have, and every extra page costs a separate decompression.
15+
vm.page-cluster=0
16+
17+
# Don't let external fragmentation raise the watermarks, which produces
18+
# reclaim bursts while memory is still free.
19+
vm.watermark_boost_factor=0
20+
21+
# Keep ~1.25% of memory free instead of 0.1%, so kswapd reclaims in the
22+
# background rather than letting allocations stall in direct reclaim.
23+
vm.watermark_scale_factor=125

‎etc/systemd/zram-generator.conf‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Compressed swap in RAM. zstd averages around 3:1, so the worst case for a
2+
# full device is roughly a third of the size below.
3+
#
4+
# The generator's own default caps this at 4G, which sends machines with a lot
5+
# of memory to the disk swapfile far earlier than they need to go.
6+
[zram0]
7+
zram-size = min(ram / 2, 8192)
8+
compression-algorithm = zstd
9+
10+
# Above the pri=0 that omarchy-hibernation-setup gives the disk swapfile, so
11+
# zram absorbs everything until it's full.
12+
swap-priority = 100

‎migrations/1784961000.sh‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
echo "Tune reclaim for swap on zram"
2+
3+
# Everything here only applies the shipped config early; boot picks it up
4+
# regardless. Nothing is worth failing the migration chain over, so each step
5+
# falls back to asking for a reboot.
6+
7+
# Load our file specifically rather than --system, which returns nonzero for
8+
# any invalid key in any admin sysctl file on the machine.
9+
sudo sysctl -p /etc/sysctl.d/99-omarchy-sysctl.conf >/dev/null || true
10+
11+
if sudo systemctl daemon-reload; then
12+
# Resizing swaps the device off first, which faults every stored page back
13+
# into memory. That's only cheap while it's empty, so a device under
14+
# pressure keeps its old size until the next boot. A device that doesn't
15+
# exist yet reads as empty, which is what we want: the restart brings it up
16+
# against the unit daemon-reload just generated.
17+
zram_used=$(awk '$1 == "/dev/zram0" {print $4}' /proc/swaps)
18+
19+
if [[ ${zram_used:-0} == 0 ]] && sudo systemctl restart dev-zram0.swap; then
20+
exit 0
21+
fi
22+
fi
23+
24+
omarchy-state set reboot-required

0 commit comments

Comments
 (0)