e3e22d03ac57a15fa023c6f11be97b442475c859
[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   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   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   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   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   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   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   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   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   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   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 - Set Ondemand Service To Disable
147   service:
148     name: "ondemand"
149     enabled: "no"
150   tags:
151     - perf-conf-ondemand
152
153 - name: Conf - Kernel Parameters
154   lineinfile:
155     path: "/etc/default/grub"
156     state: "present"
157     regexp: "^GRUB_CMDLINE_LINUX="
158     line: "GRUB_CMDLINE_LINUX=\"{% for key, value in grub.items() %}{% if value is sameas true %}{{key}} {% else %}{{key}}={{value}} {% endif %}{% endfor %}\""
159   notify:
160     - "Update GRUB"
161   tags:
162     - perf-conf-grub
163
164 - meta: flush_handlers
165
166 - name: Conf - Load Kernel Modules By Default
167   lineinfile:
168     path: "/etc/modules"
169     state: "present"
170     line: "{{ item }}"
171   with_items:
172     - "vfio-pci"
173   notify:
174     - "Reboot Server"
175   tags:
176     - perf-conf-load-kernel-modules
177
178 - name: Conf - Create a directory for 1G HugeTLBs hugepages
179   file:
180     path: "/dev/hugepages1G"
181     state: "directory"
182     mode: 0755
183   tags:
184     - perf-conf-hugepages-1g
185
186 - name: Conf - Mount 1G HugeTLBs hugepages
187   mount:
188     path: "/dev/hugepages1G"
189     src: "hugetlbfs"
190     opts: "pagesize=1G"
191     boot: false
192     state: "mounted"
193     fstype: "hugetlbfs"
194   tags:
195     - perf-conf-hugepages-1g
196
197 - name: Create a directory if it does not exist
198   file:
199     path: "/dev/hugepages2M"
200     state: "directory"
201     mode: 0755
202   tags:
203     - perf-conf-hugepages-2m
204
205 - name: Conf - Create a directory for 2M HugeTLBs hugepages
206   mount:
207     path: "/dev/hugepages2M"
208     src: "hugetlbfs"
209     opts: "pagesize=2M"
210     boot: false
211     state: "mounted"
212     fstype: "hugetlbfs"
213   tags:
214     - perf-conf-hugepages-2m
215
216 - meta: flush_handlers