zram-tools-0.3.3/0000755000175000017500000000000013750020340014004 5ustar jonathanjonathanzram-tools-0.3.3/zramswap0000755000175000017500000000455613750014601015613 0ustar jonathanjonathan#!/bin/bash # This script does the following: # zramswap start: # Space is assigned to the zram device, then swap is initialized and enabled. # zramswap stop: # Somewhat potentially dangerous, removes zram module at the end # https://github.com/torvalds/linux/blob/master/Documentation/blockdev/zram.txt readonly CONFIG="/etc/default/zramswap" readonly SWAP_DEV="/dev/zram0" if command -v logger >/dev/null; then function elog { logger -s "Error: $*" exit 1 } function wlog { logger -s "$*" } else function elog { echo "Error: $*" exit 1 } function wlog { echo "$*" } fi function start { wlog "Starting Zram" # Load config test -r "${CONFIG}" || wlog "Cannot read config from ${CONFIG} continuing with defaults." source "${CONFIG}" 2>/dev/null # Set defaults if not specified : "${ALGO:=lz4}" "${SIZE:=256}" "${PRIORITY:=100}" SIZE=$((SIZE * 1024 * 1024)) # convert amount from MiB to bytes # Prefer percent if it is set if [ -n "${PERCENT}" ]; then readonly TOTAL_MEMORY=$(awk '/MemTotal/{print $2}' /proc/meminfo) # in KiB readonly SIZE="$((TOTAL_MEMORY * 1024 * PERCENT / 100))" fi modprobe zram || elog "inserting the zram kernel module" echo -n "${ALGO}" > /sys/block/zram0/comp_algorithm || elog "setting compression algo to ${ALGO}" echo -n "${SIZE}" > /sys/block/zram0/disksize || elog "setting zram device size to ${SIZE}" mkswap "${SWAP_DEV}" || elog "initialising swap device" swapon -p "${PRIORITY}" "${SWAP_DEV}" || elog "enabling swap device" } function status { test -x "$(which zramctl)" || elog "install zramctl for this feature" test -b "${SWAP_DEV}" || elog "${SWAP_DEV} doesn't exist" # old zramctl doesn't have --output-all #zramctl --output-all zramctl "${SWAP_DEV}" } function stop { wlog "Stopping Zram" test -b "${SWAP_DEV}" || wlog "${SWAP_DEV} doesn't exist" swapoff "${SWAP_DEV}" 2>/dev/null || wlog "disabling swap device: ${SWAP_DEV}" modprobe -r zram || elog "removing zram module from kernel" } function usage { cat << EOF Usage: zramswap (start|stop|restart|status) EOF } case "$1" in start) start;; stop) stop;; restart) stop && start;; status) status;; "") usage;; *) elog "Unknown option $1";; esac zram-tools-0.3.3/conf/0000755000175000017500000000000013750014172014737 5ustar jonathanjonathanzram-tools-0.3.3/conf/zramswap0000644000175000017500000000153113750014172016526 0ustar jonathanjonathan# Compression algorithm selection # speed: lz4 > zstd > lzo # compression: zstd > lzo > lz4 # This is not inclusive of all that is available in latest kernels # See /sys/block/zram0/comp_algorithm (when zram module is loaded) to see # what is currently set and available for your kernel[1] # [1] https://github.com/torvalds/linux/blob/master/Documentation/blockdev/zram.txt#L86 #ALGO=lz4 # Specifies the amount of RAM that should be used for zram # based on a percentage the total amount of available memory # This takes precedence and overrides SIZE below #PERCENT=50 # Specifies a static amount of RAM that should be used for # the ZRAM devices, this is in MiB #SIZE=256 # Specifies the priority for the swap devices, see swapon(2) # for more details. Higher number = higher priority # This should probably be higher than hdd/ssd swaps. #PRIORITY=100 zram-tools-0.3.3/COPYING0000644000175000017500000000136713750012525015054 0ustar jonathanjonathanCopyright (c) 2014-2019, Jonathan Carter Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. zram-tools-0.3.3/.gitignore0000644000175000017500000000021713750012525016002 0ustar jonathanjonathandebian/zram-tools/ debian/zram-tools.substvars debian/zram-tools.postrm.debhelper debian/files debian/debhelper-build-stamp debian/.debhelper/ zram-tools-0.3.3/README.md0000644000175000017500000000074113750014230015266 0ustar jonathanjonathanzram-tools ========== Scripts for managing zram device, currently only for zramswap, but more tools could be implemented in the future, such as managing /tmp on zram. zramswap start -------------- Sets up zram devices and initializes swap. zramswap stop ------------- Removes all current zram swap space and device. zramswap status --------------- Shows information on data stored in zram swap. /etc/default/zramswap --------------------- Configuration file for zramswap. zram-tools-0.3.3/zramswap.80000644000175000017500000000304213750012525015746 0ustar jonathanjonathan.TH "zramswap" 1 "2018-10-04" "zramswap" .SH NAME zramswap \- configure swap on zram .SH SYNOPSIS .B zramswap [OPTION] .SH DESCRIPTION zram is a Linux feature that allows a user to create compressed ramdisks. zramswap sets up swap in zram, which effectively allows you to compress memory. Common use cases: On machines with low memory, mitigates the tedious situation where the machine is out of memory and then it starts swapping to disk only to lose a large amount of disk bandwidth. On machines where the main swap file is on flash memory, zramswap may only provide marginal performance increase (especially on fast SSD media), however, it will prevent some amount of wear on your flash memory. zramswap is especially beneficial if your main flash is on SD/MMC/CF card. On servers that run many virtual machines or containers, zramswap allows you to optimise memory usage by swapping out data that's not often accessed, but when a user needs to access it, it will be available fast. It allows you to overcommit on memory with a negligible hit on your application performance (and often an improvement in performance where you can use more main memory for filesystem cache). .SH OPTIONS Usage: zramswap [OPTION] .B ZRAMSWAP Options \fB\ start\fR .RS Sets up zram swap. .RE \fB\ stop\fR .RS Tears down zram swap. .RE \fB\ status\fR .RS Displays zram swap usage and compression ratio. .RE .SH REPORTING BUGS Please file issues at: https://salsa.debian.org/jcc/zram-tools/issues .SH AUTHORS This manual page was written by Jonathan Carter zram-tools-0.3.3/zramswap.service0000644000175000017500000000045213750012525017241 0ustar jonathanjonathan[Unit] Description=Linux zramswap setup Documentation=man:zramswap(8) [Service] EnvironmentFile=-/etc/default/zramswap ExecStart=/usr/sbin/zramswap start ExecStop=/usr/sbin/zramswap stop ExecReload=/usr/sbin/zramswap restart Type=oneshot RemainAfterExit=true [Install] WantedBy=multi-user.target