1
0
Fork 0

profiles: added profiles converted from tuned 1.0

profiles: added powersave profile
tuned: reduced number of installed profiles, the rest are in compat subpackage
This commit is contained in:
Jaroslav Škarvada 2012-03-28 15:27:14 +02:00
parent 0582eaac31
commit f0e955e967
28 changed files with 1433 additions and 82 deletions

View file

@ -0,0 +1,9 @@
#
# tuned configuration
#
[cpu]
[disk]
# Comma separated list of devices, all devices if commented out.
# devices=sda

View file

@ -0,0 +1,13 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_radeon_powersave auto
return 0
}
stop() {
restore_radeon_powersave
return 0
}

View file

@ -0,0 +1,13 @@
#
# tuned configuration
#
[main]
include=server-powersave
[net]
# Comma separated list of devices, all devices if commented out.
# devices=eth0
[script]
script=script.sh

View file

@ -0,0 +1,17 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler" deadline
remount_all_no_rootboot_partitions nobarrier
multiply_disk_readahead 4
return 0
}
stop() {
restore_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler"
remount_all_no_rootboot_partitions barrier
multiply_disk_readahead 0.25
return 0
}

View file

@ -0,0 +1,9 @@
#
# tuned configuration
#
[main]
include=throughput-performance
[script]
script=script.sh

527
profiles/functions Normal file
View file

