All Products
Search
Document Center

Alibaba Cloud Linux:Change the kernel preemption mode

Last Updated:Oct 12, 2024

You can dynamically switch the kernel preemption mode in Alibaba Cloud Linux 3 operating systems with kernel 5.10.134-17 and later versions based on your business requirements. For example, you can switch from the none preemption mode to the voluntary preemption mode during the instance runtime to meet the latency requirements of your business. This topic describes how to switch the kernel preemption mode in Alibaba Cloud Linux 3 operating systems with kernel version 5.10.134-17 and later versions and the performance differences of the supported kernel preemption modes.

Kernel preemption modes

The following table describes the kernel preemption modes supported in the Alibaba Cloud Linux 3 operating system with kernel version 5.10.134-17 or later.

Preemption mode

Description

none

  • The kernel is non-preemptible. When the kernel executes a critical task, the CPU resources of the task cannot be preempted and the task cannot be interrupted. The system performs context switching when the system returns responses in user mode and does not perform active preemption in kernel mode.

  • The throughput is high but a latency issue may occur.

voluntary

  • The kernel actively releases CPU resources at specific preemption points.

  • This preemption mode provides shorter latency and lower performance than the none mode.

Alibaba Cloud Linux 3 does not support the full mode

In addition to the none and voluntary modes, the Linux community supports the full mode.

  • In full mode, CPU resources can be preempted at any time in the kernel. More code checkpoints are added to allow the kernel to perform quasi-real-time task scheduling, which increases the overheads of kernel context switching.

  • The full mode is mainly used in real-time systems or scenarios that require high response speed. This mode is suitable for desktop environments in which heavy-load tasks are run and fast response is required to provide smooth user experience and high interactivity.

The full mode has few scenarios in the Alibaba Cloud Linux 3 kernel that mainly works on cloud servers. After the code that is used to dynamically switch to the full mode is incorporated into the code of Alibaba Cloud Linux 3, the system performance is significantly affected, and several Linux benchmark test metric values decrease by more than 10%.

Change the kernel preemption mode

In the Alibaba Cloud Linux 3 operating system with kernel version 5.10.134-17 or later, you can use the following methods to change the kernel preemption mode.

Persistently change the kernel preemption mode

The kernel preemption mode is persistently changed and retained after an instance is restarted.

You can add the preempt=none configuration to or delete the configuration from the bootcmdline parameter to change the kernel preemption mode.

  1. View the current kernel preemption mode.

    sudo cat /sys/kernel/debug/sched_preempt
  2. View the current kernel information.

    sudo grubby --info=0
  3. Change the kernel preemption mode.

    Replace the <kernel> value with the kernel version queried in Step 2. Example: /boot/vmlinuz-5.10.134-17.2.al8.x86_64.

    • Change the kernel preemption mode to voluntary.

      sudo grubby --update-kernel=<kernel> --remove-args="preempt=none"
    • Change the kernel preemption mode to none.

      sudo grubby --update-kernel=/boot/vmlinuz-<kernel> --args="preempt=none"
  4. Restart the instance for the modification to take effect.

    sudo reboot
  5. View the new kernel preemption mode.

    sudo cat /sys/kernel/debug/sched_preempt

Temporarily change the kernel preemption mode

You can use the debugfs interface to temporarily and dynamically change the kernel preemption mode. The new kernel preemption mode becomes invalid after an instance is restarted.

In this example, the kernel preemption mode is temporarily changed to voluntary.

  1. View the current kernel preemption mode.

    sudo cat /sys/kernel/debug/sched_preempt

    The following figure shows that the current kernel preemption mode is none.

    image

  2. Change the kernel preemption mode to voluntary.

    sudo sh -c 'echo voluntary > /sys/kernel/debug/sched_preempt'
  3. View the new kernel preemption mode.

    sudo cat /sys/kernel/debug/sched_preempt

    The following figure shows that the new kernel preemption mode is voluntary.

    image

Performance analysis of kernel preemption modes

In end-to-end scenarios, on MySQL, Redis, and NGINX instances that use the x86 and Arm64 architectures, the benchmark test results in none and voluntary preemption modes show that the none mode delivers better performance in most cases, and the performance gap between the two modes is relatively small. In this example, benchmark test results in the MySQL scenario are used.

In the x86 and Arm64 architectures, the oltp_write_only, oltp_read_only, and oltp_read_write metrics are tested. The test results show that greater transaction per second (TPS) and queries per second (QPS) values lead to smaller avg latency and avg 95th values, which indicates better performance.

Note

In the following examples, the test results of the none mode are normalized to 1. The following figures show the differences in the performance data between the none and voluntary modes.

  • x86

    image

  • Arm64

    image

In the x86 and Arm64 architectures, the none mode outperforms the voluntary mode, as shown in the preceding figures.