diff options
author | Simon Rettberg | 2014-01-29 17:11:46 +0100 |
---|---|---|
committer | Simon Rettberg | 2014-01-29 17:11:46 +0100 |
commit | 2fb4d43cce5f030ea81e68b9b6ebb1b40ea0e7e2 (patch) | |
tree | d258373cdd5dad119b718567bba756dfa032fd27 /remote/rootfs/rootfs-stage32/data | |
parent | [xorg] fixes for Xsession (thx ssc) (diff) | |
download | tm-scripts-2fb4d43cce5f030ea81e68b9b6ebb1b40ea0e7e2.tar.gz tm-scripts-2fb4d43cce5f030ea81e68b9b6ebb1b40ea0e7e2.tar.xz tm-scripts-2fb4d43cce5f030ea81e68b9b6ebb1b40ea0e7e2.zip |
[rfs-stage32] Speed up mounting tmp-partition and setting up zram swap
Diffstat (limited to 'remote/rootfs/rootfs-stage32/data')
4 files changed, 74 insertions, 25 deletions
diff --git a/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service new file mode 120000 index 00000000..c1754b11 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/sysinit.target.wants/zram-swap.service @@ -0,0 +1 @@ +../zram-swap.service
\ No newline at end of file diff --git a/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service new file mode 100644 index 00000000..a458b380 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/etc/systemd/system/zram-swap.service @@ -0,0 +1,10 @@ +[Unit] +Description=Setup zram swap partitions +DefaultDependencies=no +Wants=swap.target +Before=swap.target + +[Service] +Type=oneshot +ExecStart=/opt/openslx/scripts/systemd-zram_swap +RemainAfterExit=yes diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions index 362e8f14..ca7317d4 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-setup_partitions @@ -37,7 +37,7 @@ diskfm () { found=yes case "mkfs.$fs" in mkfs.xfs) - fopt="-f" + fopt="-f -b size=4k -s size=4k -l size=512b" # fastest formatting possible :) mopt="-o noexec" ;; mkfs.ext2) @@ -109,7 +109,7 @@ cat "/etc/disk.partition" HAVE_SWAP=no for hdpartnr in $(sed -n -e "/ 82 /p" "/etc/disk.partition" | sed -e "s/[[:space:]].*//"); do echo -e "$hdpartnr\tswap\t\tswap\t\tdefaults\t 0 0" >> "/etc/fstab" - swapon "$hdpartnr" -p 10 && HAVE_SWAP=yes + swapon "$hdpartnr" -p 10 && HAVE_SWAP=yes # low priority, in case we have zram swap, prefer that) done # We use special non assigned partition type (id44) for harddisk scratch @@ -167,27 +167,5 @@ if [ "$HAVE_SWAP" = "no" ]; then slxlog "partition-swap" "Have no (formatted) swap partition, using zram swap only!" "/etc/disk.partition" fi -# Add zram swap -[ "$(uname -r)" == "3.8.13.8-openslx" ] && exit 0 -CPUS=$(grep -c -E "^processor.*[0-9]+$" /proc/cpuinfo) -if [ -z "$CPUS" ]; then - echo "ERROR: Could not determine CPU core count" -else - [ "$CPUS" -gt "16" ] && CPUS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit - if ! modprobe zram "num_devices=$CPUS"; then - echo "ERROR: Could not load zram module" - else - TOTAL=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') - USE=$(( $TOTAL / ( 2 * $CPUS ) )) - echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap per core" - USE=$(( $USE * 1024 )) - DEV=0 - while [ "$DEV" -lt "$CPUS" ]; do - echo "$USE" > "/sys/block/zram${DEV}/disksize" - mkswap "/dev/zram${DEV}" - swapon "/dev/zram${DEV}" -p 1000 - DEV=$(( $DEV + 1 )) - done - fi -fi +exit 0 diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap new file mode 100755 index 00000000..f8bd5682 --- /dev/null +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/scripts/systemd-zram_swap @@ -0,0 +1,60 @@ +#!/bin/ash +# Copyright (c) 2013 - OpenSLX GmbH +# +# This program is free software distributed under the GPL version 2. +# See http://openslx.org/COPYING +# +# If you have any feedback please consult http://openslx.org/feedback and +# send your feedback to feedback@openslx.org +# +# General information about OpenSLX can be found under http://openslx.org +# +# Local hard disk autodetection script for OpenSLX linux stateless clients, +# detecting swap and special partitions + +############################################################################# + + +# Add zram swap +# Some older ubuntu kernels had a problem here, see https://bugs.launchpad.net/ubuntu/+source/linux-lts-raring/+bug/1217189 +# So make sure you're up to date + +make_swap () { + [ $# -ne 2 ] && echo "make_swap: Wrong parameter count $#" && exit 1 + local USE="$1" + local DEV="$2" + echo "$USE" > "/sys/block/zram${DEV}/disksize" + mkswap "/dev/zram${DEV}" + swapon "/dev/zram${DEV}" -p 1000 # high priority (in case we have hdd swap 0x82, prefer zram) +} + +CPUS=$(grep -c -E "^processor.*[0-9]+$" "/proc/cpuinfo") +if [ -z "$CPUS" ]; then + echo "ERROR: Could not determine CPU core count" + exit 1 +fi + +[ "$CPUS" -gt "16" ] && CPUS=16 # zram can only handle up to 32 devices, the system can apparently even just handle 29 swap partitions, so use a reasonable upper limit +if ! modprobe zram "num_devices=$CPUS"; then + echo "ERROR: Could not load zram module" + exit 1 +fi + +TOTAL=$(grep ^MemTotal /proc/meminfo | awk '{print $2}') +USE=$(( $TOTAL / ( 2 * $CPUS ) )) +echo "Have $CPUS cores, $TOTAL kb mem, use $USE kb zram swap per core" +USE=$(( $USE * 1024 )) +DEV=0 +while [ "$DEV" -lt "$CPUS" ]; do + make_swap "$USE" "$DEV" & + LAST=$! + DEV=$(( $DEV + 1 )) +done + +# Wait, so we don't trigger swap.target too early +while kill -0 "$LAST"; do + usleep 100000 +done + +exit 0 + |