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