Externalize zram role
This commit is contained in:
commit
4a1e6c8cb3
3 changed files with 104 additions and 0 deletions
14
files/etc/systemd/system/zram-config.service
Normal file
14
files/etc/systemd/system/zram-config.service
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[Unit]
|
||||
Description=ZRAM Swap
|
||||
#After=syslog.target NetworkManager.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/local/sbin/zram-swap.sh start
|
||||
ExecStop=/usr/local/sbin/zram-swap.sh stop
|
||||
#KillMode=process
|
||||
#Restart=off
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
77
files/usr/local/sbin/zram-swap.sh
Executable file
77
files/usr/local/sbin/zram-swap.sh
Executable file
|
|
@ -0,0 +1,77 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# zram-config Start zram-config
|
||||
#
|
||||
# chkconfig: 2345 08 92
|
||||
# description: Starts, stops and saves zram-config
|
||||
#
|
||||
#
|
||||
### BEGIN INIT INFO
|
||||
# Provides: zram-config
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: start and stop zram-config
|
||||
# Description: Start, stop and save zram-config
|
||||
### END INIT INFO
|
||||
|
||||
# http://askubuntu.com/questions/130374/ramdisk-compressed-writeable-no-swap
|
||||
# https://kernel.org/doc/Documentation/blockdev/zram.txt
|
||||
|
||||
#NRDEVICES=$[$(grep ^physical\ id /proc/cpuinfo | sort -u | wc -l)*$(grep ^core\ id /proc/cpuinfo | sort -u | wc -l)]
|
||||
#if [ $NRDEVICES -eq 0 ]; then
|
||||
# NRDEVICES=$(grep -c '^processor\s*:' /proc/cpuinfo)
|
||||
#fi
|
||||
#NRDEVICES=1
|
||||
case "$1" in
|
||||
start)
|
||||
if [ $(grep -c /dev/zram /proc/swaps) -gt 1 ]; then
|
||||
echo "Already running" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ $(lsmod | grep -c zram) -eq 0 ]; then
|
||||
modprobe zram
|
||||
ZRAMID=0
|
||||
else
|
||||
ZRAMID=$(cat /sys/class/zram-control/hot_add)
|
||||
fi
|
||||
MEM=$(free -k | grep -e "^Mem:" | awk '{printf("%d\n",$2/1.2)}')
|
||||
# echo 1 > /sys/block/zram${ZRAMID}/reset
|
||||
if [ -e /sys/block/zram${ZRAMID}/comp_algorithm ]; then
|
||||
if [ $(grep -c lz4 /sys/block/zram${ZRAMID}/comp_algorithm) -eq 1 ]; then
|
||||
echo lz4 > /sys/block/zram${ZRAMID}/comp_algorithm
|
||||
fi
|
||||
fi
|
||||
if [ -e /sys/block/zram${ZRAMID}/mem_limit ]; then
|
||||
echo $[${MEM}*2]k > /sys/block/zram${ZRAMID}/disksize
|
||||
echo ${MEM}k > /sys/block/zram${ZRAMID}/mem_limit
|
||||
else
|
||||
echo ${MEM}k > /sys/block/zram${ZRAMID}/disksize
|
||||
fi
|
||||
mkswap /dev/zram${ZRAMID}
|
||||
swapon -p 10 /dev/zram${ZRAMID}
|
||||
;;
|
||||
stop)
|
||||
# Suppression zram
|
||||
# echo X > /sys/class/zram-control/hot_remove ou X=0 pour zram0
|
||||
for ZRAMID in $(grep /dev/zram /proc/swaps | awk '{print $1}' | cut -c10-); do
|
||||
swapoff /dev/zram${ZRAMID}
|
||||
echo 1 > /sys/block/zram${ZRAMID}/reset
|
||||
echo ${ZRAMID} > /sys/class/zram-control/hot_remove
|
||||
done
|
||||
modprobe -r zram
|
||||
;;
|
||||
esac
|
||||
#mke2fs -q -m 0 -b 4096 -O sparse_super -L zram /dev/zram0
|
||||
#mount -o relatime,noexec,nosuid /dev/zram0 /mnt/zram
|
||||
#chmod 1777 /mnt/zram/
|
||||
|
||||
# cat /sys/block/zram0/mem_used_total
|
||||
|
||||
|
||||
# https://www.google.fr/search?q=sysem+to+ram+pivot_root&ie=utf-8&oe=utf-8&rls=org.mozilla:fr:unofficial&client=seamonkey-a&gws_rd=cr&ei=ThHLVs3WA4H9acbUtNAH#q=system+to+ram+pivot_root
|
||||
#http://dreamlayers.blogspot.fr/2012/10/running-linux-from-ram.html
|
||||
#http://unix.stackexchange.com/questions/126217/when-would-you-use-pivot-root-over-switch-root
|
||||
#https://wiki.gentoo.org/wiki/Zram
|
||||
|
||||
13
tasks/main.yml
Normal file
13
tasks/main.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
- name: Install script zram-swap.sh
|
||||
copy: src=files/usr/local/sbin/zram-swap.sh dest=/usr/local/sbin/zram-swap.sh owner=root group=root mode=0755
|
||||
- name: Install service zram-config.service
|
||||
copy: src=files/etc/systemd/system/zram-config.service dest=/etc/systemd/system/zram-config.service owner=root group=root mode=0644
|
||||
when: ansible_service_mgr == "systemd"
|
||||
- name: Install zram-config link service in init.d
|
||||
file: src=/usr/local/sbin/zram-swap.sh dest=/etc/init.d/zram-config owner=root group=root state=link
|
||||
when: ansible_service_mgr != "systemd"
|
||||
- name: start zram-config service
|
||||
service: name=zram-config enabled=yes state=started
|
||||
# when: ansible_service_mgr == "systemd"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue