Revisión 460
Añadido por Francisco Rodrigo hace más de 12 años
tareas_puppet/workstations/ramzswap_kernel3/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 es la siguiente:
|
||
|
||
memoria_total /2 / num_cpus (para equipos con 1 Gb y 2 cpus 2 swap de ram de 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_kernel3/manifests/init.pp | ||
---|---|---|
class ramzswap_kernel3 {
|
||
|
||
file { "/root/ramzswap" :
|
||
owner=>root, group=>root, mode=>644,
|
||
ensure => directory,
|
||
}
|
||
|
||
file { "/etc/init.d/ramzswap.sh" :
|
||
owner=>root, group=>root, mode=>755,
|
||
source=>"puppet:///modules/ramzswap_kernel3/ramzswap/ramzswap.sh",
|
||
notify=> Exec ["crea-enlaces-ramzswap"],
|
||
}
|
||
|
||
file { "/root/ramzswap/desactiva.sh" :
|
||
owner=>root, group=>root, mode=>755,
|
||
source=>"puppet:///modules/ramzswap_kernel3/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_kernel3/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/S??ramzswap.sh",
|
||
}
|
||
|
||
}
|
tareas_puppet/workstations/ramzswap_kernel3/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
|
||
modprobe zram $num_devices_parameter=$num_cpus
|
||
|
||
# initialize the devices, set total size to 1/2 RAM
|
||
for i in $(seq 0 $decr_num_cpus); do
|
||
echo $((mem_total / 2 / num_cpus)) > /sys/block/zram$i/disksize
|
||
done
|
||
|
||
# Creating swap filesystems
|
||
for i in $(seq 0 $decr_num_cpus); do
|
||
mkswap /dev/zram$i
|
||
done
|
||
|
||
# Switch the swaps on
|
||
for i in $(seq 0 $decr_num_cpus); do
|
||
swapon -p 100 /dev/zram$i
|
||
done
|
||
tareas_puppet/workstations/ramzswap_kernel3/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/zram[[:digit:]]+' /proc/swaps); do
|
||
swapoff "$device"
|
||
done
|
||
# remove module, wait instead of failing if it's busy
|
||
rmmod --wait zram
|
||
tareas_puppet/workstations/ramzswap_kernel3/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
|
||
|
||
Exportar a: Unified diff
Tarea puppet de la ramzswap para workstations con núcleo 3.2.0