from azlux/zram

Zram implementation
This commit is contained in:
azlux 2019-03-13 15:29:37 +01:00 committed by GitHub
commit 36a88b8933
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 4 deletions

View File

@ -60,6 +60,17 @@ If you have issue with apache2, you can try to add `apache2.service` next to oth
The log for log2ram will be written at: `/var/log/log2ram.log`
| Compressor name | Ratio | Compression | Decompress. |
|------------------------|----------|-------------|-------------|
|zstd 1.3.4 -1 | 2.877 | 470 MB/s | 1380 MB/s |
|zlib 1.2.11 -1 | 2.743 | 110 MB/s | 400 MB/s |
|brotli 1.0.2 -0 | 2.701 | 410 MB/s | 430 MB/s |
|quicklz 1.5.0 -1 | 2.238 | 550 MB/s | 710 MB/s |
|lzo1x 2.09 -1 | 2.108 | 650 MB/s | 830 MB/s |
|lz4 1.8.1 | 2.101 | 750 MB/s | 3700 MB/s |
|snappy 1.1.4 | 2.091 | 530 MB/s | 1800 MB/s |
|lzf 3.6 -1 | 2.077 | 400 MB/s | 860 MB/s |
###### Now, muffins for everyone!

3
install.sh Normal file → Executable file
View File

@ -21,4 +21,5 @@ install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram
# Make sure we start clean
rm -rf /var/hdd.log
echo "##### Reboot to activate log2ram #####"
echo "##### Reboot to activate log2ram #####"
echo "##### edit /etc/log2ram.conf to configure options ####"

25
log2ram
View File

@ -50,21 +50,44 @@ wait_for () {
done
}
createZramLogDrive () {
# Check Zram Class created
if [ ! -d "/sys/class/zram-control" ]; then
modprobe zram
RAM_DEV='0'
else
RAM_DEV=$(cat /sys/class/zram-control/hot_add)
fi
echo ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm
echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize
echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit
mke2fs -t ext4 /dev/zram${RAM_DEV}
}
case "$1" in
start)
[ -d $HDD_LOG/ ] || mkdir $HDD_LOG/
mount --bind $RAM_LOG/ $HDD_LOG/
mount --make-private $HDD_LOG/
wait_for $HDD_LOG
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size="$SIZE" log2ram $RAM_LOG/
if [ "$ZL2R" = true ]; then
createZramLogDrive
mount -t ext4 -o nosuid,noexec,nodev,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/
else
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/
fi
wait_for $RAM_LOG
syncFromDisk
;;
stop)
syncToDisk
#ZRAM_LOG=$(awk '$2 == "/var/log" {print $1}' /proc/mounts)
#ZRAM_LOG=$(echo ${ZRAM_LOG} | grep -o -E '[0-9]+')
umount -l $RAM_LOG/
umount -l $HDD_LOG/
# Unsure as even with Root permision denied
#echo ${ZRAM_LOG} > /sys/class/zram-control/hot_remove
;;
write)

View File

@ -14,4 +14,20 @@ USE_RSYNC=false
# If there are some errors with available RAM space, a system mail will be send
# Change it to false and you will have only a log if there is no place on RAM anymore.
MAIL=true
MAIL=true
# **************** Zram backing conf *************************************************
# ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs
ZL2R=false
# COMP_ALG this is any compression algorithm listed in /proc/crypto
# lz4 is fastest with lightest load but deflate (zlib) and Zstandard (zstd) give far better compression ratios
# lzo is very close to lz4 and may with some binaries have better optimisation
# COMP_ALG=lz4 for speed or Zstd for compression, lzo or zlib if optimisation or availabilty is a problem
COMP_ALG=lz4
# LOG_DISK_SIZE is the uncompressed disk size. Note zram uses about 0.1% of the size of the disk when not in use
# LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE
# lzo/lz4=2.1:1 compression ratio zlib=2.7:1 zstandard=2.9:1
# Really a guestimate of a bit bigger than compression ratio whilst minimising 0.1% mem usage of disk size
LOG_DISK_SIZE=100M

View File

@ -1,7 +1,7 @@
[Unit]
Description=Log2Ram
DefaultDependencies=no
Before=basic.target rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target apache2.service
Before=basic.target rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target zram-swap-conf.service apache2.service
After=local-fs.target
Conflicts=shutdown.target reboot.target halt.target
RequiresMountsFor=/var/log /var/hdd.log

0
uninstall.sh Normal file → Executable file
View File