Skip to content

Commit 9412f97

Browse files
authored
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
1 parent 1faac77 commit 9412f97

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

archinstall/lib/installer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,12 +979,17 @@ def setup_swap(self, kind: str = 'zram') -> None:
979979
if kind == 'zram':
980980
info('Setting up swap on zram')
981981
self.pacman.strap('zram-generator')
982-
982+
# Get RAM size in MB from hardware info
983+
ram_kb = SysInfo.mem_total()
984+
# Convert KB to MB and divide by 2, with minimum of 4096 MB
985+
size_mb = max(ram_kb // 2048, 4096)
986+
info(f'Zram size: {size_mb} from RAM: {ram_kb}')
983987
# We could use the default example below, but maybe not the best idea: https://github.com/archlinux/archinstall/pull/678#issuecomment-962124813
984988
# zram_example_location = '/usr/share/doc/zram-generator/zram-generator.conf.example'
985989
# shutil.copy2(f"{self.target}{zram_example_location}", f"{self.target}/usr/lib/systemd/zram-generator.conf")
986990
with open(f'{self.target}/etc/systemd/zram-generator.conf', 'w') as zram_conf:
987991
zram_conf.write('[zram0]\n')
992+
zram_conf.write(f'zram-size = {size_mb}\n')
988993

989994
self.enable_service('systemd-zram-setup@zram0.service')
990995

0 commit comments

Comments
 (0)