pax_global_header00006660000000000000000000000064134357130360014517gustar00rootroot0000000000000052 comment=c4ae29e0d2d683ecde9760b1393fb16a175dd232 zram-tools-0.3.2.1/000077500000000000000000000000001343571303600137675ustar00rootroot00000000000000zram-tools-0.3.2.1/COPYING000066400000000000000000000013671343571303600150310ustar00rootroot00000000000000Copyright (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.2.1/README.md000066400000000000000000000012551343571303600152510ustar00rootroot00000000000000zram-tools ========== Scripts for managing zram devices, 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. zram doesn't natively support multiple processors, so by default a zram device is set up for every core and then swap is initialized on those devices. This is configurable in the zramswap config file. zramswap stop ------------- Removes all current zram swap spaces and devices. zramswap status --------------- shows information on data stored in zram swap. /etc/default/zramswap --------------------- Configuration file for zramswap. zram-tools-0.3.2.1/conf/000077500000000000000000000000001343571303600147145ustar00rootroot00000000000000zram-tools-0.3.2.1/conf/zramswap000066400000000000000000000007111343571303600165020ustar00rootroot00000000000000# Specifies amount of zram devices to create. # By default, zramswap-start will use all available cores. #CORES=1 # Specifies the amount of RAM that should be used for zram # based on a percentage the total amount of available memory #PERCENTAGE=10 # Specifies a static amount of RAM that should be used for # the ZRAM devices, this is in MiB #ALLOCATION=256 # Specifies the priority for the swap devices, see swapon(2) # for more details. #PRIORITY=100 zram-tools-0.3.2.1/zramswap000077500000000000000000000054121343571303600155630ustar00rootroot00000000000000#!/bin/bash # This script does the following: # zramswap start: # * Space is assigned to each zram device, then swap is initialized on # there # zramswap stop: # * Undo start # * Also attempts to remove zram module at the end # TODO: # * Migrate to using zramctl from util-linux for the setup, # (this will close debian bug #917643): # then also: # - add option for compression algorythm # - ammount of compression streams # - Make use of the zramctl stats too function start { #Set some defaults: ALLOCATION=256 # ZRAM Swap you want assigned, in MiB PRIORITY=100 # Swap priority, see swapon(2) for more details # Get amount of available CPU cores, set to 1 if not detected correctly if [ ! -f /proc/cpuinfo ]; then echo "WARNING: Can't find /proc/cpuinfo, is proc mounted?" echo " Using a single core for zramswap..." CORES=1 else CORES=$(grep -c ^processor /proc/cpuinfo) fi # Override above from config file, if it exists if [ -f /etc/default/zramswap ]; then . /etc/default/zramswap fi ALLOCATION=$((ALLOCATION * 1024 * 1024)) # convert amount from MiB to bytes if [ -n "$PERCENTAGE" ]; then totalmemory=$(awk '/MemTotal/{print $2}' /proc/meminfo) # in KiB ALLOCATION=$((totalmemory * 1024 * $PERCENTAGE / 100)) fi # Initialize zram devices modprobe zram num_devices=$CORES # Assign memory to zram devices, initialize swap and activate # Decrementing $CORE, because cores start counting at 0 for CORE in $(seq 0 $(($CORES - 1))); do echo $(($ALLOCATION / $CORES)) > /sys/block/zram$CORE/disksize mkswap /dev/zram$CORE swapon -p $PRIORITY /dev/zram$CORE done } function status { orig_data_size="0" for file in /sys/block/zram*/*_data_size ; do if [ $file = "/sys/block/zram*/*_data_size" ]; then compress_ratio="0" break fi read file_content < $file what=$(basename $file) eval "$what=\$(($what + $file_content))" compress_ratio=$(echo "scale=2; $orig_data_size / $compr_data_size" | bc) done echo "compr_data_size: $((compr_data_size / 1024)) KiB" echo "orig_data_size: $((orig_data_size / 1024)) KiB" echo "compression-ratio: $compress_ratio" } function stop { for swapspace in $(swapon -s | awk '/zram/{print $1}'); do swapoff $swapspace done modprobe -r zram } function usage { echo "Usage:" echo " zramswap start - start zram swap" echo " zramswap stop - stop zram swap" echo " zramswap status - prints some statistics" } if [ "$1" = "start" ]; then start fi if [ "$1" = "stop" ]; then stop fi if [ "$1" = "status" ]; then status fi if [ "$1" = "" ]; then usage fi zram-tools-0.3.2.1/zramswap.8000066400000000000000000000030421343571303600157230ustar00rootroot00000000000000.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.2.1/zramswap.service000066400000000000000000000004521343571303600172160ustar00rootroot00000000000000[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