46057837950e63653f382e686bf53f8e8d0ee137
[csit.git] / resources / tools / testbed-setup / ansible / roles / performance_tuning / tasks / main.yaml
1 ---
2 # file: roles/performance_tuning/tasks/main.yaml
3
4 - name: Performance Tuning - Install Distribution - Release - Machine Prerequisites
5   package:
6     name: "{{ packages | flatten(levels=1) }}"
7     state: latest
8     update_cache: true
9   tags:
10     - install-dependencies
11
12 - name: Performance Tuning - Distribution - release - machine optimizations
13   include_tasks: '{{ ansible_distribution|lower }}_{{ ansible_distribution_release }}.yaml'
14   tags:
15     - machine-optimizations
16
17 - name: Performance Tuning - Configure {{ ansible_machine }} Kernel Parameters
18   lineinfile:
19     path: "/etc/default/grub"
20     state: "present"
21     regexp: "^GRUB_CMDLINE_LINUX="
22     line: "{{ grub_cmdline_linux[ansible_machine] | join() }}"
23   notify:
24     - "Update GRUB"
25     - "Reboot server"
26   tags:
27     - set-grub
28
29 - name: Performance Tuning - Turbo Boost
30   import_tasks: turbo_boost.yaml
31   when: >
32     cpu_microarchitecture == "skylake" or
33     cpu_microarchitecture == "cascadelake"
34   tags:
35     - turbo-boost
36
37 - name: Performance Tuning - Adjust nr_hugepages
38   # change the minimum size of the hugepage pool.
39   # 2G VPP, 4GB per VNF/CNF, 2G reserve
40   sysctl:
41     name: "vm.nr_hugepages"
42     value: "{{ sysctl.vm.nr_hugepages  }}"
43     state: "present"
44     sysctl_file: "/etc/sysctl.d/90-csit.conf"
45     reload: "yes"
46   tags:
47     - set-sysctl
48
49 - name: Performance Tuning - Adjust max_map_count
50   # this file contains the maximum number of memory map areas a process
51   # may have. memory map areas are used as a side-effect of calling
52   # malloc, directly by mmap and mprotect, and also when loading shared
53   # libraries.
54   #
55   # while most applications need less than a thousand maps, certain
56   # programs, particularly malloc debuggers, may consume lots of them,
57   # e.g., up to one or two maps per allocation.
58   # must be greater than or equal to (2 * vm.nr_hugepages).
59   sysctl:
60     name: "vm.max_map_count"
61     value: "{{ sysctl.vm.nr_hugepages * 4  }}"
62     state: "present"
63     sysctl_file: "/etc/sysctl.d/90-csit.conf"
64     reload: "yes"
65   tags:
66     - set-sysctl
67
68 - name: Performance Tuning - Adjust hugetlb_shm_group
69   # hugetlb_shm_group contains group id that is allowed to create sysv
70   # shared memory segment using hugetlb page.
71   sysctl:
72     name: "vm.hugetlb_shm_group"
73     value: "1000"
74     state: "present"
75     sysctl_file: "/etc/sysctl.d/90-csit.conf"
76     reload: "yes"
77   tags:
78     - set-sysctl
79
80 - name: Performance Tuning - Adjust swappiness
81   # this control is used to define how aggressive the kernel will swap
82   # memory pages.  higher values will increase agressiveness, lower values
83   # decrease the amount of swap.  a value of 0 instructs the kernel not to
84   # initiate swap until the amount of free and file-backed pages is less
85   # than the high water mark in a zone.
86   sysctl:
87     name: "vm.swappiness"
88     value: "0"
89     state: "present"
90     sysctl_file: "/etc/sysctl.d/90-csit.conf"
91     reload: "yes"
92   tags:
93     - set-sysctl
94
95 - name: Performance Tuning - Adjust shmmax
96   # shared memory max must be greator or equal to the total size of hugepages.
97   # for 2mb pages, totalhugepagesize = vm.nr_hugepages * 2 * 1024 * 1024
98   # if the existing kernel.shmmax setting (cat /sys/proc/kernel/shmmax)
99   # is greater than the calculated totalhugepagesize then set this parameter
100   # to current shmmax value.
101   sysctl:
102     name: "kernel.shmmax"
103     value: "{{ sysctl.vm.nr_hugepages * 2 * 1024 * 1024 }}"
104     state: "present"
105     sysctl_file: "/etc/sysctl.d/90-csit.conf"
106     reload: "yes"
107   tags:
108     - set-sysctl
109
110 - name: Performance Tuning - Adjust watchdog_cpumask
111   # this value can be used to control on which cpus the watchdog may run.
112   # the default cpumask is all possible cores, but if no_hz_full is
113   # enabled in the kernel config, and cores are specified with the
114   # nohz_full= boot argument, those cores are excluded by default.
115   # offline cores can be included in this mask, and if the core is later
116   # brought online, the watchdog will be started based on the mask value.
117   #
118   # typically this value would only be touched in the nohz_full case
119   # to re-enable cores that by default were not running the watchdog,
120   # if a kernel lockup was suspected on those cores.
121   sysctl:
122     name: "kernel.watchdog_cpumask"
123     value: "{{ sysctl.kernel.watchdog_cpumask }}"
124     state: "present"
125     sysctl_file: "/etc/sysctl.d/90-csit.conf"
126     reload: "yes"
127   tags:
128     - set-sysctl
129
130 - name: Performance Tuning - Adjust randomize_va_space
131   # this option can be used to select the type of process address
132   # space randomization that is used in the system, for architectures
133   # that support this feature.
134   # 0 - turn the process address space randomization off.  this is the
135   #     default for architectures that do not support this feature anyways,
136   #     and kernels that are booted with the "norandmaps" parameter.
137   sysctl:
138     name: "kernel.randomize_va_space"
139     value: "0"
140     state: "present"
141     sysctl_file: "/etc/sysctl.d/90-csit.conf"
142     reload: "yes"
143   tags:
144     - set-sysctl
145
146 - name: Performance Tuning - Copy Cpufrequtils File
147   copy:
148     src: "files/cpufrequtils"
149     dest: "/etc/default/cpufrequtils"
150     owner: "root"
151     group: "root"
152     mode: "0644"
153   tags:
154     - copy-cpufrequtils
155
156 - name: Performance Tuning - Copy Irqbalance File
157   template:
158     src: "files/irqbalance"
159     dest: "/etc/default/irqbalance"
160     owner: "root"
161     group: "root"
162     mode: "0644"
163   tags:
164     - copy-irqbalance
165
166 - name: Performance Tuning - Set Ondemand Service To Disable
167   service:
168     name: "ondemand"
169     enabled: "no"
170   tags:
171     - set-ondemand
172
173 - name: Performance Tuning - Load Kernel Modules By Default
174   lineinfile:
175     path: "/etc/modules"
176     state: "present"
177     line: "{{ item }}"
178   with_items:
179     - "vfio-pci"
180   tags:
181     - load-kernel-modules
182
183 - meta: flush_handlers