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