generated from nicolabelluti/template-ansible
93 lines
2.5 KiB
YAML
93 lines
2.5 KiB
YAML
# Everything that lands on the kernel cmdline goes in one marked block, leaving
|
|
# the existing KERNEL_CMDLINE[default]+= line untouched.
|
|
#
|
|
# systemd.zram=0 - stop zram-generator creating the zram device
|
|
# zswap.* - module params, must be set before first swap-out
|
|
# ttm.pages_limit - hard cap on GTT allocation, lifted from the ~50% of RAM
|
|
# default. 3959290 pages of 4K = ~15.1 GiB
|
|
# ttm.page_pool_size - must match pages_limit or allocations can fail
|
|
- name: Add BC-250 kernel parameters
|
|
become: true
|
|
ansible.builtin.blockinfile:
|
|
path: /etc/default/limine
|
|
marker: '# {mark} ANSIBLE bc250 memory'
|
|
block: |
|
|
KERNEL_CMDLINE[default]+=" systemd.zram=0 zswap.enabled=1 zswap.shrinker_enabled=1 zswap.compressor=lz4 zswap.max_pool_percent=20 ttm.pages_limit=3959290 ttm.page_pool_size=3959290"
|
|
notify: Rebuild initramfs and limine entries
|
|
|
|
# lz4 must be in the initramfs for zswap to use it from early boot.
|
|
- name: Add lz4 to the initramfs modules
|
|
become: true
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/mkinitcpio.conf
|
|
regexp: '^MODULES='
|
|
line: 'MODULES=(lz4)'
|
|
notify: Rebuild initramfs and limine entries
|
|
|
|
# CachyOS ships a udev rule that disables zswap when zram comes up.
|
|
# An empty file with the same name overrides it.
|
|
- name: Neutralise the CachyOS zram udev rule
|
|
become: true
|
|
ansible.builtin.copy:
|
|
content: ''
|
|
dest: /etc/udev/rules.d/30-zram.rules
|
|
mode: '0644'
|
|
|
|
- name: Lower swappiness
|
|
become: true
|
|
ansible.builtin.copy:
|
|
content: vm.swappiness=10
|
|
dest: /etc/sysctl.d/99-bc250.conf
|
|
mode: '0644'
|
|
register: sysctl_conf
|
|
|
|
- name: Apply swappiness now
|
|
become: true
|
|
ansible.builtin.command:
|
|
argv:
|
|
- sysctl
|
|
- --system
|
|
when: sysctl_conf.changed
|
|
changed_when: true
|
|
|
|
- name: Create the swap subvolume
|
|
become: true
|
|
ansible.builtin.command:
|
|
argv:
|
|
- btrfs
|
|
- subvolume
|
|
- create
|
|
- /swap
|
|
args:
|
|
creates: /swap
|
|
|
|
- name: Create the swapfile
|
|
become: true
|
|
ansible.builtin.command:
|
|
argv:
|
|
- btrfs
|
|
- filesystem
|
|
- mkswapfile
|
|
- --size
|
|
- 8g
|
|
- --uuid
|
|
- clear
|
|
- /swap/swapfile
|
|
args:
|
|
creates: /swap/swapfile
|
|
|
|
- name: Add the swapfile to fstab
|
|
become: true
|
|
ansible.builtin.lineinfile:
|
|
path: /etc/fstab
|
|
regexp: '^/swap/swapfile'
|
|
line: '/swap/swapfile none swap defaults 0 0'
|
|
|
|
- name: Apply pending initramfs changes
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Reboot to apply the new kernel parameters
|
|
become: true
|
|
ansible.builtin.reboot:
|
|
reboot_timeout: 600
|