zram trimming by writing zero pages
- by qdot
I'm using ZRAM as a backing block device for /tmp filesystem in the following manner:
echo 8000000000 > /sys/block/zram0/disksize
mkfs.ext4 -O dir_nlink,extent,extra_isize,flex_bg,^has_journal,uninit_bg -m0 \
-b 4096 -L "zram0" /dev/zram0
mount -o barrier=0,commit=240,noatime,nodev,nosuid /dev/zram0 /tmp
chmod aogu+rwx /tmp
It works out reasonably well for me - however, there is an issue here - when files are removed, they are not zero'ed, so the ZRAM does not remote the compressed pages. Obviously running
dd if=/dev/zero of=/tmp/ZERO bs=1M count={free-space-some-rest}; rm /tmp/ZERO
clears it up in the ZRAM - it gets notified of zero-pages and shrinks the store.
How can I get ext4 to zero used pages on delete? Also, any other suggestions on how to optimize it?