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