Linux性能优化特性Tuned和ktune(3)

[root@SICS-MIGPC-DB tune-profiles]# ls -l
total 68
-rw-r--r-- 1 root root  17 Apr  7 16:39 active-profile
drwxr-xr-x 2 root root 4096 Apr  3 13:11 default
drwxr-xr-x 2 root root 4096 Apr  3 13:11 desktop-powersave
drwxr-xr-x 2 root root 4096 Apr  3 13:11 enterprise-storage
drwxr-xr-x 2 root root 4096 Apr  3 13:42 enterprise-storage-no-thp
-rw-r--r-- 1 root root 9779 Jul 24  2013 functions
drwxr-xr-x 2 root root 4096 Apr  3 13:11 laptop-ac-powersave
drwxr-xr-x 2 root root 4096 Apr  3 13:11 laptop-battery-powersave
drwxr-xr-x 2 root root 4096 Apr  3 13:11 latency-performance
drwxr-xr-x 2 root root 4096 Apr  3 13:11 sap
drwxr-xr-x 2 root root 4096 Apr  3 13:11 server-powersave
drwxr-xr-x 2 root root 4096 Apr  3 13:11 spindown-disk
drwxr-xr-x 2 root root 4096 Apr  3 13:11 throughput-performance
drwxr-xr-x 2 root root 4096 Apr  3 13:11 virtual-guest
drwxr-xr-x 2 root root 4096 Apr  3 13:11 virtual-host

首先我们查看两个文件内容。Active-profile内容表明了当前正在使用的Profile名称。

[root@SICS-MIGPC-DB tune-profiles]# cat active-profile 

enterprise-storage-no-thp

而functions文件中定义了一些脚本中使用的函数内容。

[root@SICS-MIGPC-DB tune-profiles]# cat functions 

# vim: set syn=sh :

#

# This script contains functions which can be useful in ktune profile scripts.

#

#

# DISK tuning

#

DISKS_DEV="$(command ls -d1 /dev/[shv]d*[a-z] 2>/dev/null)"

DISKS_SYS="$(command ls -d1 /sys/block/{sd,cciss,dm-,vd}* 2>/dev/null)"

# SATA Aggressive Link Power Management

# usage: set_disk_alpm policy

set_disk_alpm() {

policy=$1

for host in /sys/class/scsi_host/*; do

if [ -f $host/ahci_port_cmd ]; then

port_cmd=`cat $host/ahci_port_cmd`;

if [ $((0x$port_cmd & 0x240000)) = 0 -a -f $host/link_power_management_policy ]; then

echo $policy >$host/link_power_management_policy;

else

echo "max_performance" >$host/link_power_management_policy;

fi

fi

done

}

进入目录,每个Profile目录中的内容都近似。

[root@SICS-MIGPC-DB tune-profiles]# cd enterprise-storage-no-thp/

[root@SICS-MIGPC-DB enterprise-storage-no-thp]# ls -l

total 20

-rwxr-xr-x 1 root root  313 Apr  3 13:42 ktune.sh

-rw-r--r-- 1 root root 1239 Apr  3 13:37 ktune.sysconfig

-rw-r--r-- 1 root root 1562 Apr  3 13:37 sysctl.ktune

-rw-r--r-- 1 root root  191 Apr  3 13:37 tuned.conf

Ktune.sh文件是一个可执行脚本,是在ktune服务在启动过程中自动执行,来进行系统调整。

#!/bin/sh

. /etc/tune-profiles/functions –引用的functions文件

start() {

set_cpu_governor performance

set_transparent_hugepages never

disable_disk_barriers

multiply_disk_readahead 4

return 0

}

stop() {

restore_cpu_governor

restore_transparent_hugepages

enable_disk_barriers

restore_disk_readahead

return 0

}

process $@

ktune.sysconfig文件是作为ktune运行的配置参数。

# ktune service configuration
# This is the ktune sysctl file.  You can comment this out to prevent ktune
# from applying its sysctl settings.
#SYSCTL="/etc/sysctl.ktune"
# Use *.conf files in the ktune configuration directory /etc/ktune.d.
#  Value: yes|no,  default: yes
# It is useful if you want to load settings from additional files. Set this to
# no if you to prevent ktune from using these additional files.
USE_KTUNE_D="yes"
# This is the custom sysctl configuration file.  Any settings in this file will
# be applied after the ktune settings, overriding them.  Comment this out to
# use only the ktune settings.
SYSCTL_POST="/etc/sysctl.d/* /etc/sysctl.conf"
# This is the I/O scheduler ktune will use.  This will *not* override anything
# explicitly set on the kernel command line, nor will it change the scheduler
# for any block device that is using a non-default scheduler when ktune starts.
# You should probably leave this on "deadline", but "as", "cfq", and "noop" are
# also legal values.  Comment this out to prevent ktune from changing I/O
# scheduler settings.
ELEVATOR="deadline"
# These are the devices, that should be tuned with the ELEVATOR
ELEVATOR_TUNE_DEVS="/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler"
Sysctl.ktune是指点sysctl设置,用来修改sysctl.conf文件。
# ktune sysctl settings for rhel6 servers with enterprise-class
# storage, 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

4、结论

从使用者的角度看,tuned是一种非常简单易用的调优工具。而且容易进行调优经验的积累分享。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/16287.html