@ -0,0 +1,527 @@
#
# This is library of helper functions that can be used in scripts in tuned profiles.
#
#
# Config
#
STORAGE=/var/run/tuned
STORAGE_SUFFIX=".save"
#
# Helpers
#
# Save sysfs value
# $0 STORAGE_NAME SYSFS_NAME
_save_sys() {
[ "$#" -ne 2 ] && return
[ -r "$2" ] && cat "$2" > "${STORAGE}/${1}${STORAGE_SUFFIX}"
}
# Set sysfs value
# $0 SYSFS_NAME VALUE
_set_sys() {
[ "$#" -ne 2 ] && return
[ -w "$1" ] && echo "$2" > "$1"
}
# Save and set sysfs value
# $0 STORAGE_NAME SYSFS_NAME VALUE
_save_set_sys() {
[ "$#" -ne 3 ] && return
_save_sys "$1" "$2"
_set_sys "$2" "$3"
}
# Get stored sysfs value from storage
# $0 STORAGE_NAME
_get_stored_sys() {
[ "$#" -ne 1 ] && return
[ -r "${STORAGE}/${1}${STORAGE_SUFFIX}" ] && cat "${STORAGE}/${1}${STORAGE_SUFFIX}"
}
# Restore sysfs value from storage, if nothing is stored, use VALUE
# $0 STORAGE_NAME SYSFS_NAME [VALUE]
_restore_sys() {
[ "$#" -lt 2 -o "$#" -gt 3 ] && return
_rs_value="`_get_stored_sys \"$1\"`"
[ "$_rs_value" ] || _rs_value="$3"
[ "$_rs_value" ] && _set_sys "$2" "$_rs_value"
}
#
# 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)"
_check_elevator_override()
{
/bin/fgrep -q 'elevator=' /proc/cmdline
}
# $0 OPERATOR DEVICES ELEVATOR
_set_elevator_helper() {
_check_elevator_override && return
SYS_BLOCK_SDX=""
[ "$2" ] && SYS_BLOCK_SDX=$(eval LANG=C /bin/ls -1 "${2}" 2>/dev/null)
# if there is no kernel command line elevator settings, apply the elevator
if [ "$1" -a "$SYS_BLOCK_SDX" ]; then
for i in $SYS_BLOCK_SDX; do
se_dev="`echo \"$i\" | sed 's|/sys/block/\([^/]\+\)/queue/scheduler|\1|'`"
$1 "elevator_${se_dev}" "$i" "$3"
done
fi
}
# $0 DEVICES ELEVATOR
set_elevator() {
_set_elevator_helper _save_set_sys "$1" "$2"
}
# $0 DEVICES [ELEVATOR]
restore_elevator() {
re_elevator="$2"
[ "$re_elevator" ] || re_elevator = cfq
_set_elevator_helper _restore_sys "$1" "$re_elevator"
}
# 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
}
# usage: set_disk_apm level
set_disk_apm() {
level=$1
for disk in $DISKS_DEV; do
hdparm -B $level $disk &>/dev/null
done
}
# usage: set_disk_spindown level
set_disk_spindown() {
level=$1
for disk in $DISKS_DEV; do
hdparm -S $level $disk &>/dev/null
done
}
# usage: multiply_disk_readahead by
multiply_disk_readahead() {
by=$1
# float multiplication not supported in bash
# bc might not be installed, python is available for sure
for disk in $DISKS_SYS; do
control="${disk}/queue/read_ahead_kb"
old=$(cat $control)
new=$(echo "print int($old*$by)" | python)
(echo $new > $control) &>/dev/null
done
}
# usage: remount_disk options partition1 partition2 ...
remount_partitions() {
options=$1
shift
for partition in $@; do
mount -o remount,$options $partition
done
}
remount_all_no_rootboot_partitions() {
[ "$1" ] || return
# Find non-root and non-boot partitions, disable barriers on them
rootvol=$(df -h / | grep "^/dev" | awk '{print $1}')
bootvol=$(df -h /boot | grep "^/dev" | awk '{print $1}')
volumes=$(df -hl --exclude=tmpfs | grep "^/dev" | awk '{print $1}')
nobarriervols=$(echo "$volumes" | grep -v $rootvol | grep -v $bootvol)
remount_partitions "$1" $nobarriervols
}
DISK_QUANTUM_SAVE="${STORAGE}/disk_quantum${STORAGE_SUFFIX}"
set_disk_scheduler_quantum() {
value=$1
rm -f "$DISK_QUANTUM_SAVE"
for disk in $DISKS_SYS; do
control="${disk}/queue/iosched/quantum"
echo "echo $(cat $control) > $control" >> "$DISK_QUANTUM_SAVE" 2>/dev/null
(echo $value > $control) &2>/dev/null
done
}
restore_disk_scheduler_quantum() {
if [ -r "$DISK_QUANTUM_SAVE" ]; then
/bin/sh "$DISK_QUANTUM_SAVE" &>/dev/null
rm -f "$DISK_QUANTUM_SAVE"
fi
}
#
# CPU tuning
#
CPUSPEED_SAVE_FILE="${STORAGE}/ktune-cpuspeed${STORAGE_SUFFIX}"
CPUSPEED_ORIG_GOV="${STORAGE}/ktune-cpuspeed-governor-%s${STORAGE_SUFFIX}"
CPUSPEED_STARTED="${STORAGE}/ktune-cpuspeed-started"
CPUSPEED_CFG="/etc/sysconfig/cpuspeed"
CPUSPEED_INIT="/etc/init.d/cpuspeed"
CPUS="$(ls -d1 /sys/devices/system/cpu/cpu* | sed 's;^.*/;;' | grep "cpu[0-9]\+")"
# set CPU governor setting and store the old settings
# usage: set_cpu_governor governor
set_cpu_governor() {
governor=$1
# prefer governor setting using cpuspeed daemon
if [ -e $CPUSPEED_INIT ]; then
if [ ! -e $CPUSPEED_SAVE_FILE -a -e $CPUSPEED_CFG ]; then
cp -p $CPUSPEED_CFG $CPUSPEED_SAVE_FILE
sed -e 's/^GOVERNOR=.*/GOVERNOR='$governor'/g' $CPUSPEED_SAVE_FILE > $CPUSPEED_CFG
fi
service cpuspeed status &> /dev/null
[ $? -eq 3 ] && touch $CPUSPEED_STARTED || rm -f $CPUSPEED_STARTED
service cpuspeed restart &> /dev/null
# direct change using /sys fs
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
echo >&2
echo "Suggestion: install 'cpuspeed' package to get best tuning results." >&2
echo "Falling back to '$governor' scaling governor for all CPUs." >&2
echo >&2
for cpu in $CPUS; do
gov_file=/sys/devices/system/cpu/$cpu/cpufreq/scaling_governor
save_file=$(printf $CPUSPEED_ORIG_GOV $cpu)
rm -f $save_file
if [ -e $gov_file ]; then
cat $gov_file > $save_file
echo $governor > $gov_file
fi
done
fi
}
# re-enable previous CPU governor settings
# usage: restore_cpu_governor
restore_cpu_governor() {
if [ -e $CPUSPEED_INIT ]; then
if [ -e $CPUSPEED_SAVE_FILE ]; then
cp -fp $CPUSPEED_SAVE_FILE $CPUSPEED_CFG
rm -f $CPUSPEED_SAVE_FILE
fi
if [ -e $CPUSPEED_STARTED ]; then
rm -f $CPUSPEED_STARTED
service cpuspeed stop &> /dev/null
else
service cpuspeed restart &> /dev/null
fi
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
for cpu in $CPUS; do
cpufreq_dir=/sys/devices/system/cpu/$cpu/cpufreq
save_file=$(printf $CPUSPEED_ORIG_GOV $cpu)
if [ -e $cpufreq_dir/scaling_governor ]; then
if [ -e $save_file ]; then
cat $save_file > $cpufreq_dir/scaling_governor
rm -f $save_file
else
echo userspace > $cpufreq_dir/scaling_governor
cat $cpufreq_dir/cpuinfo_max_freq > $cpufreq_dir/scaling_setspeed
fi
fi
done
fi
}
_cpu_multicore_powersave() {
value=$1
[ -e /sys/devices/system/cpu/sched_mc_power_savings ] && echo $value > /sys/devices/system/cpu/sched_mc_power_savings
}
# enable multi core power savings for low wakeup systems
enable_cpu_multicore_powersave() {
_cpu_multicore_powersave 1
}
disable_cpu_multicore_powersave() {
_cpu_multicore_powersave 0
}
#
# MEMORY tuning
#
THP_ENABLE="/sys/kernel/mm/redhat_transparent_hugepage/enabled"
THP_SAVE="${STORAGE}/ktune-thp${STORAGE_SUFFIX}"
enable_transparent_hugepages() {
if [ -e $THP_ENABLE ]; then
cut -f2 -d'[' $THP_ENABLE | cut -f1 -d']' > $THP_SAVE
(echo always > $THP_ENABLE) &> /dev/null
fi
}
restore_transparent_hugepages() {
if [ -e $THP_SAVE ]; then
(echo $(cat $THP_SAVE) > $THP_ENABLE) &> /dev/null
rm -f $THP_SAVE
fi
}
#
# WIFI tuning
#
# usage: _wifi_set_power_level level
_wifi_set_power_level() {
# 0 auto, PM enabled
# 1-5 least savings and lowest latency - most savings and highest latency
# 6 disable power savings
level=$1
# apply the settings using iwpriv
ifaces=$(cat /proc/net/wireless | grep -v '|' | sed 's@^ *\([^:]*\):.*@\1@')
for iface in $ifaces; do
iwpriv $iface set_power $level
done
# some adapters may relay on sysfs
for i in /sys/bus/pci/devices/*/power_level; do
(echo $level > $i) &> /dev/null
done
}
enable_wifi_powersave() {
_wifi_set_power_level 5
}
disable_wifi_powersave() {
_wifi_set_power_level 0
}
#
# BLUETOOTH tuning
#
disable_bluetooth() {
hciconfig hci0 down
rmmod hci_usb
}
enable_bluetooth() {
modprobe hci_usb
hciconfig hci0 up
}
#
# USB tuning
#
_usb_autosuspend() {
value=$1
for i in /sys/bus/usb/devices/*/power/autosuspend; do echo $value > $i; done &> /dev/null
}
enable_usb_autosupend() {
_usb_autosuspend 1
}
disable_usb_autosuspend() {
_usb_autosuspend 0
}
#
# SOUND CARDS tuning
#
enable_snd_ac97_powersave() {
_save_set_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save Y
}
disable_snd_ac97_powersave() {
_save_set_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save N
}
restore_snd_ac97_powersave() {
_restore_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save $1
}
set_hda_intel_powersave() {
_save_set_sys hda_intel /sys/module/snd_hda_intel/parameters/power_save $1
}
restore_hda_intel_powersave() {
_restore_sys hda_intel /sys/module/snd_hda_intel/parameters/power_save $1
}
#
# VIDEO CARDS tuning
#
# Power savings settings for Radeon
# usage: set_radeon_powersave dynpm | default | low | mid | high
set_radeon_powersave () {
[ "$1" ] || return
[ -e /sys/class/drm/card0/device/power_method ] || return
if [ "$1" = default -o "$1" = auto -o "$1" = low -o "$1" = med -o "$1" = high ]; then
[ -w /sys/class/drm/card0/device/power_profile ] || return
_save_sys radeon_profile /sys/class/drm/card0/device/power_profile
_save_set_sys radeon_method /sys/class/drm/card0/device/power_method profile
_set_sys /sys/class/drm/card0/device/power_profile "$1"
elif [ "$1" = dynpm ]; then
_save_sys radeon_profile /sys/class/drm/card0/device/power_profile
_save_set_sys radeon_method /sys/class/drm/card0/device/power_method dynpm
fi
}
restore_radeon_powersave () {
_restore_sys radeon_method /sys/class/drm/card0/device/power_method profile
_rrp_method="`_get_stored_sys radeon_method`"
[ -z "$_rrp_method" -o _rrp_method="profile" ] && _restore_sys radeon_profile /sys/class/drm/card0/device/power_profile default
}
#
# SOFTWARE tuning
#
RSYSLOG_CFG="/etc/rsyslog.conf"
RSYSLOG_SAVE="${STORAGE}/ktune-cpuspeed${STORAGE_SUFFIX}"
disable_logs_syncing() {
cp -p $RSYSLOG_CFG $RSYSLOG_SAVE
sed -i 's/ \/var\/log/-\/var\/log/' $RSYSLOG_CFG
}
restore_logs_syncing() {
mv $RSYSLOG_SAVE $RSYSLOG_CFG
}
#
# HARDWARE SPECIFIC tuning
#
# Asus EEE with Intel Atom
_eee_fsb_control() {
value=$1
if [ -e /sys/devices/platform/eeepc/she ]; then
echo $value > /sys/devices/platform/eeepc/she
elif [ -e /sys/devices/platform/eeepc/cpufv ]; then
echo $value > /sys/devices/platform/eeepc/cpufv
fi
}
eee_set_reduced_fsb() {
_eee_fsb_control 2
}
eee_set_normal_fsb() {
_eee_fsb_control 1
}
#
# KTUNE ACTION PROCESSING
#
error_not_implemented() {
echo "tuned: ktune script function '$1' is not implemented." >&2
}
# implicit actions, will be used if not provided by profile script:
#
# * start must be implemented
# * stop must be implemented
# * reload runs start
# * restart runs stop + start
# * status returns 0
start() {
error_not_implemented start
return 16
}
stop() {
error_not_implemented stop
return 16
}
reload() {
start
return $?
}
restart() {
stop && start
return $?
}
status() {
return 0
}
# main processing
process() {
VAR_SUBSYS_KTUNE="/var/lock/subsys/ktune"
case "$1" in
start)
[ -f "$VAR_SUBSYS_KTUNE" ] && exit 0
start
RETVAL=$?
;;
stop)
[ -f "$VAR_SUBSYS_KTUNE" ] || exit 0
stop
RETVAL=$?
;;
reload)
[ -f "$VAR_SUBSYS_KTUNE" ] && reload
RETVAL=$?
;;
restart|force-reload)
[ -f "$VAR_SUBSYS_KTUNE" ] && restart
RETVAL=$?
;;
condrestart|try-restart)
[ -f "$VAR_SUBSYS_KTUNE" ] || exit 0
restart
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=2
;;
esac
exit $RETVAL
}

