Skip to content

Commit

Permalink
Extract KSM management task to kernel role
Browse files Browse the repository at this point in the history
KSM is not Nova compute specific, manage it in the
generic EDPM kernel role's deidcated task instead.

Additionally, ensure the bootstrap role always installs
the dependency package ksmtuned.

Signed-off-by: Bohdan Dobrelia <[email protected]>
  • Loading branch information
bogdando committed Sep 26, 2023
1 parent 581ab88 commit 831595d
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 59 deletions.
6 changes: 6 additions & 0 deletions playbooks/configure_network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
tasks_from: kernelargs.yml
tags:
- edpm_kernel
- name: Configure KSM for kernel
import_role:
name: osp.edpm.edpm_kernel
tasks_from: ksm.yml
tags:
- edpm_kernel
- name: import edpm_network_config
import_role:
name: osp.edpm.edpm_network_config
Expand Down
1 change: 1 addition & 0 deletions roles/edpm_bootstrap/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ edpm_bootstrap_packages_bootstrap:
- tmpwatch
- sysstat
- iproute-tc
- ksmtuned

edpm_bootstrap_release_version_package:
- rhosp-release
Expand Down
1 change: 1 addition & 0 deletions roles/edpm_bootstrap/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ argument_specs:
- tmpwatch
- sysstat
- iproute-tc
- ksmtuned
description: "List of packages that are requred to bootstrap EDPM."

edpm_bootstrap_release_version_package:
Expand Down
3 changes: 3 additions & 0 deletions roles/edpm_kernel/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ edpm_kernel_hugepages_remove: false

# This should be synced with edpm_nova_compute role
edpm_nova_compute_config_dir: /var/lib/config-data/ansible-generated/nova_libvirt

# KSM control
edpm_kernel_enable_ksm: false
19 changes: 19 additions & 0 deletions roles/edpm_kernel/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
# Copyright Red Hat, Inc. 2023
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Delete PageKSM
ansible.builtin.command: echo 2 >/sys/kernel/mm/ksm/run
become: true
4 changes: 4 additions & 0 deletions roles/edpm_kernel/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ argument_specs:
type: dict
default: {}
description: Hugepages configuration dictionary.
edpm_kernel_enable_ksm:
default: false
description: Enable/Disable KSM (disabling it unloads all shared PageKSM!)
type: bool
40 changes: 40 additions & 0 deletions roles/edpm_kernel/tasks/ksm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# Copyright 2023 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Disable KSM services
become: true
when: not edpm_kernel_enable_ksm|bool
ansible.builtin.systemd:
name: "{{ item }}"
state: stopped
enabled: false
loop:
- ksm.service
- ksmtuned.service
# NOTE(bogdando): when KSM is disabled, any memory pages that were shared
# prior to deactivating KSM are still shared. So delete them all
notify: Delete PageKSM

- name: Enable KSM
become: true
when: edpm_kernel_enable_ksm|bool
ansible.builtin.systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- ksm.service
- ksmtuned.service
1 change: 0 additions & 1 deletion roles/edpm_nova_compute/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ edpm_nova_compute_file_backed_memory: 0 # role specific
edpm_nova_compute_volume_use_multipath: false # role specific
edpm_nova_compute_hw_machine_type: "x86_64=q35" # role specific
edpm_nova_compute_additional_cell: false
edpm_nova_compute_enable_ksm: false # role specific
edpm_nova_compute_cinder_password: "{{ edpm_cinder_password | default('') }}" # sensitive, assert not empty
edpm_nova_compute_keystone_region: regionOne
edpm_nova_compute_num_pcie_ports: 16 # role specific
Expand Down
4 changes: 0 additions & 4 deletions roles/edpm_nova_compute/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ argument_specs:
default: '{{ edpm_enable_internal_tls | default (false) }}'
description: ''
type: str
edpm_nova_compute_enable_ksm:
default: false
description: ''
type: bool
edpm_nova_compute_enable_rbd_backend:
default: false
description: ''
Expand Down
54 changes: 0 additions & 54 deletions roles/edpm_nova_compute/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,60 +28,6 @@
state: present
reload: true

- name: Enable/disable ksm
block:
- name: Disable KSM on compute
when: not edpm_nova_compute_enable_ksm|bool
block:
- name: Check for ksm
ansible.builtin.shell: systemctl is-active ksm.service || systemctl is-enabled ksm.service
become: true
failed_when: false
register: ksm_service_check

- name: Disable KSM services
ansible.builtin.service:
name: "{{ item }}"
state: stopped
enabled: false
with_items:
- ksm.service
- ksmtuned.service
when:
- not ansible_check_mode
- ksm_service_check.rc is defined
- ksm_service_check.rc == 0
register: ksmdisabled

# When KSM is disabled, any memory pages that were shared prior to
# deactivating KSM are still shared. To delete all of the PageKSM
# in the system, we use:
- name: Delete PageKSM after disable ksm on compute
ansible.builtin.command: echo 2 >/sys/kernel/mm/ksm/run
when:
- ksm_service_check.rc is defined
- ksm_service_check.rc == 0
- ksmdisabled is changed

- name: Enable KSM on compute
when: edpm_nova_compute_enable_ksm|bool
block:
- name: Make sure package providing ksmtuned is installed (RHEL8 or CentOS8)
ansible.builtin.package:
name: qemu-kvm-common
state: present
when:
- ansible_facts['distribution_major_version'] is version('8', '==')

- name: Enable ksmtunded
ansible.builtin.service:
name: "{{ item }}"
state: started
enabled: true
with_items:
- ksm.service
- ksmtuned.service

- name: Configure nova.conf
when: edpm_nova_compute_config_use_ansible
block:
Expand Down

0 comments on commit 831595d

Please sign in to comment.