Skip to content

Commit

Permalink
Merge pull request sap-linuxlab#886 from berndfinger/issue-885-thp-fl…
Browse files Browse the repository at this point in the history
…exibility

sap_hana_preconfigure: Allow setting THP to any possible value
  • Loading branch information
berndfinger authored Nov 12, 2024
2 parents ec1a47f + 5c6413b commit 422df4b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 39 deletions.
8 changes: 7 additions & 1 deletion roles/sap_hana_preconfigure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ Set this parameter to `true` to modify the Grub boot command line.<br>
By default, the role will run `grub2-mkconfig` to update the Grub configuration if necessary.<br>
Set this parameter to `false` if this is not desired.<br>

### sap_hana_preconfigure_thp
- _Type:_ `str`
- _Default:_ ``

Override the default setting for THP, which is determined automatically by the role, depending on the RHEL version.

### sap_hana_preconfigure_db_group_name
- _Type:_ `str`

Expand Down Expand Up @@ -449,4 +455,4 @@ Available values: `HANA`, `NETWEAVER+HANA`, `S4HANA-APP+DB`, `S4HANA-DBSERVER`
(SUSE specific) On Azure, TCP timestamps, reuse and recycle should be disabled.<br>
If the variable is set, an override file for saptune will be created (/etc/saptune/override/2382421) to set net.ipv4.tcp_timestamps and net.ipv4.tcp_tw_reuse to 0.<br>
Set this parameter to `true` on Azure.<br>
<!-- END Role Variables -->
<!-- END Role Variables -->
4 changes: 4 additions & 0 deletions roles/sap_hana_preconfigure/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ sap_hana_preconfigure_run_grub2_mkconfig: true
# It will be used to configure process limits as per step "Configuring Process Resource Limits" of SAP note 2772999.
# Example: See README.md

# sap_hana_preconfigure_thp: (not defined by default)
# Override the default setting for THP, which is determined automatically by the role, depending on the RHEL version.
# Can be one of 'always', 'madvise', or 'never'.

# (SUSE specific) Version of saptune to install.
# It is recommended to install latest version by keeping this variable empty.
# This will replace the current installed version if present, even downgrade if necessary.
Expand Down
12 changes: 3 additions & 9 deletions roles/sap_hana_preconfigure/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,10 @@
listen: __sap_hana_preconfigure_grubby_update_handler
notify: __sap_hana_preconfigure_reboot_handler

- name: "Run grubby for disabling THP"
ansible.builtin.command: grubby --args="transparent_hugepage=never" --update-kernel=ALL
- name: "Run grubby for setting THP to '{{ __sap_hana_preconfigure_fact_thp }}'"
ansible.builtin.command: grubby --args="transparent_hugepage={{ __sap_hana_preconfigure_fact_thp }}" --update-kernel=ALL
changed_when: true
listen: __sap_hana_preconfigure_grubby_thp_never_handler
notify: __sap_hana_preconfigure_reboot_handler

- name: "Run grubby for setting THP to madvise"
ansible.builtin.command: grubby --args="transparent_hugepage=madvise" --update-kernel=ALL
changed_when: true
listen: __sap_hana_preconfigure_grubby_thp_madvise_handler
listen: __sap_hana_preconfigure_grubby_thp_handler
notify: __sap_hana_preconfigure_reboot_handler

- name: Reboot the managed node
Expand Down
12 changes: 12 additions & 0 deletions roles/sap_hana_preconfigure/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,18 @@ argument_specs:
required: false
type: bool

sap_hana_preconfigure_thp:
default: ''
description:
- Override the default setting for THP, which is determined automatically by the role, depending on the RHEL version.
choices:
- ''
- 'always'
- 'madvise'
- 'never'
required: false
type: str

sap_hana_preconfigure_db_group_name:
description:
- Use this parameter to specify the name of the RHEL group which is used for the database processes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'never'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '8' or
Expand All @@ -37,10 +38,17 @@
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'madvise'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2

- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
when:
- sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp

- name: Assert that 'transparent_hugepage={{ __sap_hana_preconfigure_fact_thp }}' is in GRUB_CMDLINE_LINUX in /etc/default/grub
ansible.builtin.assert:
that: "'transparent_hugepage={{ __sap_hana_preconfigure_fact_thp }}' in __sap_hana_preconfigure_register_default_grub_cmdline_thp_assert.stdout"
Expand Down
54 changes: 25 additions & 29 deletions roles/sap_hana_preconfigure/tasks/RedHat/generic/configure-thp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,48 @@
src: /proc/cmdline
register: __sap_hana_preconfigure_register_proc_cmdline_thp

- name: Set THP to 'never' at boot time
ansible.builtin.command: /bin/true
notify: __sap_hana_preconfigure_grubby_thp_never_handler
changed_when: true
- name: Set fact for THP, RHEL up to RHEL 9.1
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'never'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '8' or
- ansible_distribution_major_version == '7' or
ansible_distribution_major_version == '8' or
ansible_distribution_version == '9.0' or
ansible_distribution_version == '9.1'
- not ( __sap_hana_preconfigure_register_proc_cmdline_thp['content'] | b64decode | regex_findall('transparent_hugepage=never') )
tags: grubconfig

- name: Set THP to 'madvise' at boot time
ansible.builtin.command: /bin/true
notify: __sap_hana_preconfigure_grubby_thp_madvise_handler
changed_when: true
- name: Set fact for THP, RHEL 9.2 and later
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: 'madvise'
when:
- sap_hana_preconfigure_thp is undefined or sap_hana_preconfigure_thp | length == 0
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2
- not ( __sap_hana_preconfigure_register_proc_cmdline_thp['content'] | b64decode | regex_findall('transparent_hugepage=madvise') )

- name: Set fact for THP if 'sap_hana_preconfigure_thp' is defined
ansible.builtin.set_fact:
__sap_hana_preconfigure_fact_thp: "{{ sap_hana_preconfigure_thp }}"
when:
- sap_hana_preconfigure_thp is defined and sap_hana_preconfigure_thp

- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' at boot time
ansible.builtin.command: /bin/true
notify: __sap_hana_preconfigure_grubby_thp_handler
changed_when: true
when: not ( __sap_hana_preconfigure_register_proc_cmdline_thp['content'] | b64decode | regex_findall('transparent_hugepage=' + __sap_hana_preconfigure_fact_thp) )
tags: grubconfig

- name: Configure - Get initial status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
register: __sap_hana_preconfigure_register_thp_status_before
changed_when: false

- name: Set THP to 'never' on the running system
ansible.builtin.shell: echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
- name: Set THP to '{{ __sap_hana_preconfigure_fact_thp }}' on the running system
ansible.builtin.shell: echo '{{ __sap_hana_preconfigure_fact_thp }}' > /sys/kernel/mm/transparent_hugepage/enabled
changed_when: true
when:
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '8' or
ansible_distribution_version == '9.0' or
ansible_distribution_version == '9.1'
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != 'never'

- name: Set THP to 'madvise' on the running system
ansible.builtin.shell: echo 'madvise' > /sys/kernel/mm/transparent_hugepage/enabled
changed_when: true
when:
- ansible_distribution == 'RedHat'
- ansible_distribution_major_version == '9' and
__sap_hana_preconfigure_fact_ansible_distribution_minor_version | int >= 2
- __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != 'madvise'
when: __sap_hana_preconfigure_register_thp_status_before.stdout.split('[')[1].split(']')[0] != __sap_hana_preconfigure_fact_thp

- name: Configure - Get the status of THP
ansible.builtin.command: cat /sys/kernel/mm/transparent_hugepage/enabled
Expand Down

0 comments on commit 422df4b

Please sign in to comment.