View file

@ -1,14 +0,0 @@
#!/bin/sh
. /etc/tune-profiles/functions
start() {
echo 1 > /tmp/test.txt
return 0
}
stop() {
return 0
}
process $@

View file

@ -1,10 +0,0 @@
[main]
[m_sysctl]
type=sysctl
net.core.rmem_default = 262144
[script]
type=script
script=script.sh

View file

@ -0,0 +1,13 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
enable_wifi_powersave
return 0
}
stop() {
disable_wifi_powersave
return 0
}

View file

@ -0,0 +1,9 @@
#
# tuned configuration
#
[main]
include=desktop-powersave
[script]
script=script.sh

View file

@ -0,0 +1,6 @@
#
# tuned configuration
#
[main]
include=powersave

View file

@ -0,0 +1,20 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler" deadline
set_cpu_governor performance
/usr/libexec/tuned/pmqos-static.py cpu_dma_latency=0
return 0
}
stop() {
restore_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler"
restore_cpu_governor
/usr/libexec/tuned/pmqos-static.py disable
return 0
}

View file

@ -0,0 +1,6 @@
#
# tuned configuration
#
[script]
script=script.sh

27
profiles/powersave/script.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
[ "$USB_AUTOSUSPEND" = 1 ] && enable_usb_autosuspend
set_disk_alpm min_power
enable_cpu_multicore_powersave
set_cpu_governor ondemand
enable_snd_ac97_powersave
set_hda_intel_powersave 10
enable_wifi_powersave
set_radeon_powersave auto
return 0
}
stop() {
[ "$USB_AUTOSUSPEND" = 1 ] && disable_usb_autosuspend
set_disk_alpm max_performance
disable_cpu_multicore_powersave
restore_cpu_governor
restore_snd_ac97_powersave
restore_hda_intel_powersave
disable_wifi_powersave
restore_radeon_powersave
return 0
}

