Linux performance optimization using Tuned configuration optimization solution

Write in front

  • Organizing notes related to exams
  • The blog post covers a simple understanding of Linux tuned tuning tools
  • A brief description of tuning configuration files and an introduction to custom tuning solutions
  • If you don’t understand enough, please help me correct it.

There is only one true responsibility for everyone: to find themselves. Then stick to it in your heart for the rest of your life, wholeheartedly, and never stop. All other roads are incomplete, human means of escape, a cowardly return to popular ideals, drifting with the crowd, and inner fear – Hermann Hesse’s “Demian”< /strong>

tuned performance tuning configuration

tuned is a tool developed and maintained by Red Hat for system performance optimization. It can dynamically adjust various parameters and parameters of the system according to different workloads and needs. configured to provide optimal performance and efficiency.

The official website introduces it like this:

  • Monitor connected devices using udev Device Manager
  • Adjust system settings based on selected profile
  • Supports various types of configuration, such as sysctl, sysfs or kernel boot command line parameters, which are integrated in plugin architecture
  • Supports hot-plugging of devices, which can be controlled via the command line or via D-Bus, so it can be easily integrated into existing management solutions: e.g. using Cockpit
  • Can run in daemonless mode, but has limited functionality
  • Store all its configuration cleanly in one place – in the TuneD configuration file – rather than having to configure it in multiple places and custom scripts

The system can be optimized according to different application cases through the profile of tuned. The core of tuned is profile

Install tools and configure auto-start

┌──[[email protected]]-[/proc/sys/fs]
└─$yum -y install tuned
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:07:01 ago on Sun 01 Oct 2023 03:03:42 PM CST.
Package tuned-2.13.0-6.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
┌──[[email protected]]-[/etc/tuned]
└─$systemctl enable tuned --now

The tuned software provides many tuning plans, which adjust kernel parameters according to different goals, such as power saving plan, high network throughput plan, low latency plan, etc. Administrators can also customize tuning plans according to their own needs.

Activate the specified configuration file

tuned-adm profile <profile_name>
┌──[[email protected]]-[/etc/tuned]
└─$tuned-adm profile throughput-performance

View activated profiles

┌──[[email protected]]-[/etc/tuned]
└─$tuned-adm active
Current active profile: virtual-guest

The /etc/tuned/ directory contains the active_profile file, which records the currently activated tuning plan

tuned-adm list can list the list of available configuration files and the currently activated configuration file

As you can see, the currently active profile is Current active profile: virtual-guest,virtual-guest

┌──[[email protected]]-[/proc/sys/fs]
└─$tuned-adm list
Available profiles:
- accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states
- balanced - General non-specialized tuned profile
- desktop - Optimize for the desktop use-case
- hpc-compute - Optimize for HPC compute workloads
- intel-sst - Configure for Intel Speed Select Base Frequency
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G + networks
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: virtual-guest
┌──[[email protected]]-[/proc/sys/fs]
└─$

Quick description:

  • accelerator-performance: Adjustments based on throughput performance, disabling higher latency STOP state, acceleration mode
  • balanced: Generic non-specialized Tuned profile. equilibrium mode
  • desktop: Optimized for desktop usage scenarios. Interactive apps are more responsive
  • hpc-compute: Optimized for HPC computing workloads. high performance computing
  • intel-sst: Configure for Intel Speed Select Base Frequency.
  • latency-performance: Optimize deterministic performance at the expense of power consumption, suitable for low latency requirements
  • network-latency: Focus on optimizing low-latency network performance at the expense of power consumption.
  • network-throughput: Optimizes network throughput for streaming, typically only available on older CPUs or 40G+ networks.
  • powersave: optimize power consumption and achieve low power consumption, power saving mode
  • throughput-performance: Maximum throughput, provides disk and network IO throughput
  • virtual-guest: Optimized for running in a virtual machine guest, that is, virtual machine mode
  • virtual-host: Optimized for running KVM guests, a host running a virtual machine

tuned-adm recommend is used to view the optimization methods recommended by the system

┌──[[email protected]]-[/etc/tuned]
└─$tuned-adm recommend
virtual-guest

