#!/bin/bash TOTAL_MB=100 TOTAL_BYTES=$((TOTAL_MB << 20)) ROOT_CG=/sys/fs/cgroup ZRAM_DEV=/dev/zram0 TMPFS=./tmpfs A_ASCII=$(printf '%d' "'A") function cleanup() { rm -rf $TMPFS/* umount $TMPFS rmdir $TMPFS if swapon -s | grep -q $ZRAM_DEV; then swapoff $ZRAM_DEV fi echo 1 > /sys/block/zram0/reset rmdir $ROOT_CG/test } trap cleanup EXIT echo 1 > /sys/module/zswap/parameters/shrinker_enabled # Initialize tmpfs mkdir $TMPFS mount -t tmpfs none $TMPFS # Initialize zram echo $((TOTAL_MB*2))m > /sys/block/zram0/disksize mkswap -L zram0 $ZRAM_DEV swapon $ZRAM_DEV # Initialize cgroup echo "+memory" > $ROOT_CG/cgroup.subtree_control mkdir $ROOT_CG/test # Create a test tmpfs file containing the alphabet on repeat ( echo 0 > $ROOT_CG/test/cgroup.procs s=$(printf '%s' {A..Z}) yes $s | dd iflag=fullblock of=$TMPFS/test bs=1M count=$TOTAL_MB status=none ) # Reclaim everything (invoking the zswap shrinker) echo $TOTAL_BYTES > $ROOT_CG/test/memory.reclaim