feat(ansible): Ubuntu Jammy VI.
[csit.git] / fdio.infra.ansible / roles / performance_tuning / tasks / main.yaml
1 ---
2 # file: roles/performance_tuning/tasks/main.yaml
3
4 - name: Inst - Update Package Cache (APT)
5   ansible.builtin.apt:
6     update_cache: true
7     cache_valid_time: 3600
8   when:
9     - ansible_distribution|lower == 'ubuntu'
10   tags:
11     - perf-inst-prerequisites
12
13 - name: Inst - Machine Prerequisites
14   ansible.builtin.package:
15     name: "{{ packages | flatten(levels=1) }}"
16     state: latest
17   tags:
18     - perf-inst-prerequisites
19
20 - name: Conf - Turbo Boost
21   import_tasks: turbo_boost.yaml
22   when: >
23     cpu_microarchitecture == "skylake" or
24     cpu_microarchitecture == "cascadelake" or
25     cpu_microarchitecture == "icelake"
26   tags:
27     - perf-conf-turbo-boost
28
29 - name: Conf - Adjust max_map_count
30   # this file contains the maximum number of memory map areas a process
31   # may have. memory map areas are used as a side-effect of calling
32   # malloc, directly by mmap and mprotect, and also when loading shared
33   # libraries.
34   #
35   # while most applications need less than a thousand maps, certain
36   # programs, particularly malloc debuggers, may consume lots of them,
37   # e.g., up to one or two maps per allocation.
38   # must be greater than or equal to (2 * vm.nr_hugepages).
39   ansible.builtin.sysctl:
40     name: "vm.max_map_count"
41     value: "{{ sysctl.vm.nr_hugepages * 4  }}"
42     state: "present"
43     sysctl_file: "/etc/sysctl.d/90-csit.conf"
44     reload: "yes"
45   tags:
46     - perf-conf-sysctl
47
48 - name: Conf - Adjust hugetlb_shm_group
49   # hugetlb_shm_group contains group id that is allowed to create sysv
50   # shared memory segment using hugetlb page.
51   ansible.builtin.sysctl:
52     name: "vm.hugetlb_shm_group"
53     value: "1000"
54     state: "present"
55     sysctl_file: "/etc/sysctl.d/90-csit.conf"
56     reload: "yes"
57   tags:
58     - perf-conf-sysctl
59
60 - name: Conf - Adjust swappiness
61   # this control is used to define how aggressive the kernel will swap
62   # memory pages.  higher values will increase agressiveness, lower values
63   # decrease the amount of swap.  a value of 0 instructs the kernel not to
64   # initiate swap until the amount of free and file-backed pages is less
65   # than the high water mark in a zone.
66   ansible.builtin.sysctl:
67     name: "vm.swappiness"
68     value: "0"
69     state: "present"
70     sysctl_file: "/etc/sysctl.d/90-csit.conf"
71     reload: "yes"
72   tags:
73     - perf-conf-sysctl
74
75 - name: Conf - Adjust shmmax
76   # shared memory max must be greator or equal to the total size of hugepages.
77   # for 2mb pages, totalhugepagesize = vm.nr_hugepages * 2 * 1024 * 1024
78   # if the existing kernel.shmmax setting (cat /sys/proc/kernel/shmmax)
79   # is greater than the calculated totalhugepagesize then set this parameter
80   # to current shmmax value.
81   ansible.builtin.sysctl:
82     name: "kernel.shmmax"
83     value: "{{ sysctl.vm.nr_hugepages * 2 * 1024 * 1024 }}"
84     state: "present"
85     sysctl_file: "/etc/sysctl.d/90-csit.conf"
86     reload: "yes"
87   tags:
88     - perf-conf-sysctl
89
90 - name: Conf - Adjust watchdog_cpumask
91   # this value can be used to control on which cpus the watchdog may run.
92   # the default cpumask is all possible cores, but if no_hz_full is
93   # enabled in the kernel config, and cores are specified with the
94   # nohz_full= boot argument, those cores are excluded by default.
95   # offline cores can be included in this mask, and if the core is later
96   # brought online, the watchdog will be started based on the mask value.
97   #
98   # typically this value would only be touched in the nohz_full case
99   # to re-enable cores that by default were not running the watchdog,
100   # if a kernel lockup was suspected on those cores.
101   ansible.builtin.sysctl:
102     name: "kernel.watchdog_cpumask"
103     value: "{{ sysctl.kernel.watchdog_cpumask }}"
104     state: "present"
105     sysctl_file: "/etc/sysctl.d/90-csit.conf"
106     reload: "yes"
107   tags:
108     - perf-conf-sysctl
109
110 - name: Conf - Adjust randomize_va_space
111   # this option can be used to select the type of process address
112   # space randomization that is used in the system, for architectures
113   # that support this feature.
114   # 0 - turn the process address space randomization off.  this is the
115   #     default for architectures that do not support this feature anyways,
116   #     and kernels that are booted with the "norandmaps" parameter.
117   ansible.builtin.sysctl:
118     name: "kernel.randomize_va_space"
119     value: "0"
120     state: "present"
121     sysctl_file: "/etc/sysctl.d/90-csit.conf"
122     reload: "yes"
123   tags:
124     - perf-conf-sysctl
125
126 - name: Conf - Cpufrequtils
127   ansible.builtin.copy:
128     src: "files/cpufrequtils"
129     dest: "/etc/default/cpufrequtils"
130     owner: "root"
131     group: "root"
132     mode: 0644
133   tags:
134     - perf-conf-cpufrequtils
135
136 - name: Conf - Irqbalance
137   ansible.builtin.template:
138     src: "files/irqbalance"
139     dest: "/etc/default/irqbalance"
140     owner: "root"
141     group: "root"
142     mode: 0644
143   tags:
144     - perf-conf-irqbalance
145
146 - name: Conf - Kernel Parameters
147   ansible.builtin.lineinfile:
148     path: "/etc/default/grub"
149     state: "present"
150     regexp: "^GRUB_CMDLINE_LINUX="
151     line: "GRUB_CMDLINE_LINUX=\"{% for key, value in grub.items() %}{% if value is sameas true %}{{key}} {% else %}{{key}}={{value}} {% endif %}{% endfor %}\""
152   notify:
153     - "Update GRUB"
154   tags:
155     - perf-conf-grub
156
157 - meta: flush_handlers
158
159 - name: Conf - Load Kernel Modules By Default
160   ansible.builtin.lineinfile:
161     path: "/etc/modules"
162     state: "present"
163     line: "{{ item }}"
164   with_items:
165     - "vfio-pci"
166   notify:
167     - "Reboot Server"
168   tags:
169     - perf-conf-load-kernel-modules
170
171 - name: Conf - Create a directory for 1G HugeTLBs hugepages
172   ansible.builtin.file:
173     path: "/dev/hugepages1G"
174     state: "directory"
175     mode: 0755
176   tags:
177     - perf-conf-hugepages-1g
178
179 - name: Conf - Mount 1G HugeTLBs hugepages
180   ansible.builtin.mount:
181     path: "/dev/hugepages1G"
182     src: "hugetlbfs"
183     opts: "pagesize=1G"
184     boot: false
185     state: "mounted"
186     fstype: "hugetlbfs"
187   tags:
188     - perf-conf-hugepages-1g
189
190 - name: Create a directory if it does not exist
191   ansible.builtin.file:
192     path: "/dev/hugepages2M"
193     state: "directory"
194     mode: 0755
195   tags:
196     - perf-conf-hugepages-2m
197
198 - name: Conf - Create a directory for 2M HugeTLBs hugepages
199   ansible.builtin.mount:
200     path: "/dev/hugepages2M"
201     src: "hugetlbfs"
202     opts: "pagesize=2M"
203     boot: false
204     state: "mounted"
205     fstype: "hugetlbfs"
206   tags:
207     - perf-conf-hugepages-2m
208
209 - meta: flush_handlers