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