From b5a50e7a8d398d2aab48df6ae4244a5e66a30ebe Mon Sep 17 00:00:00 2001 From: Benedikt Wegmann <Benedikt.Wegmann@gwdg.de> Date: Thu, 2 Mar 2017 09:40:00 +0100 Subject: [PATCH] zram --- README.md | 6 ++++++ files/etc/sysctl.d/60-swappiness.conf | 1 + files/usr/bin/init-zram-swapping | 24 ++++++++++++++++++++++++ manifests/zram.pp | 27 +++++++++++++++++++++++++++ spec/classes/zram_spec.rb | 20 ++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 files/etc/sysctl.d/60-swappiness.conf create mode 100755 files/usr/bin/init-zram-swapping create mode 100644 manifests/zram.pp create mode 100644 spec/classes/zram_spec.rb diff --git a/README.md b/README.md index a30103a..bdd776a 100644 --- a/README.md +++ b/README.md @@ -136,3 +136,9 @@ Installiert das Apt-Modul für automatische Updates. Die Konfiguration installie * $autoremove (optional) = Entfernt nicht mehr benötigte Pakete, z.B. alte Kernel. (Default: ```true```) * $allowed_origins (optional) = Array mit Quellenangaben für Apt, aus denen Updates installiert werden dürfen. (Default: ```["\${distro_id}:\${distro_codename}-updates","LP-PPA-ubuntu-lxc-lxd-stable:\${distro_codename}","Docker:ubuntu-\${distro_codename}","Puppetlabs:\${distro_codename}"]```) * $package_blacklist (optional) = ein Array mit Paketnamen, die von automatischen Updates ausgeschlossen werden. (Default: 'docker-engine') + +### ubuntu_server::zram + +Installiert `zram-config` Paket zur Einrichtung von komprimierten Blockdevices im RAM ([zram](https://en.wikipedia.org/wiki/Zram)) und mit aktiviertem Swap darauf. + +* $agressive (optional) = Setzt die Gesamtgröße der `zram`-Devices auf fast den gesamten RAM statt auf die Hälfte und setzt `vm.swappiness` auf 90 für frühzeitiges auslagern. (Default: `false`) \ No newline at end of file diff --git a/files/etc/sysctl.d/60-swappiness.conf b/files/etc/sysctl.d/60-swappiness.conf new file mode 100644 index 0000000..7aef346 --- /dev/null +++ b/files/etc/sysctl.d/60-swappiness.conf @@ -0,0 +1 @@ +vm.swappiness=90 diff --git a/files/usr/bin/init-zram-swapping b/files/usr/bin/init-zram-swapping new file mode 100755 index 0000000..f0a3085 --- /dev/null +++ b/files/usr/bin/init-zram-swapping @@ -0,0 +1,24 @@ +#!/bin/sh + +# load dependency modules +NRDEVICES=$(grep -c ^processor /proc/cpuinfo | sed 's/^0$/1/') +if modinfo zram | grep -q ' zram_num_devices:' 2>/dev/null; then + MODPROBE_ARGS="zram_num_devices=${NRDEVICES}" +elif modinfo zram | grep -q ' num_devices:' 2>/dev/null; then + MODPROBE_ARGS="num_devices=${NRDEVICES}" +else + exit 1 +fi +modprobe zram $MODPROBE_ARGS + +# Calculate memory to use for zram (1/2 of ram) +totalmem=`LC_ALL=C free | grep -e "^Mem:" | sed -e 's/^Mem: *//' -e 's/ *.*//'` +mem=$((((totalmem - 102400 )/ ${NRDEVICES}) * 1024)) + +# initialize the devices +for i in $(seq ${NRDEVICES}); do + DEVNUMBER=$((i - 1)) + echo $mem > /sys/block/zram${DEVNUMBER}/disksize + mkswap /dev/zram${DEVNUMBER} + swapon -p 5 /dev/zram${DEVNUMBER} +done diff --git a/manifests/zram.pp b/manifests/zram.pp new file mode 100644 index 0000000..9f243db --- /dev/null +++ b/manifests/zram.pp @@ -0,0 +1,27 @@ +# zram installieren und ggf. swappiness anpassen + +class ubuntu_server::zram($agressive=false){ + + File{ + owner => 'root', + } + + package{'zram-config': + ensure => present, + } + + if ( $agressive == true ) { + file{'/usr/bin/init-zram-swapping': + ensure => present, + source => 'puppet:///modules/ubuntu_server/usr/bin/init-zram-swapping', + mode => '0755', + require => Package['zram-config'], + } + + file{'/etc/sysctl.d/60-swappiness.conf': + ensure => present, + source => 'puppet:///modules/ubuntu_server/etc/sysctl.d/60-swappiness.conf', + } + } + +} diff --git a/spec/classes/zram_spec.rb b/spec/classes/zram_spec.rb new file mode 100644 index 0000000..f9c5c99 --- /dev/null +++ b/spec/classes/zram_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "ubuntu_server::zram" do + + context "with class defaults" do + it { is_expected.to compile.with_all_deps } + it { is_expected.not_to contain_file('/usr/bin/init-zram-swapping') } + it { is_expected.not_to contain_file('/etc/sysctl.d/60-swappiness.conf') } + end + + context "with $agressive = true" do + let(:params) {{ + :agressive => true, + }} + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file('/usr/bin/init-zram-swapping') } + it { is_expected.to contain_file('/etc/sysctl.d/60-swappiness.conf') } + end + +end -- GitLab