Proyecto

General

Perfil

« Anterior | Siguiente » 

Revisión 456

Instalación de swap en ram para workstations con kernel 2.6.32, gestionando tamaño memoria y número de cpus

Ver diferencias:

tareas_puppet/workstations/ramzswap/files/ramzswap/desactiva.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: desactiva.sh
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop: 0,1,6
# Short-Description: desactiva la ramzswap
### END INIT INFO
for device in $(grep -E --only-matching '/dev/ramzswap[[:digit:]]+' /proc/swaps); do
swapoff "$device"
rzscontrol "$device" --reset
done
# remove module, wait instead of failing if it's busy
rmmod --wait ramzswap
tareas_puppet/workstations/ramzswap/files/ramzswap/ramzswap.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: ramzswap.sh
# Required-Start: $remote_fs $syslog $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: inicializa la ramzswap
### END INIT INFO
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/init/swap-functions.sh
case "$1" in
start|"")
# Activa ramz
/root/ramzswap/inicializa.sh
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# Desactiva ramz
/root/ramzswap/desactiva.sh
;;
*)
echo "Usage: ramzwap.sh [start|stop]" >&2
exit 3
;;
esac
exit 0
tareas_puppet/workstations/ramzswap/files/ramzswap/inicializa.sh
#! /bin/sh
### BEGIN INIT INFO
# Provides: inicializa.sh
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: inicializa la ramzswap
### END INIT INFO
get_number_of_present_cpus() {
cpulist=$( cat /sys/devices/system/cpu/present | tr ',' ' ' )
local num_cpus=0
for item in $cpulist; do
if ( echo $item | grep --silent '-' ); then
greater_cpunum=$( echo $item | cut -d '-' -f 2 )
lesser_cpunum=$( echo $item | cut -d '-' -f 1 )
local num_cpus=$(( $num_cpus + $greater_cpunum - $lesser_cpunum + 1 ))
else
local num_cpus=$(( $num_cpus + 1 ))
fi
done
echo $num_cpus
}
# get the number of CPUs
num_cpus=$(get_number_of_present_cpus)
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
mem_total=$((mem_total_kb * 1024))
# determine modprobe parameter name, depending on kernel version
if (uname --release | grep -E --silent "^3\.[123]"); then
num_devices_parameter='zram_num_devices'
else
num_devices_parameter='num_devices'
fi
# load zram modules
disk_size_kb=$((mem_total_kb / 2 / num_cpus))
modprobe lzo_compress
modprobe lzo_decompress
insmod /lib/modules/2.6.32-5-686/kernel/ramzswap.ko $num_devices_parameter=$num_cpus disksize_kb=$disk_size_kb
# initialize the devices, set total size to 1/2 RAM
for i in $(seq 0 $decr_num_cpus); do
rzscontrol /dev/ramzswap$i --init
done
# Switch the swaps on
for i in $(seq 0 $decr_num_cpus); do
swapon -p 100 /dev/ramzswap$i
done
tareas_puppet/workstations/ramzswap/leeme.txt
Configura los workstations con la swap tirando de memoria RAM antes que la swap de disco.
Esto hace que todos los procesos de I/O sean mucho más rápidos.
Se intenta gestionar más eficientemente el uso de la swap.
Por defecto la configuración de ramzswap sigue esta formula:
memoria_total /2 / num_cpus (para equipos con 512 Mb con una sola cpu asigna 256 Mb).
Autor: Oscar Vaquero (Administración SI)
Modificación de los scripts para adaptarlos a cualquier sistema,
creación de tarea puppet y pruebas.
Francisco Rodrigo López
IES Javier García Téllez (Caceres).
INSTRUCCIONES DE INSTALACION DEL MODULO
---------------------------------------
Desempaquetar en /etc/puppet/modules.
Incluirlo en clase-especifica.pp
tareas_puppet/workstations/ramzswap/manifests/init.pp
class ramzswap {
file { "/root/ramzswap" :
owner=>root, group=>root, mode=>644,
ensure => directory,
}
file { "/lib/modules/2.6.32-5-686/kernel/ramzswap.ko" :
owner=>root, group=>root, mode=>664,
source=>"puppet:///modules/ramzswap/ramzswap/ramzswap.ko",
}
file { "/usr/bin/rzscontrol" :
owner=>root, group=>root, mode=>755,
source=>"puppet:///modules/ramzswap/ramzswap/rzscontrol",
}
file { "/etc/init.d/ramzswap.sh" :
owner=>root, group=>root, mode=>755,
source=>"puppet:///modules/ramzswap/ramzswap/ramzswap.sh",
notify=> Exec ["crea-enlaces-ramzswap"],
}
file { "/root/ramzswap/desactiva.sh" :
owner=>root, group=>root, mode=>755,
source=>"puppet:///modules/ramzswap/ramzswap/desactiva.sh",
require => File ["/root/ramzswap","/etc/init.d/ramzswap.sh"],
}
file { "/root/ramzswap/inicializa.sh" :
owner=>root, group=>root, mode=>755,
source=>"puppet:///modules/ramzswap/ramzswap/inicializa.sh",
require => File ["/root/ramzswap","/etc/init.d/ramzswap.sh"],
notify => Exec ["crea-enlaces-ramzswap"],
}
exec { "crea-enlaces-ramzswap" :
path => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
command => "update-rc.d ramzswap.sh defaults",
require => File ["/etc/init.d/ramzswap.sh"],
unless => "ls /etc/rc2.d/S26ramzswap.sh",
}
}

Exportar a: Unified diff