tuned-adm off is used to turn off the tuning solution

┌──[[email protected]]-[/etc/tuned]
└─$tuned-adm off

The new version has more tuning strategies and provides more tuning scenarios.

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/sys/kernel/cgroup]
└─$ tuned-adm --version
tuned-adm 2.15.0
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/sys/kernel/cgroup]
└─$ tuned-adm recommend
balanced

The default tuning strategy is balanced, and the following are the provided tuning strategies

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/sys/kernel/cgroup]
└─$ tuned-adm list
Available profiles:
- accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states
- atomic-guest - Optimize virtual guests based on the Atomic variant
- atomic-host - Optimize bare metal systems running the Atomic variant
- balanced - General non-specialized tuned profile
- cpu-partitioning - Optimize for CPU partitioning
- default - Legacy default tuned profile
- desktop - Optimize for the desktop use-case
- desktop-powersave - Optmize for the desktop use-case with power saving
- enterprise-storage - Legacy profile for RHEL6, for RHEL7, please use throughput-performance profile
- hpc-compute - Optimize for HPC compute workloads
- intel-sst - Configure for Intel Speed Select Base Frequency
- laptop-ac-powersave - Optimize for laptop with power savings
- laptop-battery-powersave - Optimize laptop profile with more aggressive power saving
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- mssql - Optimize for MS SQL Server
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G + networks
- optimize-serial-console - Optimize for serial console use.
- oracle - Optimize for Oracle RDBMS
- postgresql - Optimize for PostgreSQL server
- powersave - Optimize for low power consumption
- realtime - Optimize for realtime workloads
- realtime-virtual-guest - Optimize for realtime workloads running within a KVM guest
- realtime-virtual-host - Optimize for KVM guests running realtime workloads
- sap-hana - Optimize for SAP HANA
- sap-netweaver - Optimize for SAP NetWeaver
- server-powersave - Optimize for server power savings
- spectrumscale-ece - Optimized for Spectrum Scale Erasure Code Edition Servers
- spindown-disk - Optimize for power saving by spinning-down rotational disks
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: balanced

The tuning strategy of tuned is based on configuration files, that is, each tuning strategy has a corresponding configuration file. Through the configuration file, you can simply see what operations the tuning has done.

Tuning configuration file parsing

Here we briefly analyze what the configuration file does? Take the network-throughput configuration as an example?

The network-throughput tuning strategy is mainly optimized for streaming network throughput and is generally only suitable for older CPUs or 40G+ networks.

tuned.conf is the configuration file of the tuned tuning scheme. The configuration file can be placed in

  • /etc/tuned//tuned.conf
  • /usr/lib/tuned/

Among them, the /etc/tuned/ directory has higher priority!

Default tuning configuration files are in the directory below. Each tuning method has its own configuration file.

┌──[[email protected]]-[/usr/lib/tuned]
└─$ls
accelerator-performance desktop hpc-compute latency-performance network-throughput recommend.d virtual-guest
balanced functions intel-sst network-latency powersave throughput-performance virtual-host
┌──[[email protected]]-[/usr/lib/tuned]
└─$

You can see that the default tuning file is divided into two parts, the main and sysctl parts

┌──[[email protected]]-[/usr/lib/tuned]
└─$cat ./network-throughput/tuned.conf
#
# tuned configuration
#

[main]
summary=Optimize for streaming network throughput, generally only necessary on older CPUs or 40G + networks
include=throughput-performance

[sysctl]
# Increase kernel buffer size maximums. Currently this seems only necessary at 40Gb speeds.
#
# The buffer tuning values below do not account for any potential hugepage allocation.
# Ensure that you do not oversubscribe system memory.
net.ipv4.tcp_rmem="4096 87380 16777216"
net.ipv4.tcp_wmem="4096 16384 16777216"
net.ipv4.udp_mem="3145728 4194304 16777216"
┌──[[email protected]]-[/usr/lib/tuned]
└─$
  • The mail section describes the role of this configuration file, and it references the "throughput-performance" configuration file include=throughput-performance
  • The sysctl section describes the kernel parameters it modified. The main changes here are the network buffer sizes related to TCP and UDP.

Let’s take a look at the adjustments made to the referenced configuration files.

┌──[[email protected]]-[/usr/lib/tuned]
└─$cat ./throughput-performance/tuned.conf | grep -v ^#

[main]
summary=Broadly applicable tuning that provides excellent performance across a variety of common server workloads

[cpu]
governor=performance
energy_perf_bias=performance
min_perf_pct=100

[disk]
readahead=>4096

[sysctl]
kernel.sched_min_granularity_ns = 10000000
kernel.sched_wakeup_granularity_ns = 15000000
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
vm.swappiness=10
┌──[[email protected]]-[/usr/lib/tuned]
└─$

There are more configuration blocks such as cpu, disk and so on.

  • The [cpu] section contains CPU-related parameter settings. governor=performance sets the CPU frequency regulation policy to performance mode, energy_perf_bias=performance sets the CPU energy consumption performance preference to performance mode, min_perf_pct=100 sets the CPU Minimum performance percentage is 100%.
  • The [disk] section contains settings related to disk-related parameters. readahead=>4096 Set the disk readahead size to 4096.
  • The [sysctl] section contains some kernel parameter settings. For example, kernel.sched_min_granularity_ns sets the scheduling minimum granularity interval to 10,000,000 nanoseconds, and kernel.sched_wakeup_granularity_ns sets the scheduling wakeup granularity interval to 15,000,000 nanoseconds. In addition, there are parameter settings related to memory management, such as vm.dirty_ratio, vm.dirty_background_ratio and vm.swappiness.

The configuration block will be introduced in detail below. In addition to the configuration files corresponding to the different tuning strategies above, tuned also provides a global configuration file. This configuration file mainly configures tuned Service related configuration

┌──[[email protected]]-[/usr/lib/tuned]
└─$cat /etc/tuned/tuned-main.conf | grep -v ^#

daemon = 1 #Specify whether to use daemon mode
dynamic_tuning = 0 #Specify whether to enable dynamic adjustment. If set to 1, dynamic scaling will be enabled, otherwise only static scaling will be used.
sleep_interval = 1
update_interval = 10
recommend_command = 1
reapply_sysctl = 1
default_instance_priority = 0
udev_buffer_size = 1MB
log_file_count = 2
log_file_max_size = 1MB
┌──[[email protected]]-[/usr/lib/tuned]
└─$

Of course, we can also define our own configuration files for optimization

Customized tuning plan

You can customize the tuning plan, and tuned tuning methods are generally divided into two types: dynamic and static

  • Static tuning: Apply the preset kernel parameters at one time (the kernel parameters here mainly refer to the kernel parameters in /sys or /proc )
  • Dynamic tuning: tunde monitors system behavior and dynamically tunes and optimizes kernel parameters based on the behavior. For example: there is a video transcoding job. When the video is transcoded, no network connection is required. At this time, it can be reduced Network interface speed to reduce energy consumption. When the video transcoding is completed and the network interface data increases for a long time, set the interface to the maximum speed.

The /etc/tuned/ directory contains the tuned-main.conf file (global configuration file), which is mainly used for dynamic tuning, generally automatically The defined tuning plan is also placed in this location

A custom tuning plan generally copies an existing tuning plan and makes changes.

┌──[[email protected]]-[/usr/lib/tuned]
└─$cp -r /usr/lib/tuned/throughput-performance/ /etc/tuned/liruilong-performance
┌──[[email protected]]-[/usr/lib/tuned]
└─$cat /etc/tuned/liruilong-performance/tuned.conf
#
# tuned configuration
#

[main]
summary=Broadly applicable tuning that provides excellent performance across a variety of common server workloads

[cpu]
governor=performance
energy_perf_bias=performance
min_perf_pct=100

[disk]
# The default unit for readahead is KiB. This can be adjusted to sectors
# by specifying the relevant suffix, eg. (readahead => 8192 s). There must
# be at least one space between the number and suffix (if suffix is specified).
readahead=>4096

[sysctl]
# ktune sysctl settings for rhel6 servers, maximizing i/o throughput
#
# Minimal preemption granularity for CPU-bound tasks:
# (default: 1 msec# (1 + ilog(ncpus)), units: nanoseconds)
kernel.sched_min_granularity_ns = 10000000

# SCHED_OTHER wake-up granularity.
# (default: 1 msec# (1 + ilog(ncpus)), units: nanoseconds)
#
# This option delays the preemption effects of decoupled workloads
# and reduces their over-scheduling. Synchronous workloads will still
# have immediate wakeup/sleep latencies.
kernel.sched_wakeup_granularity_ns = 15000000

# If a workload mostly uses anonymous memory and it hits this limit, the entire
# working set is buffered for I/O, and any more write buffering would require
# swapping, so it's time to throttle writes until I/O can catch up. Workloads
# that mostly use file mappings may be able to use even higher values.
#
# The generator of dirty data starts writeback at this percentage (system default
# is 20%)
vm.dirty_ratio = 40

# Start background writeback (via writeback threads) at this percentage (system
# default is 10%)
vm.dirty_background_ratio = 10

# PID allocation wrap value. When the kernel's next PID value
# reaches this value, it wraps back to a minimum PID value.
# PIDs of value pid_max or larger are not allocated.
#
# A suggested value for pid_max is 1024 * <# of cpu cores/threads in system>
# e.g., a box with 32 cpus, the default of 32768 is reasonable, for 64 cpus,
# 65536, for 4096 cpus, 4194304 (which is the upper limit possible).
#kernel.pid_max = 65536

# The swappiness parameter controls the tendency of the kernel to move
# processes out of physical memory and onto the swap disk.
# 0 tells the kernel to avoid swapping processes out of physical memory
# for as long as possible
# 100 tells the kernel to aggressively swap processes out of physical memory
# and move them to swap cache
vm.swappiness=10
┌──[[email protected]]-[/usr/lib/tuned]
└─$

Regarding the tuned.conf configuration file, here is a brief explanation. You can view the corresponding information in the man manual.

┌──[[email protected]]-[/usr/lib/tuned]
└─$man tuned.conf

main

[main] is the main configuration. In main, you can include the include= statement. You can load a specific profile through the include statement. You can create a new profile based on the existing profile. If two profiles are defined If there are conflicting tuning parameters, the newly defined parameters shall prevail.

Plugins

Other configuration sections are defined as plug-ins. Each configuration section has a name. The name is the unique identifier of the plug-in. It can be arbitrary and cannot be repeated. type= Plugin type. Plug-in type, common types cpu, disk, mount, net, vm, sysctl, script, sysfs, scheduler, systemd.

If you use the plug-in name is consistent with [NAME], then type can be ignored,

View currently supported plugins:

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$ dpkg -L tuned | grep plugin_
/usr/lib/python3/dist-packages/tuned/plugins/plugin_audio.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_bootloader.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_cpu.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_disk.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_eeepc_she.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_irqbalance.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_modules.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_mounts.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_net.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_rtentsk.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_scheduler.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_script.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_scsi_host.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_selinux.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_service.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_sysctl.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_sysfs.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_systemd.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_usb.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_video.py
/usr/lib/python3/dist-packages/tuned/plugins/plugin_vm.py
/usr/lib/python3/dist-packages/tuned/utils/plugin_loader.py
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$