View file

@ -0,0 +1,23 @@
#
# tuned configuration
#
[cpu]
[eee_she]
[disk]
# Comma separated list of devices, all devices if commented out.
# devices=sda
[net]
# Comma separated list of devices, all devices if commented out.
# devices=eth0
[sysctl]
vm.laptop_mode=5
vm.dirty_writeback_centisecs=1500
kernel.nmi_watchdog=0
[script]
script=script.sh

View file

@ -1,57 +0,0 @@
[main]
include=included
[my_sysctl]
replace=1
type=sysctl
# ktune sysctl settings for EL 5 servers
# 256 KB default performs well experimentally, and is often recommended by ISVs.
net.core.rmem_default = 262144
net.core.wmem_default = 262144
# When opening a high-bandwidth connection while the receiving end is under
# memory pressure, disk I/O may be necessary to free memory for the socket,
# making disk latency the effective latency for the bandwidth-delay product
# initially. For 10 Gb ethernet and SCSI, the BDP is about 5 MB. Allow 8 MB
# to account for overhead, to ensure that new sockets can saturate the medium
# quickly.
net.core.wmem_max = 8388608
# Allow a deep backlog for 10 Gb and bonded Gb ethernet connections
net.core.netdev_max_backlog = 10000
# Always have one page available, plus an extra for overhead, to ensure TCP NFS
# pageout doesn't stall under memory pressure. Default to max unscaled window,
# plus overhead for rmem, since most LAN sockets won't need to scale.
net.ipv4.tcp_rmem = 8192 87380 8388608
net.ipv4.tcp_wmem = 8192 65536 8388608
# Always have enough memory available on a UDP socket for an 8k NFS request,
# plus overhead, to prevent NFS stalling under memory pressure. 16k is still
# low enough that memory fragmentation is unlikely to cause problems.
net.ipv4.udp_rmem_min = 16384
net.ipv4.udp_wmem_min = 16384
# Ensure there's enough memory to actually allocate those massive buffers to a
# socket.
net.ipv4.tcp_mem = 8388608 12582912 16777216
net.ipv4.udp_mem = 8388608 12582912 16777216
# Filesystem I/O is usually much more efficient than swapping, so try to keep
# swapping low. It's usually safe to go even lower than this on systems with
# server-grade storage.
vm.swappiness = 30
# 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.
vm.dirty_ratio = 50
# Ensure there's always some easily-dropped pagecache if the system is under
# memory pressure from cached files, since it's much faster to page back in than
# swap.
# Doesn't exist for 2.6.30++ anymore
# vm.pagecache = 90

View file

@ -0,0 +1,13 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_disk_alpm min_power
return 0
}
stop() {
set_disk_alpm max_performance
return 0
}

View file

@ -0,0 +1,10 @@
#
# tuned configuration
#
[cpu]
[disk]
[script]
script=script.sh

View file

@ -0,0 +1,37 @@
#!/bin/sh
. /usr/lib/tuned/functions
EXT_PARTITIONS=$(mount | grep -E "type ext(3|4)" | cut -d" " -f1)
start() {
set_disk_alpm medium_power
set_disk_apm 128
set_disk_spindown 6
[ "$USB_AUTOSUSPEND" = 1 ] && enable_usb_autosuspend
disable_bluetooth
enable_wifi_powersave
disable_logs_syncing
remount_partitions commit=600,noatime $EXT_PARTITIONS
find /etc/ &> /dev/null
sync
return 0
}
stop() {
set_disk_alpm max_power
set_disk_apm 255
set_disk_spindown 0
[ "$USB_AUTOSUSPEND" = 1 ] && disable_usb_autosuspend
enable_bluetooth
disable_wifi_powersave
restore_logs_syncing
remount_partitions commit=5 $EXT_PARTITIONS
return 0
}

View file

@ -0,0 +1,27 @@
#
# tuned configuration
#
# spindown-disk usecase:
# Safe extra energy on your laptop or home server
# which wake-up only when you ssh to it. On server
# could be hdparm and sysctl values problematic for
# some type of discs. Laptops should be probably ok
# with these numbers.
#
# Possible problems:
# The script is remounting your ext3 fs if you have
# it as noatime. Also configuration of rsyslog is
# changed to not sync. hdparm is setting disc to
# minimal spins but without use of tuned daemon.
# Bluetooth will be switch off.
# Wifi will be switch into power safe mode.
[sysctl]
vm.dirty_writeback_centisecs=6000
vm.dirty_expire_centisecs=9000
vm.dirty_ratio=60
vm.laptop_mode=5
vm.swappiness=30
[script]
script=script.sh

View file

@ -0,0 +1,17 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler" deadline
set_cpu_governor performance
enable_transparent_hugepages
return 0
}
stop() {
restore_elevator "/sys/block/{sd,cciss,dm-,vd}*/queue/scheduler"
restore_cpu_governor
restore_transparent_hugepages
return 0
}

View file

@ -0,0 +1,43 @@
#
# tuned configuration
#
[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 = 15
# 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
[script]
script=script.sh

View file

@ -0,0 +1,15 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
remount_all_no_rootboot_partitions nobarrier
multiply_disk_readahead 4
return 0
}
stop() {
remount_all_no_rootboot_partitions barrier
multiply_disk_readahead 0.25
return 0
}

View file

@ -0,0 +1,15 @@
#
# tuned configuration
#
[main]
include=throughput-performance
[sysctl]
# Filesystem I/O is usually much more efficient than swapping, so try to keep
# swapping low. It's usually safe to go even lower than this on systems with
# server-grade storage.
vm.swappiness = 30
[script]
script=script.sh

21
profiles/virtual-host/script.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
. /usr/lib/tuned/functions
start() {
set_elevator "/sys/block/{sd,cciss,dm-}*/queue/scheduler" deadline
set_cpu_governor performance
enable_transparent_hugepages
remount_all_no_rootboot_partitions nobarrier
multiply_disk_readahead 4
return 0
}
stop() {
restore_elevator "/sys/block/{sd,cciss,dm-}*/queue/scheduler"
restore_cpu_governor
restore_transparent_hugepages
remount_all_no_rootboot_partitions barrier
multiply_disk_readahead 0.25
return 0
}

View file

@ -0,0 +1,25 @@
#
# tuned configuration
#
[main]
include=throughput-performance
[sysctl]
# Filesystem I/O is usually much more efficient than swapping, so try to keep
# swapping low. It's usually safe to go even lower than this on systems with
# server-grade storage.
vm.swappiness = 10
#
# The generator of dirty data starts writeback at this percentage (system default
# is 20%)
vm.dirty_ratio = 10
# Start background writeback (via writeback threads) at this percentage (system
# default is 10%)
vm.dirty_background_ratio = 5
[script]
replace=1
script=script.sh

View file

@ -0,0 +1,491 @@
#
# This is library of helper functions that can be used in scripts in tuned profiles.
#
#
# Config
#
STORAGE=/var/run/tuned
STORAGE_SUFFIX=".save"
#
# Helpers
#
# Save sysfs value
# $0 STORAGE_NAME SYSFS_NAME
_save_sys() {
[ "$#" -ne 2 ] && return
[ -r "$2" ] && cat "$2" > "${STORAGE}/${1}${STORAGE_SUFFIX}"
}
# Set sysfs value
# $0 SYSFS_NAME VALUE
_set_sys() {
[ "$#" -ne 2 ] && return
[ -w "$1" ] && echo "$2" > "$1"
}
# Save and set sysfs value
# $0 STORAGE_NAME SYSFS_NAME VALUE
_save_set_sys() {
[ "$#" -ne 3 ] && return
_save_sys "$1" "$2"
_set_sys "$2" "$3"
}
# Get stored sysfs value from storage
# $0 STORAGE_NAME
_get_stored_sys() {
[ "$#" -ne 1 ] && return
[ -r "${STORAGE}/${1}${STORAGE_SUFFIX}" ] && cat "${STORAGE}/${1}${STORAGE_SUFFIX}"
}
# Restore sysfs value from storage, if nothing is stored, use VALUE
# $0 STORAGE_NAME SYSFS_NAME [VALUE]
_restore_sys() {
[ "$#" -lt 2 -o "$#" -gt 3 ] && return
_rs_value="`_get_stored_sys \"$1\"`"
[ "$_rs_value" ] || _rs_value="$3"
[ "$_rs_value" ] && _set_sys "$2" "$_rs_value"
}
#
# 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)"
_check_elevator_override()
{
/bin/fgrep -q 'elevator=' /proc/cmdline
}
# $0 OPERATOR DEVICES ELEVATOR
_set_elevator_helper() {
_check_elevator_override && return
SYS_BLOCK_SDX=""
[ "$2" ] && SYS_BLOCK_SDX=$(eval LANG=C /bin/ls -1 "${2}" 2>/dev/null)
# if there is no kernel command line elevator settings, apply the elevator
if [ "$1" -a "$SYS_BLOCK_SDX" ]; then
for i in $SYS_BLOCK_SDX; do
se_dev="`echo \"$i\" | sed 's|/sys/block/\([^/]\+\)/queue/scheduler|\1|'`"
$1 "elevator_${se_dev}" "$i" "$3"
done
fi
}
# $0 DEVICES ELEVATOR
set_elevator() {
_set_elevator_helper _save_set_sys "$1" "$2"
}
# $0 DEVICES [ELEVATOR]
restore_elevator() {
re_elevator="$2"
[ "$re_elevator" ] || re_elevator = cfq
_set_elevator_helper _restore_sys "$1" "$re_elevator"
}
# 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
}
# usage: set_disk_apm level
set_disk_apm() {
level=$1
for disk in $DISKS_DEV; do
hdparm -B $level $disk &>/dev/null
done
}
# usage: set_disk_spindown level
set_disk_spindown() {
level=$1
for disk in $DISKS_DEV; do
hdparm -S $level $disk &>/dev/null
done
}
# usage: multiply_disk_readahead by
multiply_disk_readahead() {
by=$1
# float multiplication not supported in bash
# bc might not be installed, python is available for sure
for disk in $DISKS_SYS; do
control="${disk}/queue/read_ahead_kb"
old=$(cat $control)
new=$(echo "print int($old*$by)" | python)
(echo $new > $control) &>/dev/null
done
}
# usage: remount_disk options partition1 partition2 ...
remount_partitions() {
options=$1
shift
for partition in $@; do
mount -o remount,$options $partition
done
}
remount_all_no_rootboot_partitions() {
[ "$1" ] || return
# Find non-root and non-boot partitions, disable barriers on them
rootvol=$(df -h / | grep "^/dev" | awk '{print $1}')
bootvol=$(df -h /boot | grep "^/dev" | awk '{print $1}')
volumes=$(df -hl --exclude=tmpfs | grep "^/dev" | awk '{print $1}')
nobarriervols=$(echo "$volumes" | grep -v $rootvol | grep -v $bootvol)
remount_partitions "$1" $nobarriervols
}
DISK_QUANTUM_SAVE="${STORAGE}/disk_quantum${STORAGE_SUFFIX}"
set_disk_scheduler_quantum() {
value=$1
rm -f "$DISK_QUANTUM_SAVE"
for disk in $DISKS_SYS; do
control="${disk}/queue/iosched/quantum"
echo "echo $(cat $control) > $control" >> "$DISK_QUANTUM_SAVE" 2>/dev/null
(echo $value > $control) &2>/dev/null
done
}
restore_disk_scheduler_quantum() {
if [ -r "$DISK_QUANTUM_SAVE" ]; then
/bin/sh "$DISK_QUANTUM_SAVE" &>/dev/null
rm -f "$DISK_QUANTUM_SAVE"
fi
}
#
# CPU tuning
#
CPUSPEED_SAVE_FILE="${STORAGE}/cpuspeed${STORAGE_SUFFIX}"
CPUSPEED_ORIG_GOV="${STORAGE}/cpuspeed-governor-%s${STORAGE_SUFFIX}"
CPUSPEED_STARTED="${STORAGE}/cpuspeed-started"
CPUSPEED_CFG="/etc/sysconfig/cpuspeed"
CPUSPEED_INIT="/etc/init.d/cpuspeed"
CPUS="$(ls -d1 /sys/devices/system/cpu/cpu* | sed 's;^.*/;;' | grep "cpu[0-9]\+")"
# set CPU governor setting and store the old settings
# usage: set_cpu_governor governor
set_cpu_governor() {
governor=$1
# prefer governor setting using cpuspeed daemon
if [ -e $CPUSPEED_INIT ]; then
if [ ! -e $CPUSPEED_SAVE_FILE -a -e $CPUSPEED_CFG ]; then
cp -p $CPUSPEED_CFG $CPUSPEED_SAVE_FILE
sed -e 's/^GOVERNOR=.*/GOVERNOR='$governor'/g' $CPUSPEED_SAVE_FILE > $CPUSPEED_CFG
fi
service cpuspeed status &> /dev/null
[ $? -eq 3 ] && touch $CPUSPEED_STARTED || rm -f $CPUSPEED_STARTED
service cpuspeed restart &> /dev/null
# direct change using /sys fs
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
echo >&2
echo "Suggestion: install 'cpuspeed' package to get best tuning results." >&2
echo "Falling back to '$governor' scaling governor for all CPUs." >&2
echo >&2
for cpu in $CPUS; do
gov_file=/sys/devices/system/cpu/$cpu/cpufreq/scaling_governor
save_file=$(printf $CPUSPEED_ORIG_GOV $cpu)
rm -f $save_file
if [ -e $gov_file ]; then
cat $gov_file > $save_file
echo $governor > $gov_file
fi
done
fi
}
# re-enable previous CPU governor settings
# usage: restore_cpu_governor
restore_cpu_governor() {
if [ -e $CPUSPEED_INIT ]; then
if [ -e $CPUSPEED_SAVE_FILE ]; then
cp -fp $CPUSPEED_SAVE_FILE $CPUSPEED_CFG
rm -f $CPUSPEED_SAVE_FILE
fi
if [ -e $CPUSPEED_STARTED ]; then
rm -f $CPUSPEED_STARTED
service cpuspeed stop &> /dev/null
else
service cpuspeed restart &> /dev/null
fi
elif [ -e /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
for cpu in $CPUS; do
cpufreq_dir=/sys/devices/system/cpu/$cpu/cpufreq
save_file=$(printf $CPUSPEED_ORIG_GOV $cpu)
if [ -e $cpufreq_dir/scaling_governor ]; then
if [ -e $save_file ]; then
cat $save_file > $cpufreq_dir/scaling_governor
rm -f $save_file
else
echo userspace > $cpufreq_dir/scaling_governor
cat $cpufreq_dir/cpuinfo_max_freq > $cpufreq_dir/scaling_setspeed
fi
fi
done
fi
}
_cpu_multicore_powersave() {
value=$1
[ -e /sys/devices/system/cpu/sched_mc_power_savings ] && echo $value > /sys/devices/system/cpu/sched_mc_power_savings
}
# enable multi core power savings for low wakeup systems
enable_cpu_multicore_powersave() {
_cpu_multicore_powersave 1
}
disable_cpu_multicore_powersave() {
_cpu_multicore_powersave 0
}
#
# MEMORY tuning
#
THP_ENABLE="/sys/kernel/mm/redhat_transparent_hugepage/enabled"
THP_SAVE="${STORAGE}/thp${STORAGE_SUFFIX}"
enable_transparent_hugepages() {
if [ -e $THP_ENABLE ]; then
cut -f2 -d'[' $THP_ENABLE | cut -f1 -d']' > $THP_SAVE
(echo always > $THP_ENABLE) &> /dev/null
fi
}
restore_transparent_hugepages() {
if [ -e $THP_SAVE ]; then
(echo $(cat $THP_SAVE) > $THP_ENABLE) &> /dev/null
rm -f $THP_SAVE
fi
}
#
# WIFI tuning
#
# usage: _wifi_set_power_level level
_wifi_set_power_level() {
# 0 auto, PM enabled
# 1-5 least savings and lowest latency - most savings and highest latency
# 6 disable power savings
level=$1
# apply the settings using iwpriv
ifaces=$(cat /proc/net/wireless | grep -v '|' | sed 's@^ *\([^:]*\):.*@\1@')
for iface in $ifaces; do
iwpriv $iface set_power $level
done
# some adapters may relay on sysfs
for i in /sys/bus/pci/devices/*/power_level; do
(echo $level > $i) &> /dev/null
done
}
enable_wifi_powersave() {
_wifi_set_power_level 5
}
disable_wifi_powersave() {
_wifi_set_power_level 0
}
#
# BLUETOOTH tuning
#
disable_bluetooth() {
hciconfig hci0 down
rmmod hci_usb
}
enable_bluetooth() {
modprobe hci_usb
hciconfig hci0 up
}
#
# USB tuning
#
_usb_autosuspend() {
value=$1
for i in /sys/bus/usb/devices/*/power/autosuspend; do echo $value > $i; done &> /dev/null
}
enable_usb_autosupend() {
_usb_autosuspend 1
}
disable_usb_autosuspend() {
_usb_autosuspend 0
}
#
# SOUND CARDS tuning
#
enable_snd_ac97_powersave() {
_save_set_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save Y
}
disable_snd_ac97_powersave() {
_save_set_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save N
}
restore_snd_ac97_powersave() {
_restore_sys ac97 /sys/module/snd_ac97_codec/parameters/power_save $1
}
set_hda_intel_powersave() {
_save_set_sys hda_intel /sys/module/snd_hda_intel/parameters/power_save $1
}
restore_hda_intel_powersave() {
_restore_sys hda_intel /sys/module/snd_hda_intel/parameters/power_save $1
}
#
# VIDEO CARDS tuning
#
# Power savings settings for Radeon
# usage: set_radeon_powersave dynpm | default | low | mid | high
set_radeon_powersave () {
[ "$1" ] || return
[ -e /sys/class/drm/card0/device/power_method ] || return
if [ "$1" = default -o "$1" = auto -o "$1" = low -o "$1" = med -o "$1" = high ]; then
[ -w /sys/class/drm/card0/device/power_profile ] || return
_save_sys radeon_profile /sys/class/drm/card0/device/power_profile
_save_set_sys radeon_method /sys/class/drm/card0/device/power_method profile
_set_sys /sys/class/drm/card0/device/power_profile "$1"
elif [ "$1" = dynpm ]; then
_save_sys radeon_profile /sys/class/drm/card0/device/power_profile
_save_set_sys radeon_method /sys/class/drm/card0/device/power_method dynpm
fi
}
restore_radeon_powersave () {
_restore_sys radeon_method /sys/class/drm/card0/device/power_method profile
_rrp_method="`_get_stored_sys radeon_method`"
[ -z "$_rrp_method" -o _rrp_method="profile" ] && _restore_sys radeon_profile /sys/class/drm/card0/device/power_profile default
}
#
# SOFTWARE tuning
#
RSYSLOG_CFG="/etc/rsyslog.conf"
RSYSLOG_SAVE="${STORAGE}/cpuspeed${STORAGE_SUFFIX}"
disable_logs_syncing() {
cp -p $RSYSLOG_CFG $RSYSLOG_SAVE
sed -i 's/ \/var\/log/-\/var\/log/' $RSYSLOG_CFG
}
restore_logs_syncing() {
mv $RSYSLOG_SAVE $RSYSLOG_CFG
}
#
# HARDWARE SPECIFIC tuning
#
# Asus EEE with Intel Atom
_eee_fsb_control() {
value=$1
if [ -e /sys/devices/platform/eeepc/she ]; then
echo $value > /sys/devices/platform/eeepc/she
elif [ -e /sys/devices/platform/eeepc/cpufv ]; then
echo $value > /sys/devices/platform/eeepc/cpufv
fi
}
eee_set_reduced_fsb() {
_eee_fsb_control 2
}
eee_set_normal_fsb() {
_eee_fsb_control 1
}
#
# ACTION PROCESSING
#
error_not_implemented() {
echo "tuned: script function '$1' is not implemented." >&2
}
# implicit actions, will be used if not provided by profile script:
#
# * start must be implemented
# * stop must be implemented
start() {
error_not_implemented start
return 16
}
stop() {
error_not_implemented stop
return 16
}
#
# main processing
#
process() {
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop}"
RETVAL=2
;;
esac
exit $RETVAL
}

View file

@ -1,7 +1,7 @@
Summary: A dynamic adaptive system tuning daemon
Name: tuned
Version: 2.0
Release: 0.2.alpha%{?dist}
Release: 0.3.alpha%{?dist}
License: GPLv2
# The source for this package was pulled from upstream git. Use the
# following commands to get the corresponding tarball:
@ -35,6 +35,13 @@ minimal, maximal and average time between operations to be able to
identify applications that behave power inefficient (many small operations
instead of fewer large ones).
%package profiles-compat
Summary: Additional tuned profiles mainly for backward compatibility with tuned 1.0
Requires: %{name} = %{version}-%{release}
%description profiles-compat
Additional tuned profiles mainly for backward compatibility with tuned 1.0.
It can be also used to fine tune your system for specific scenarios.
%prep
%setup -q
@ -84,6 +91,12 @@ fi
%{python_sitelib}/tuned
%{_sbindir}/tuned
%{_sbindir}/tuned-adm
%exclude %{_prefix}/lib/tuned/desktop-powersave
%exclude %{_prefix}/lib/tuned/laptop-ac-powersave
%exclude %{_prefix}/lib/tuned/server-powersave
%exclude %{_prefix}/lib/tuned/laptop-battery-powersave
%exclude %{_prefix}/lib/tuned/enterprise-storage
%exclude %{_prefix}/lib/tuned/spindown-disk
%{_prefix}/lib/tuned
%config(noreplace) %{_sysconfdir}/tuned/active_profile
%{_sysconfdir}/tmpfiles.d
@ -106,8 +119,21 @@ fi
%{_mandir}/man8/diskdevstat.*
%{_mandir}/man8/scomes.*
%files profiles-compat
%defattr(-,root,root,-)
%{_prefix}/lib/tuned/desktop-powersave
%{_prefix}/lib/tuned/laptop-ac-powersave
%{_prefix}/lib/tuned/server-powersave
%{_prefix}/lib/tuned/laptop-battery-powersave
%{_prefix}/lib/tuned/enterprise-storage
%{_prefix}/lib/tuned/spindown-disk
%changelog
* Wed Mar 28 2012 Jaroslav Škarvada <jskarvad@redhat.com> - 2.0-0.3.alpha
- Converted profiles from tuned 1.0
- Added powersave profile
- Reduced number of installed profiles, others added into profiles-compat subpackage
* Mon Mar 22 2012 Jan Kaluza <jkaluza@redhat.com> 2.0-0.2.alpha
- Added tuned-adm and tuned.cfg man page