added my Recipes
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Enable compressed swap in memory using zram
|
||||
Requires=zram-swap.service
|
||||
After=zram-swap.service
|
||||
|
||||
[Swap]
|
||||
What=/dev/zram0
|
||||
|
||||
[Install]
|
||||
WantedBy=swap.target
|
||||
85
meta-openembedded/meta-oe/recipes-extended/zram/zram/init
Normal file
85
meta-openembedded/meta-oe/recipes-extended/zram/zram/init
Normal file
@@ -0,0 +1,85 @@
|
||||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: zram
|
||||
# Required-Start:
|
||||
# Required-Stop:
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
|
||||
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
|
||||
# Included as part of antix-goodies package by anticapitalista <antiX@operamail.com>
|
||||
# This script was written by tradetaxfree and is found at http://crunchbanglinux.org/forums/topic/15344/zram-a-good-idea/
|
||||
# Copy this script (as root) from /usr/local/bin to /etc/init.d and then #update-rc.d zram defaults
|
||||
# After booting verify the module is loaded with: lsmod | grep zram
|
||||
### END INIT INFO
|
||||
set -e
|
||||
|
||||
start() {
|
||||
# get the number of CPUs
|
||||
num_cpus=$(grep -c processor /proc/cpuinfo)
|
||||
# if something goes wrong, assume we have 1
|
||||
[ "$num_cpus" != 0 ] || num_cpus=1
|
||||
|
||||
# set decremented number of CPUs
|
||||
last_cpu=$((num_cpus - 1))
|
||||
|
||||
#default Factor % = 90 change this value here or create /etc/default/zram
|
||||
FACTOR=90
|
||||
#& put the above single line in /etc/default/zram with the value you want
|
||||
[ -f /etc/default/zram ] && . /etc/default/zram || true
|
||||
factor=$FACTOR # percentage
|
||||
|
||||
# get the amount of memory in the machine
|
||||
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
|
||||
mem_by_cpu=$(($memtotal/$num_cpus*$factor/100*1024))
|
||||
|
||||
# load dependency modules
|
||||
modprobe zram num_devices=$num_cpus
|
||||
echo "zram devices probed successfully"
|
||||
|
||||
# initialize the devices
|
||||
for i in $(seq 0 $last_cpu); do
|
||||
echo 1 > /sys/block/zram$i/reset
|
||||
echo $mem_by_cpu > /sys/block/zram$i/disksize
|
||||
# Creating swap filesystems
|
||||
mkswap /dev/zram$i
|
||||
# Switch the swaps on
|
||||
swapon -p 100 /dev/zram$i
|
||||
done
|
||||
}
|
||||
|
||||
stop() {
|
||||
# get the number of CPUs
|
||||
num_cpus=$(grep -c processor /proc/cpuinfo)
|
||||
|
||||
# set decremented number of CPUs
|
||||
last_cpu=$((num_cpus - 1))
|
||||
|
||||
# Switching off swap
|
||||
for i in $(seq 0 $last_cpu); do
|
||||
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
|
||||
swapoff /dev/zram$i
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
sleep 1
|
||||
rmmod zram
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
sleep 3
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart}"
|
||||
RETVAL=1
|
||||
esac
|
||||
exit $RETVAL
|
||||
19
meta-openembedded/meta-oe/recipes-extended/zram/zram/zram-swap-deinit
Executable file
19
meta-openembedded/meta-oe/recipes-extended/zram/zram/zram-swap-deinit
Executable file
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
device=$1
|
||||
if [ "$device" = "" ]; then
|
||||
echo "Usage: zram-swap-deinit <device>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sysblockdev=/sys/block/$(basename $device)
|
||||
if [ ! -d $sysblockdev ]; then
|
||||
echo "Block device not found in sysfs"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# zramctl -r is not suitable as it also removes the actual device. Recreating
|
||||
# it is non-trivial, especially if not /dev/zram0 is used...
|
||||
echo 1 > ${sysblockdev}/reset
|
||||
|
||||
31
meta-openembedded/meta-oe/recipes-extended/zram/zram/zram-swap-init
Executable file
31
meta-openembedded/meta-oe/recipes-extended/zram/zram/zram-swap-init
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
device=$1
|
||||
if [ "$device" = "" ]; then
|
||||
echo "Usage: zram-swap-init <device>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Allocate zram to be size of actual system memory
|
||||
# Note: zram is only allocated when used. When swapped pages compress with a
|
||||
# a 2:1 ratio zram will require 50% of system memory (while allowing to use
|
||||
# 150% memory).
|
||||
ZRAM_SIZE_PERCENT=100
|
||||
ZRAM_ALGORITHM=lz4
|
||||
|
||||
[ -f /etc/default/zram ] && . /etc/default/zram || true
|
||||
|
||||
memtotal=$(grep MemTotal /proc/meminfo | awk ' { print $2 } ')
|
||||
memzram=$(($memtotal*${ZRAM_SIZE_PERCENT}/100))
|
||||
|
||||
# Try loading zram module
|
||||
modprobe -q zram || true
|
||||
|
||||
zramctl -a ${ZRAM_ALGORITHM} -s ${memzram}KB $device
|
||||
mkswap -L "zram-swap" $device
|
||||
|
||||
devname="${device##*/}"
|
||||
if [ ! -z ${ZRAM_SIZE_LIMIT+x} ]; then
|
||||
echo ${ZRAM_SIZE_LIMIT} > /sys/block/$devname/mem_limit
|
||||
fi
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Create compressed swap in memory using zram
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
TimeoutStartSec=30sec
|
||||
ExecStart=@LIBEXECDIR@/zram-swap-init /dev/zram0
|
||||
ExecStop=@LIBEXECDIR@/zram-swap-deinit /dev/zram0
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
for i in $(grep '^/dev/zram' /proc/swaps | awk '{ print $1 }'); do
|
||||
swapoff "$i" && zramctl --reset "$i"
|
||||
done
|
||||
50
meta-openembedded/meta-oe/recipes-extended/zram/zram_0.2.bb
Normal file
50
meta-openembedded/meta-oe/recipes-extended/zram/zram_0.2.bb
Normal file
@@ -0,0 +1,50 @@
|
||||
SUMMARY = "Linux zram compressed in-memory swap"
|
||||
LICENSE = "MIT"
|
||||
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
|
||||
|
||||
inherit update-rc.d systemd
|
||||
|
||||
RDEPENDS:${PN} = "kmod \
|
||||
${@bb.utils.contains('DISTRO_FEATURES','systemd','util-linux','util-linux-swaponoff',d)}"
|
||||
RRECOMMENDS:${PN} = "kernel-module-zram"
|
||||
|
||||
PR = "r3"
|
||||
|
||||
SRC_URI = " \
|
||||
file://init \
|
||||
file://zram-swap-init \
|
||||
file://zram-swap-deinit \
|
||||
file://zram-swap.service \
|
||||
file://dev-zram0.swap \
|
||||
"
|
||||
|
||||
do_install () {
|
||||
# Install systemd related configuration file
|
||||
if ${@bb.utils.contains('DISTRO_FEATURES', 'sysvinit', 'true', 'false', d)}; then
|
||||
install -d ${D}${sysconfdir}/init.d
|
||||
install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/zram
|
||||
fi
|
||||
|
||||
if ${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'true', 'false', d)}; then
|
||||
install -d ${D}${libexecdir}
|
||||
install -m 0755 ${WORKDIR}/zram-swap-init ${D}${libexecdir}
|
||||
install -m 0755 ${WORKDIR}/zram-swap-deinit ${D}${libexecdir}
|
||||
install -d ${D}${systemd_unitdir}/system
|
||||
install -m 0644 ${WORKDIR}/zram-swap.service ${D}${systemd_unitdir}/system/zram-swap.service
|
||||
sed -i -e "s,@LIBEXECDIR@,${libexecdir},g" ${D}${systemd_unitdir}/system/zram-swap.service
|
||||
install -m 0644 ${WORKDIR}/dev-zram0.swap ${D}${systemd_unitdir}/system/dev-zram0.swap
|
||||
fi
|
||||
}
|
||||
|
||||
FILES:${PN} = " \
|
||||
${sysconfdir} \
|
||||
${systemd_unitdir} \
|
||||
${libexecdir} \
|
||||
"
|
||||
INITSCRIPT_NAME = "zram"
|
||||
INITSCRIPT_PARAMS = "start 05 2 3 4 5 . stop 22 0 1 6 ."
|
||||
|
||||
RPROVIDES:${PN} += "${PN}-systemd"
|
||||
RREPLACES:${PN} += "${PN}-systemd"
|
||||
RCONFLICTS:${PN} += "${PN}-systemd"
|
||||
SYSTEMD_SERVICE:${PN} = "dev-zram0.swap"
|
||||
Reference in New Issue
Block a user