From 9412f977718983b7d261cdac3e275a538f3163c8 Mon Sep 17 00:00:00 2001 From: HADEON <52324046+h8d13@users.noreply.github.com> Date: Thu, 25 Dec 2025 00:59:03 +0100 Subject: [PATCH] Set up Zram dynamically based on best practice (#4027) * Use the total available RAM / 2 for swap size dynamically. * ws * - Systems with 8 GB RAM or less will get 4096 MB zram - Systems with more than 8 GB RAM will get half their RAM as zram * Add debug print --- archinstall/lib/installer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 36a15df6..a4fa4891 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -979,12 +979,17 @@ class Installer: if kind == 'zram': info('Setting up swap on zram') self.pacman.strap('zram-generator') - + # Get RAM size in MB from hardware info + ram_kb = SysInfo.mem_total() + # Convert KB to MB and divide by 2, with minimum of 4096 MB + size_mb = max(ram_kb // 2048, 4096) + info(f'Zram size: {size_mb} from RAM: {ram_kb}') # We could use the default example below, but maybe not the best idea: https://github.com/archlinux/archinstall/pull/678#issuecomment-962124813 # zram_example_location = '/usr/share/doc/zram-generator/zram-generator.conf.example' # shutil.copy2(f"{self.target}{zram_example_location}", f"{self.target}/usr/lib/systemd/zram-generator.conf") with open(f'{self.target}/etc/systemd/zram-generator.conf', 'w') as zram_conf: zram_conf.write('[zram0]\n') + zram_conf.write(f'zram-size = {size_mb}\n') self.enable_service('systemd-zram-setup@zram0.service')