From 34d32373c397b929489f8e7808157d34bd474fb9 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Fri, 8 Mar 2019 04:58:06 +0000 Subject: [PATCH 1/7] Add zram functionality --- install.sh | 0 log2ram | 27 ++++++++++++++++++++++++++- log2ram.conf | 18 +++++++++++++++++- uninstall.sh | 0 4 files changed, 43 insertions(+), 2 deletions(-) mode change 100644 => 100755 install.sh mode change 100644 => 100755 uninstall.sh diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 diff --git a/log2ram b/log2ram index 127a703..46eacd6 100755 --- a/log2ram +++ b/log2ram @@ -50,21 +50,46 @@ 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/ + if [ "$ZL2R" = true ]; then + createZramLogDrive + fi wait_for $HDD_LOG - mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size="$SIZE" log2ram $RAM_LOG/ + if [ "$ZL2R" = true ]; then + 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) diff --git a/log2ram.conf b/log2ram.conf index 2636075..d5fbd2c 100644 --- a/log2ram.conf +++ b/log2ram.conf @@ -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 \ No newline at end of file +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 + diff --git a/uninstall.sh b/uninstall.sh old mode 100644 new mode 100755 From 17f82073912a09c5298bf49c6f8a789132b7443d Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Fri, 8 Mar 2019 18:21:27 +0000 Subject: [PATCH 2/7] systemd conflict zram-swap-config --- log2ram.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log2ram.service b/log2ram.service index 89f1cb8..9810c64 100644 --- a/log2ram.service +++ b/log2ram.service @@ -3,7 +3,7 @@ Description=Log2Ram DefaultDependencies=no Before=basic.target rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target apache2.service After=local-fs.target -Conflicts=shutdown.target reboot.target halt.target +Conflicts=shutdown.target reboot.target halt.target zram-swap-config.target RequiresMountsFor=/var/log /var/hdd.log IgnoreOnIsolate=yes From f86c90f9d6982a2394605e83b6d74871b49f961c Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Sat, 9 Mar 2019 00:24:14 +0000 Subject: [PATCH 3/7] clean up --- log2ram | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log2ram b/log2ram index 46eacd6..808e98f 100755 --- a/log2ram +++ b/log2ram @@ -52,7 +52,7 @@ wait_for () { createZramLogDrive () { # Check Zram Class created - if [ ! -d '/sys/class/zram-control' ]; then + if [ ! -d "/sys/class/zram-control" ]; then modprobe zram RAM_DEV='0' else From 12e7a068a82f0f79be29d1de0d1febd77a445f3a Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Sat, 9 Mar 2019 03:24:27 +0000 Subject: [PATCH 4/7] remove ignore systemd --- install.sh | 3 ++- log2ram.service | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index 629a94f..62e8742 100755 --- a/install.sh +++ b/install.sh @@ -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 ####" diff --git a/log2ram.service b/log2ram.service index 9810c64..78e94aa 100644 --- a/log2ram.service +++ b/log2ram.service @@ -2,10 +2,10 @@ Description=Log2Ram DefaultDependencies=no Before=basic.target rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target apache2.service -After=local-fs.target -Conflicts=shutdown.target reboot.target halt.target zram-swap-config.target +After=local-fs.target zram-swap-config.target +Conflicts=shutdown.target reboot.target halt.target RequiresMountsFor=/var/log /var/hdd.log -IgnoreOnIsolate=yes +#IgnoreOnIsolate=yes [Service] Type=oneshot From c72bc414570cd0816c2b1c8150947dc0c661b783 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Sat, 9 Mar 2019 04:55:45 +0000 Subject: [PATCH 5/7] systemd tests due to mount wait rountine --- log2ram.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/log2ram.service b/log2ram.service index 78e94aa..89f1cb8 100644 --- a/log2ram.service +++ b/log2ram.service @@ -2,10 +2,10 @@ Description=Log2Ram DefaultDependencies=no Before=basic.target rsyslog.service syslog.target systemd-journald.service sysinit.target shutdown.target apache2.service -After=local-fs.target zram-swap-config.target +After=local-fs.target Conflicts=shutdown.target reboot.target halt.target RequiresMountsFor=/var/log /var/hdd.log -#IgnoreOnIsolate=yes +IgnoreOnIsolate=yes [Service] Type=oneshot From e2e1c65c5f55d79b2bef03e2fda1deb5c8cc9507 Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Sat, 9 Mar 2019 14:43:41 +0000 Subject: [PATCH 6/7] make zram lines create and mount immediate --- log2ram | 4 +--- log2ram.service | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/log2ram b/log2ram index 808e98f..1f60ef3 100755 --- a/log2ram +++ b/log2ram @@ -69,11 +69,9 @@ case "$1" in [ -d $HDD_LOG/ ] || mkdir $HDD_LOG/ mount --bind $RAM_LOG/ $HDD_LOG/ mount --make-private $HDD_LOG/ - if [ "$ZL2R" = true ]; then - createZramLogDrive - fi wait_for $HDD_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/ diff --git a/log2ram.service b/log2ram.service index 89f1cb8..d97e76d 100644 --- a/log2ram.service +++ b/log2ram.service @@ -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 From 08264d3d3f3c3f919453a797a6dbb22323158ffe Mon Sep 17 00:00:00 2001 From: StuartIanNaylor Date: Sat, 9 Mar 2019 15:24:28 +0000 Subject: [PATCH 7/7] Update README.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index c55f991..e24f16e 100644 --- a/README.md +++ b/README.md @@ -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!