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