Check the parameters supported by the plug-in:

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$ cat /usr/lib/python3/dist-packages/tuned/plugins/plugin_cpu.py | grep -A 10 config_options
        def _get_config_options(self):
                return {<!-- -->
                        "load_threshold" : 0.2,
                        "latency_low" : 100,
                        "latency_high" : 1000,
                        "force_latency" : None,
                        "governor" : None,
                        "sampling_down_factor" : None,
                        "energy_perf_bias" : None,
                        "min_perf_pct" : None,
                        "max_perf_pct" : None,
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$ cat /usr/lib/python3/dist-packages/tuned/plugins/plugin_disk.py | grep -A 10 config_options
        def _get_config_options(cls):
                return {<!-- -->
                        "dynamic" : True, # FIXME: do we want this default?
                        "elevator" : None,
                        "apm" : None,
                        "spindown" : None,
                        "readahead" : None,
                        "readahead_multiply" : None,
                        "scheduler_quantum" : None,
                }

--
        def _get_config_options_used_by_dynamic(cls):
                return [
                        "apm",
                        "spindown",
                ]

        def _instance_init(self, instance):
                instance._has_static_tuning = True

                self._apm_errcnt = 0
                self._spindown_errcnt = 0
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[~]
└─$

Specific parameter configuration needs to be handled based on the actual situation. Here, the sysctl plug-in can directly set the kernel adjustable parameters, and the script plug-in can introduce a custom tuning script. But it needs to be used in combination with library functions. script is more used for dynamic tuning.

Watch a Demo

vim tuned.conf

[main]
# Includes plugins defined in "included" profile.
include=included
# Define my_sysctl plugin
[my_sysctl]
type=sysctl
# 256 KB default performs well experimentally.
net.core.rmem_default = 262144
net.core.wmem_default = 262144
[my_script]
type=script
script=${i:PROFILE_DIR}/profile.sh

The script plug-in supports the execution of specific scripts. The shell script is located in the /etc/tuned/profile-name directory and the script library /usr /lib/tuned/functions can be used to export commonly used functions.

${i:PROFILE_DIR} uses PROFILE_DIRconfigset and tuned.conf files > Built-in functions, so referenced files can be used directly

The script must be able to recognize the start and stop parameters. When the tuning scheme is activated, the start parameter enables the tuning settings. When the tuning scheme is disabled, the stop parameter restores all previously applied tuning settings, see /usr/lib/tuned/powersave/script.sh.

┌──[[email protected]]-[/usr/lib/tuned]
└─$cat /usr/lib/tuned/powersave/script.sh
#!/bin/sh

./usr/lib/tuned/functions

start() {<!-- -->
    [ "$USB_AUTOSUSPEND" = 1 ] & amp; & amp; enable_usb_autosuspend
    enable_wifi_powersave
    return 0
}

stop() {<!-- -->
    [ "$USB_AUTOSUSPEND" = 1 ] & amp; & amp; disable_usb_autosuspend
    disable_wifi_powersave
    return 0
}

process $@ # Call the process function, passing all parameters

The corresponding function calls can be found in the function library.

┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/usr/lib/python3/dist-packages/tuned/plugins]
└─$ cat /usr/lib/tuned/functions | grep process
# main processing
process() {<!-- -->
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/usr/lib/python3/dist-packages/tuned/plugins]
└─$ cat /usr/lib/tuned/functions | grep enable
        # always patch cpuspeed configuration if exists, if it doesn't exist and is enabled,
# re-enable previous CPU governor settings
# enable multi core power savings for low wakeup systems
enable_cpu_multicore_powersave() {<!-- -->
THP_ENABLE="/sys/kernel/mm/transparent_hugepage/enabled"
[ -e "$THP_ENABLE" ] || THP_ENABLE="/sys/kernel/mm/redhat_transparent_hugepage/enabled"
enable_transparent_hugepages() {<!-- -->
        # 0 auto, PM enabled
enable_wifi_powersave() {<!-- -->
enable_bluetooth() {<!-- -->
enable_usb_autosuspend() {<!-- -->
enable_snd_ac97_powersave() {<!-- -->
enable_ksm()
┌──[root@hp-ProLiant-SL270s-Gen8-SE]-[/usr/lib/python3/dist-packages/tuned/plugins]
└─$

tuned-adm verifyVerify whether the configuration is effective, check the log var/log/tuned/tuned.log

Reference to part of the blog post

?The copyright of the reference link content in the article belongs to the original author. If there is any infringement, please inform us. This is an open source project. If you approve it, don’t be stingy with stars

https://tuned-project.org/

“Red Hat Performance Tuning 442”

https://www.cnblogs.com/fengyouyishuang/articles/17232438.html

? 2018-2023 [email protected], All rights reserved. Keep Attribution-NonCommercial-ShareAlike (CC BY-NC-SA 4.0)

syntaxbug.com © 2021 All Rights Reserved.