---

- block:
  - name: Reduce swapping unless absolutely necessary
    sysctl:
      name: vm.swappiness
      value: "{{ vm_swappiness }}"
      sysctl_set: yes

  - name: Set minimum free memory for servicing allocations (PCU)
    when: "zoox_machine_role == 'ai'"
    sysctl:
      name: vm.min_free_kbytes
      value: "{{ vm_min_free_kbytes_pcu }}"
      sysctl_set: yes

  - name: Set minimum free memory for servicing allocations (Vision)
    when: "zoox_machine_role == 'vision'"
    sysctl:
      name: vm.min_free_kbytes
      value: "{{ vm_min_free_kbytes_vision }}"
      sysctl_set: yes

  - name: Set reasonable zone reclaim mode
    sysctl:
      name: vm.zone_reclaim_mode
      value: "{{ vm_zone_reclaim_mode }}"
      sysctl_set: yes

  - name: Kill the allocating task when OOM
    sysctl:
      name: vm.oom_kill_allocating_task
      value: "{{ vm_oom_kill_allocating_task }}"
      sysctl_set: yes

  become: yes
