Skip to content

Instantly share code, notes, and snippets.

@gyakovlev
Created May 30, 2021 20:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyakovlev/b9361871a76b4e72f1c82b8df502d6ba to your computer and use it in GitHub Desktop.
Save gyakovlev/b9361871a76b4e72f1c82b8df502d6ba to your computer and use it in GitHub Desktop.
/etc/udev/rules.d/10-zram.rules
# Key zram params:
# mem_limit: maximum amount of ram it will ever be allowed to eat.
# disksize: filesytem size, may be larger than mem_limit, because of compression.
# comp_algorithm: lz4 gives about 2x compression for most builds.
# backing_dev: device to dump uncompressable pages to, must be set before size. Must use a script to drop pages, not automatic.
#
# Key mkfs options:
# '-e remount-ro' to go read-only on errors, it stops the build properly
# '-m 0' to skip root-only reserved 5% of space
# '-O ^has_journal' to skip journal. it's disposable FS and we will never run fsck on it
# '-E root_owner=250:250' to make it owned by portage:portage right away
# '-T news' to optimize for many small files
#
# Example fstab line with some features disabled as irrelevant for disposable block device/fs
# /dev/zram0 /var/tmp/portage ext4 rw,noatime,discard,nobarrier 0 0
#
# Don't forget to load the module on boot, so that rule fires.
# echo 'zram' > /etc/modules-load.d/zram.conf
KERNEL=="zram0", SUBSYSTEM=="block", DRIVER=="", ACTION=="add", ATTR{initstate}=="0", ATTR{comp_algorithm}="lz4", ATTR{mem_limit}="48G", ATTR{disksize}="96G", RUN+="/sbin/mkfs.ext4 -v -e remount-ro -m 0 -O ^has_journal -E root_owner=250:250 -T news -L portage-$name $env{DEVNAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment