Giter Club home page Giter Club logo

zram-config's Introduction

zram-config

License ShellCheck Test

Overview

This is a complete zram-config utility for swap, directories, and logs to reduce SD, NAND and eMMC block wear. Furthermore zram allows near RAM speed access to working directories, and prevents frequent writing to persistent storage. Even more importantly, data stored in zram can be compressed to conserve memory.

A table located at /etc/ztab is used to configure any number and type of zram devices. Using the table an OverlayFS mount is used to mount the newly created zram device as the upper filesystem of the OverlayFS. OverlayFS is used so that files do not need to be copied from persistent storage to RAM on startup. In theory this should allow for faster boots and larger directories as no complete directory copy is needed. A modified version of kmxz/overlayfs-tools is used to implement the OverlayFS sync logic.

This tool is primarily developed and tested against Raspberry Pi OS. Any Debian derivative should also work out of the box, however there is no guarantee. Experimental Alpine support has also been added, other distributions may work but once again, there is no guarantee.

A Brief Usage Guide

Table of Contents

  1. Install
  2. Update
  3. Uninstall
  4. Configure
  5. Is it working?
  6. Known issues
  7. Performance
  8. Reference

Install

sudo apt-get install git
git clone https://github.com/ecdye/zram-config
sudo ./zram-config/install.bash

Manually start or stop

On Debian, use sudo systemctl {start|stop} zram-config.service to start or stop zram-config. On Alpine, use sudo rc-service zram-config {start|stop}. This will ensure that any changes are properly synced to the persistent storage before system poweroff.

Sync files to disk

Run sudo zram-config sync to sync any changes in the zram filesystems managed by zram-config to persistent storage. If you have concerns about losing data due to sudden power loss you could use this to ensure that changes are synced to disk periodically.

A default sync service that will sync files to disk every night can be installed by running the following.

sudo /path/to/zram-config/install.bash sync

Note that this sync service is not installed by default, you must install it separately.

Update

sudo /path/to/zram-config/update.bash

Uninstall

sudo /usr/local/share/zram-config/uninstall.bash

Configure

All configuration is done in the /etc/ztab file.

Use # to comment out any line, add new drives with the first column providing the drive type and then drive details separated by tab characters.

All algorithms in /proc/crypto are supported but only lzo-rle, lzo, lz4, and zstd have zramctl text strings; lzo-rle is the fastest with zstd having much better text compression.

mem_limit is the compressed memory limit and will set a hard memory limit for the system admin. Set to 0 to disable the mem_limit.

disk_size is the maximum size of the uncompressed memory. It should be set to roughly 150% of mem_limit depending on the algorithm and how compressible the input files are. Don't make it much higher than the compression algorithm (and the additional zram overhead) is capable of because there is a ~0.1% memory overhead when empty.

swap_priority will set zram over alternative swap devices.

page-cluster 0 means tuning to singular pages rather than the default 3 which caches 8 for HDD tuning, which can lower latency.

swappiness 150 because the improved performance of zram allows more usage without any adverse affects from the default of 60. It can be raised up to 200 which will improve performance in high memory pressure situations.

target_dir is the directory you wish to hold in zram, and the original will be moved to a bind mount bind_dir and is synchronized on start, stop, and write commands.

bind_dir is the directory where the original directory will be mounted for sync purposes. Usually in /opt or /var, name optional.

oldlog_dir will enable log-rotation to an off device directory while retaining only live logs in zram. Usually in /opt or /var, name optional.

If you need multiple zram swaps or zram directories, just create another entry in /etc/ztab. To do this simply add the new entries to the /etc/ztab, if you need to edit an active zram device you must stop zram with sudo systemctl stop zram-config.service on Debian or sudo rc-service zram-config stop on Alpine and then edit any entries you need to. Once finished, start zram using sudo systemctl start zram-config.service or sudo rc-service zram-config start which will only add the new entries if zram is already running.

Example configuration

# swap	alg		mem_limit	disk_size	swap_priority	page-cluster	swappiness
swap	lzo-rle		250M		750M		75		0		150

# dir	alg		mem_limit	disk_size	target_dir		bind_dir
#dir	lzo-rle		50M		150M		/home/pi		/opt/zram/pi.bind

# log	alg		mem_limit	disk_size	target_dir		bind_dir		oldlog_dir
log	lzo-rle		50M		150M		/var/log		/opt/zram/log.bind	/opt/zram/oldlog

Is it working?

Run zramctl in your preferred shell and if you see and output similar to below, yes it is working. Please note that if the zramctl command is missing, you will need to install the util-linux package to have a convenient way to view the zram status.

pi@raspberrypi:~$ zramctl
NAME       ALGORITHM DISKSIZE  DATA  COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram1 lzo-rle       150M 16.9M 373.2K  692K       4 /opt/zram/zram1
/dev/zram0 lzo-rle       750M    4K    87B   12K       4 [SWAP]

To view more information on zram usage take a look at the following commands and their corresponding output.

pi@raspberrypi:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/root        3833792 1368488   2275172  38% /
devtmpfs          437356       0    437356   0% /dev
tmpfs             471980       0    471980   0% /dev/shm
tmpfs             188792     440    188352   1% /run
tmpfs               5120       0      5120   0% /run/lock
/dev/mmcblk0p1    258095   49436    208660  20% /boot
/dev/zram1        132240   18440    103048  16% /opt/zram/zram1
overlay1          132240   18440    103048  16% /var/log
tmpfs              94396       0     94396   0% /run/user/1000
pi@raspberrypi:~$ free -h
               total        used        free      shared  buff/cache   available
Mem:           921Mi        46Mi       750Mi       0.0Ki       124Mi       819Mi
Swap:          849Mi          0B       849Mi
pi@raspberrypi:~$ swapon
NAME       TYPE      SIZE USED PRIO
/var/swap  file      100M   0B   -2
/dev/zram0 partition 750M   0B   75

Known issues

Conflicts with services

When running zram on a directory that has services accessing it, they will need to be stopped before starting or stopping zram. For example, in the log zram device zram-config stops the services that run by default in the /var/log directory before starting or stopping. If your system has other services that write to /var/log that are not stopped zram may fail to properly sync files and remove the zram device when stopping, and will probably outright fail to start when initializing a zram device. This issue is not limited to logs, if you are running zram on another directoy that is written to by a service you will run into the same issue.

For an example on how this project internally takes care of this issue see the serviceConfiguration function in zram-config. A more in depth version of this function is used in the openHAB branch that can be referenced as well.

Swapiness on older Linux kernel versions

When running zram swap on Linux kernel versions older than 5.8 swappiness has a maximum value of 100. If you observe issues runnning on older kernel versions try setting the default value of 150 back to 100.

Raspberry Pi 4 8GB compatibility

The Raspberry Pi 4 8GB model can exhibit issues with zram due to a Linux kernel bug. This bug has been fixed as of Raspberry Pi Kernel version 1.20210527. See raspberrypi/linux@cef3970381 for more details about the issue.

Performance

LZO-RLE offers the best performance and is probably the best choice, and from kernel 5.1 and onward it is the default. If you are not running at least kernel 5.1 then LZO-RLE may not be supported by your system and you may need to change /etc/ztab accordingly. You might have text based low impact directories such as /var/log or /var/cache where a highly effective text compressor such as zstd is optimal, with effective compression that can be up to 200% of what LZO may achieve especially with text. With /tmp and /run, zram is unnecessary because they are RAM mounted as tmpfs and, if memory gets short, then the zram swap will provide extra. It is only under intense loads that the slight overhead of zram compression becomes noticeable.

This chart from facebook/zstd provides a good benchmark for the performance of the different compressors.

Compressor name Ratio Compression Decompression
zstd 1.5.1 -1 2.887 530 MB/s 1700 MB/s
zlib 1.2.11 -1 2.743 95 MB/s 400 MB/s
brotli 1.0.9 -0 2.702 395 MB/s 450 MB/s
quicklz 1.5.0 -1 2.238 540 MB/s 760 MB/s
lzo1x 2.10 -1 2.106 660 MB/s 845 MB/s
lz4 1.9.3 2.101 740 MB/s 4500 MB/s
lzf 3.6 -1 2.077 410 MB/s 830 MB/s
snappy 1.1.9 2.073 550 MB/s 1750 MB/s

Reference

https://www.kernel.org/doc/Documentation/blockdev/zram.txt

https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

zram-config's People

Contributors

dependabot[bot] avatar ecdye avatar flavorplus avatar mstormi avatar stuartiannaylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zram-config's Issues

bad persistence on ZRAM

just FYI, I ran into an extraordinarily mean error on my own production system that took me half a day to find out
(with shutters all down and heating off ☹️ ):

Some .rrd file (rrd4j persistent storage) was broken and that made Java crash repeatedly.
But deleting it didn't help. Persistence files are on ZRAM but seems when I deleted it ZRAM took the older version from the lowerFS and seems that was broken in the first place.
Duh.

No, don't know yet what to make of that, just documenting for now.

Maybe one thing is we should extend the permissions_corrections() apply to /opt/zram/.bind/ too (the lowerFS copies of
all the ZRAM'ed dirs).

doesn't sync on reboot

I have a problem of zram data sometimes to disappear on reboot. It's an intermittent problem.

I've debugged an instance where the lazy unmount apparent didn't work and the routine returned without calling mergeOverlay()
On another occasion, it called mergeOverlay() but it didn't have files to sync although I create a date file before reboot in both cases.
Now as the shutdown sequence proceeded, data was lost.

Is it intentional to regularly/lazy unmount BEFORE mergeOverlay() ?

OverlayFS

I like the use of OverlayFS as large directory structures that would not be really possible to copy on the initial sync especially at boot become valid.

Like most things I am an OverlayFS noob and confused by the 2nd overlay directive copied from examples.
In some examples it is none and if you do a DF it seems to set the filesystem type description and a umount of the OverlayFS mount gives an output that the /opt/overlay mount doesn't exist.

I am struggling to find any direct documentation for that directive of as without it will look for a fstab entry.

mount --verbose --types overlay -o lowerdir=$BIND_DIR,upperdir=/opt/zram$RAM_DEV/upper,workdir=/opt/zram$RAM_DEV/workdir overlay $ZRAM_DIR

Also even though it will not error writing out to lower whilst mounted is supposedly a no-no.
Aufs is spin-lock crazy mad from what I can deduce from why some distro's and kernel say no and even though it would be an instant fix to writing out to lower I am slightly reluctant to make the switch.

Also wondering in ztab if log & dir entries should have a concat device option where a singular zram device is used with the sum of disksize and mem-limit entries if 1 and not if 0.

Anyway currently thinking about these 'issues/options' but if you have some input please do.

stop -> start sometimes results in crashed syslog service.

I happened to notice that about half the time when running the "stop -> start" commands to restart zram-config ... it results the syslog service being a "red" state and not running. Manually starting syslog seems to fix it sometime later.
I believe the syslog start / stop commands u have in the script are not working as intended. I can run the same command to stop syslog, but it always respawns on its own nearly instantaneously.

New feature - support for in ram volumes only

It would be nice to have ability to support in ram volumes only within /etc/ztab. For example, there can be introduced new mount type ram (or tmp) which will have one parameter less compared to dir (bind_dir is not needed). This will result into zram volume creation and direct mount without overlayFS into target_dir. Such option would be beneficial for the cases where some mount doesn't need to be backed by disk at all, e.g. /tmp.

It is possible to configure to create own startup scripts to achieve desired behavior, however it would be very nice to have it configurable at one place /etc/ztab.

syncToDisk ?

I noticed the syncToDisk command is commented out in zram-config
What does it mean, will changes to upper layer FS (in ram) ever get synced to lower layer (SD card)?
Can I enforce a sync ?

install.bash should cleanup after itself

just installing stuff with apt install and not cleaning up isn't very nice...

i suggest adding a apt remove --auto-remove --purge git make gcc binutils cpp step

Not mounting any target

Hi guys,

I do have Raspberry PI 4 8 GB with fully updated Ubuntu Mate 20.04.2 LTS. I'm trying to set this thing up but maybe I'm stupid because it's not working like you have presented on the code home page.

domy@domy-pi:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
domy@domy-pi:~$ zramctl
domy@domy-pi:~$
domy@domy-pi:~$ systemctl status zram-config.service
● zram-config.service - zram-config
     Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sat 2021-05-29 20:32:33 CEST; 10min ago
       Docs: https://github.com/ecdye/zram-config/blob/main/README.md
    Process: 1918 ExecStart=/usr/local/sbin/zram-config start (code=exited, status=0/SUCCESS)
   Main PID: 1918 (code=exited, status=0/SUCCESS)

May 29 20:32:33 domy-pi systemd[1]: Started zram-config.
May 29 20:32:33 domy-pi zram-config[1923]: zram-config start 2021-05-29-20:32:33
May 29 20:32:34 domy-pi zram-config[1961]: zramctl: /dev/zram0: failed to reset: Device or resource busy
domy@domy-pi:~$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 127.1M  1 loop /snap/chromium/1595
loop1         7:1    0  48.9M  1 loop /snap/core18/1949
loop2         7:2    0 145.4M  1 loop /snap/gnome-3-28-1804/147
loop3         7:3    0  65.1M  1 loop /snap/gtk-common-themes/1515
loop4         7:4    0  48.9M  1 loop /snap/core18/2068
loop5         7:5    0  59.6M  1 loop /snap/lxd/20330
loop6         7:6    0  61.6M  1 loop /snap/lxd/19040
loop7         7:7    0  27.9M  1 loop /snap/snapd/11843
loop8         7:8    0    27M  1 loop /snap/snapd/10709
loop9         7:9    0    16K  1 loop /snap/software-boutique/56
loop10        7:10   0  15.2M  1 loop /snap/ubuntu-mate-welcome/627
mmcblk0     179:0    0 119.1G  0 disk
|-mmcblk0p1 179:1    0   256M  0 part /boot/firmware
`-mmcblk0p2 179:2    0 118.9G  0 part /
domy@domy-pi:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.7G     0  3.7G   0% /dev
tmpfs           782M   30M  752M   4% /run
/dev/mmcblk0p2  117G  6.4G  106G   6% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0      128M  128M     0 100% /snap/chromium/1595
/dev/loop1       49M   49M     0 100% /snap/core18/1949
/dev/loop2      146M  146M     0 100% /snap/gnome-3-28-1804/147
/dev/loop3       66M   66M     0 100% /snap/gtk-common-themes/1515
/dev/loop4       49M   49M     0 100% /snap/core18/2068
/dev/loop9      128K  128K     0 100% /snap/software-boutique/56
/dev/loop6       62M   62M     0 100% /snap/lxd/19040
/dev/loop7       28M   28M     0 100% /snap/snapd/11843
/dev/loop5       60M   60M     0 100% /snap/lxd/20330
/dev/loop8       27M   27M     0 100% /snap/snapd/10709
/dev/loop10      16M   16M     0 100% /snap/ubuntu-mate-welcome/627
/dev/mmcblk0p1  253M  128M  125M  51% /boot/firmware
tmpfs           782M   16K  782M   1% /run/user/1000
domy@domy-pi:~$ swapon -s
domy@domy-pi:~$

Log file is attached, a little bit long for this. zram-config.log
Configuration file /etc/ztab has not been changed yet.

Can someone please explain me how to get this thing working? And is it possible to include /tmp directory with this tool or I do need to use /etc/fstab?

Thank you in advance and I wish you all the best!

Not all /dev/zramN devices go away when doing Stop

For some reason everytime I run: "systemctl stop zram-config -> systemctl start zram-config"
On the first time doing this sometime after the system boots up ... Ill notice a /dev/zram just left around and getting written to but not mounted, when I run "zramctl"
I look in logs and when I stop it, it shows the appropriate zram devices removed. I can even run zramctl when zram-config is stopped and it wont show any zram devices ... but for some reason on that next start, it will just show a rogue zram device ... and still gettin written to ... it will also show the correct devices after that start.
It should be noticed any attempt to do "stop" -> "start" after that first one works fine and no more rogue devices are added ... but that original first one always comes back...after the start.

OpenRC init script

Whilst systemd distros are definitely the dominant force in linux recently, there remain a few distros (Gentoo, Void, Artix, Adelie, Alpine, others) who still use Openrc (or others!) for their init system. Whilst I could make a crude attempt at an init script for these distros, I wonder whether the author is better placed to put something together appropriate to the application, taking into account the different feature-set that OpenRC has.
FWIW, any difficulties/queries with this, I can say that the #openrc support channel on Freenode IRC is quite responsive 😃

Five Minute Shutdown of Service

Using a new Buster 5.4.79 (December 2020) image.
Default Lite image, with latest package updates.

Installed git package
Installed zram-config

No changes to ztab config file

If rebooting/shutting down , the shutdown hangs at "A stop job is running for zram-config (xxs / 5min)"

If stopping using sudo zram-config "stop" the hang occurs at: systemctl stop systemd-journald.socket systemd-journald-audit.socket systemd-journald-dev-log.socket for about 5 minutes.

Is this normal behavior? Am I missing some package in the Lite version?

Improvement - oldlog_dir flatterns log directory structure and mix logs together

For log configuration within /etc/ztab, zram-config creates automatically simple logrotate configuration defining global logdir option pointing to oldlog_dir. This works perfectly for logs inside target_dir and while some log is rotated it is automatically offloaded to non-overlay directory. However, many applications (e.g. apache, nginx) creates sub directories within /var/log folder and configures logrotate configuration for those sub directories. Currently, the simple 00_oldlog implies that rotated logs from sub directories are stored directly into oldlog_dir. This introduces confusion as many times log filenames are the same for different services (e.g. error.log). Logs named using the same filename are mixed together into oldlog_dir within one file sequence (e.g. error.log.1 is from apache, error.log.2 is from haproxy, error.log.3 is again from apache and error.log.4 is from nginx).

It would be very helpful, if createZlog can:

  • enumerate directory structure within original content of target_dir
  • configure appropriate logrotate olddir option for every directory

Thus, logs from apache2 sub directory will be rotated into ${oldlog_dir}/apache2 and so on. This will maintain desired log structure as in the original log location.

master version is not building.

root@raspberrypi:/home/pi/Documents/zram-config# sh install.sh
install.sh: 4: install.sh: Syntax error: "(" unexpected (expecting "}")

I cannot install zram-config in raspbian buster.

pi@raspberrypi:~/Documents/zram-config $ uname -r
4.19.58-v7+

Bug - dir and log versions are not preserving ownership and permissions of target_dir

The easiest way to demonstrate the issue is to configure zram overlay for /tmp folder:

dir lz4 150M 400M /tmp /tmp.bind

Once zram-config performs configuration, newly created /tmp directory for mount is created with default ownership and permissions which are root:root 0755. This cause issues for any process running under different than root permission. This process cannot create/write into /tmp at all. The only possible workaround is to have sub-directory with broader permissions already created in /tmp and reconfigure temp path for all non-root processes.

The expected functionality should be: within createZdir mkdir for TARGET_DIR should preserve ownership and permission from original which is at that moment remounted to ${ZDIR}${BIND_DIR}.

Install script does not install all dependencies

On Ubuntu server for Raspberry Pi, two additional packages are needed. Here is the patch:

diff --git a/install.sh b/install.sh
index c553e2e..b4d4b24 100755
--- a/install.sh
+++ b/install.sh
@@ -4,7 +4,7 @@ systemctl -q is-active zram-config  && { echo "ERROR: zram-config service is sti
 [ "$(id -u)" -eq 0 ] || { echo "You need to be ROOT (sudo can be used)"; exit 1; }
 [ -d /usr/local/bin/zram-config ] && { echo "zram-config is already installed, uninstall first"; exit 1; }
 
-apt-get -y install libattr1-dev
+apt-get -y install libattr1-dev make gcc
 if grep -q "buster" /etc/os-release
 then
        git clone https://github.com/StuartIanNaylor/overlayfs-tools -b Arch

How to sync manually?

#zram_dir is the directory you wish to hold in zram, the original is moved to a bind mount bind_dir and is synchronised on start/stop and write commands.

pi@raspberrypi:~ $ sudo zram-config write
Usage: zram-config {start|stop|enable-ephemeral|disable-ephemeral}

Zram-config is newest.

How do I use zram-config

How do I use zram-config
I have changed the hard drive on an old laptop using mx linux ( just found out it does not use systemd ) to a ssd.
So I thought I would try and reduce the writes to it using zswap and found your project which also reduces log writes to the drive.

I have downloaded and installed using

sudo apt-get install git
git clone https://github.com/StuartIanNaylor/zram-config
cd zram-config
sudo sh install.sh

edited ztab to (without the --)

--# swap alg mem_limit disk_size swap_priority page-cluster swappiness
swap lz4 200M 600M 75 0 90

--# dir alg mem_limit disk_size target_dir bind_dir
--#dir lz4 50M 150M /home/pi /pi.bind

--# log alg mem_limit disk_size target_dir bind_dir oldlog_dir
log lz4 50M 150M /var/log /log.bind /opt/zram/oldlog

I started it using

sudo ./zram-config start
I got this error
grep: /boot/cmdline.txt: No such file or directory

Starting zram

:~/zram-config
$ sudo ./zram-config start
[sudo] password for david:
grep: /boot/cmdline.txt: No such file or directory

Laptop No systemd

zramctl
NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT
/dev/zram0 lz4 600M 4K 76B 12K 2 [SWAP]

df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 4001928 0 4001928 0% /dev
tmpfs 806188 1472 804716 1% /run
/dev/sdb2 19901264 6249376 12617904 34% /
tmpfs 5120 4 5116 1% /run/lock
tmpfs 2487680 183564 2304116 8% /run/shm
/dev/sdb3 80107640 19042820 56952440 26% /home
/dev/sda5 30865336 24375064 4915720 84% /mnt/MX-Data
/dev/sda4 323202812 162449304 160753508 51% /mnt/Windows
/dev/sda8 81258232 74505792 2601708 97% /mnt/Old-home
cgroup 12 0 12 0% /sys/fs/cgroup
tmpfs 806184 20 806164 1% /run/user/1000

free -h
total used free shared buff/cache available
Mem: 7.7G 3.5G 698M 563M 3.5G 3.4G
Swap: 4.6G 0B 4.6G

Note larger swap total

swapon
NAME TYPE SIZE USED PRIO
/dev/sdb4 partition 4.2G 0B -2
/dev/zram0 partition 600M 0B 75

Note zram partition I assume swap is working

but nothing suggesting log file has been moved

I am comparing with a virtualbox in a desktop with debian that uses systemd

here i can see the log seems to be set up

df shows
/dev/zram1 numbers /opt/zram/zram1
overlay1 number /var/log

zramctrl
has extra line
/dev/zram1 lz4 number /opt/zram/zram1

Thanks for your help

Dave

Lots of output after sudo zram-config "stop" / "start"

I have lots of shell output that looks like unwanted behaviour and so I wonder if this is a problem related to my system or not. I'm running Debian Buster on a RaspberryPi4.

[09:07:12] pi@raspberrypi4:~$ sudo zram-config "stop"
+ TMPDIR=/tmp
+ ZSHARE=/usr/local/share/zram-config
+ ZLOG=/usr/local/share/zram-config/log/zram-config.log
+ ZDIR=/opt/zram
+ [[ '' == \s\h\u\t\d\o\w\n ]]
+ case "$1" in
++ systemctl is-active zram-config.service
+ [[ active == \a\c\t\i\v\e ]]
+ systemctl kill zram-config.service
+ systemctl stop zram-config.service
++ date +%Y-%m-%d-%H:%M:%S
+ echo 'zram-config stop 2021-04-14-09:07:17'
+ tac /tmp/zram-device-list
+ file=/tmp/zram-device-list.rev
+ read -r line
+ case "$line" in
+ set -- log /zram2 /var/log /log.bind
+ echo 'ztab remove log /zram2 /var/log /log.bind'
+ case "$1" in
+ ZRAM_DEV=/zram2
+ TARGET_DIR=/var/log
+ BIND_DIR=/log.bind
+ [[ -z '' ]]
+ serviceConfiguration stop
+ [[ stop == \s\t\o\p ]]
+ echo 'Stopping services that interfere with zram device configuration'
++ systemctl is-active rsyslog.service
+ [[ active == \a\c\t\i\v\e ]]
+ export rsyslogActive=true
+ rsyslogActive=true
+ systemctl stop syslog.socket
++ systemctl is-active systemd-journald.service
+ [[ active == \a\c\t\i\v\e ]]
+ export journaldActive=true
+ journaldActive=true
+ journalctl --flush
+ systemctl stop systemd-journald.socket systemd-journald-audit.socket systemd-journald-dev-log.socket
+ removeZdir
+ [[ -n '' ]]
+ echo /zram2
+ [[ -n /var/log ]]
+ umount --verbose /var/log/
+ umount --verbose --lazy /var/log/
+ return 1
+ read -r line
+ case "$line" in
+ set -- swap /zram0 zram-config0
+ echo 'ztab remove swap /zram0 zram-config0 '
+ case "$1" in
+ ZRAM_DEV=/zram0
+ removeZswap
+ swapoff /dev/zram0
+ return 1
+ read -r line
+ rm -fv /tmp/zram-device-list.rev /tmp/zram-device-list
+ [[ -z '' ]]
+ serviceConfiguration start
+ [[ start == \s\t\o\p ]]
+ [[ start == \s\t\a\r\t ]]
+ echo 'Restarting services that interfere with zram device configuration'
+ [[ -n true ]]
+ systemctl restart systemd-journald.socket systemd-journald-audit.socket systemd-journald-dev-log.socket
+ [[ -n true ]]
+ systemctl restart syslog.socket

what does exactly your software ?

I have zram enabled before zram-config installation.
zram-config is for configure zram devices or for create zram disk and configure ?
Is possible create hdd folders hardlink in zram using zram-config ?

Any way to avoid locking up zram volume when full?

Hi there, I've been following zram-config since the days when it was called zram-swap-config under the previous owner, StuartIanNaylor and the work you guys put in here has really extended the life of my old Raspberry Pi 3Bs. I'm really thankful for the existence of zram-config.

I've since ramped up my cluster into 6x Rock Pi 4As, a Rock Pi X and an NUC. Though memory is less of an issue now, but logging I/O is still a concern as I run on eMMC storage which is not as replaceable as SD cards.

On my devices that run zram-config, I run into this issue whereby the zram log volume becomes read-only when it's full. This is usually not an issue but I run Kubernetes on the cluster, and container logs write to /var/log/container, so when it becomes full, no new containers can be created on that node. This forces me to either restart zram-config service, which leaves a zram device (e.g. zram0) in the zramctl list while mounting the logs on a new zram device (e.g. zram2), or restart the node itself which has proven to be quite disruptive to workloads.

My question would be:

Is there any way to avoid locking up the file system?

I understand this may not be a problem or bug with the code itself and that it may be expected behaviour but I'd like to learn of any mitigation measures that you'd recommend I take apart from simply increasing the memory allocation for the log volume or switching to a higher compression-ratio algorithm (I'm already on zstd). I'd be happy to contribute as well if some changes can help with this behavior.

grep: /boot/cmdline.txt: No such file or directory

On Ubuntu 18.04 server for Raspberry Pi, the cmdline.txt file is located at /boot/firmware/cmdline.txt rather than /boot/cmdline.txt. I'm not yet sure what issues this causes.

Here is the output of sudo systemctl status zram-config:

zram-config.service - zram-config
   Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
   Active: active (exited) since Fri 2019-10-18 17:18:23 UTC; 1min 2s ago
  Process: 1181 ExecStart=/usr/local/bin/zram-config start (code=exited, status=0/SUCCESS)
 Main PID: 1181 (code=exited, status=0/SUCCESS)

Oct 18 17:18:22 rpi systemd[1]: Starting zram-config...
Oct 18 17:18:22 rpi zram-config[1181]: grep: /boot/cmdline.txt: No such file or directory
Oct 18 17:18:22 rpi zram-config[1181]: grep: /usr/local/share/zram-config/zram-device-list: No such file or directo
Oct 18 17:18:22 rpi zram-config[1181]: mv: cannot stat '/usr/local/share/zram-config/zram-device-list.new': No such
Oct 18 17:18:22 rpi zram-config[1181]: mv: cannot stat '/usr/local/share/zram-config/zram-device-list.new': No such
Oct 18 17:18:22 rpi zram-config[1181]: stat: cannot stat 'stat': No such file or directory
Oct 18 17:18:22 rpi zram-config[1181]: stat: cannot stat 'stat': No such file or directory
Oct 18 17:18:22 rpi zram-config[1181]: stat: cannot stat 'stat': No such file or directory
Oct 18 17:18:23 rpi systemd[1]: Started zram-config.

Doesn't work with Raspbian Buster Lite

sudo sh install.sh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
libattr1-dev
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 33.8 kB of archives.
After this operation, 79.9 kB of additional disk space will be used.
Get:1 http://mirror.datamossa.io/raspbian buster/main armhf libattr1-dev armhf 1:2.4.48-4 [33.8 kB]
Fetched 33.8 kB in 1s (27.5 kB/s)
Selecting previously unselected package libattr1-dev:armhf.
(Reading database ... 38598 files and directories currently installed.)
Preparing to unpack .../libattr1-dev_1%3a2.4.48-4_armhf.deb ...
Unpacking libattr1-dev:armhf (1:2.4.48-4) ...
Setting up libattr1-dev:armhf (1:2.4.48-4) ...
Processing triggers for man-db (2.8.5-2) ...
Cloning into 'overlayfs-tools'...
remote: Enumerating objects: 92, done.
remote: Total 92 (delta 0), reused 0 (delta 0), pack-reused 92
Unpacking objects: 100% (92/92), done.
gcc -Wall -std=c99 -c main.c
In file included from main.c:16:
/usr/include/linux/stat.h:56:8: error: redefinition of ‘struct statx_timestamp’
struct statx_timestamp {
^~~~~~~~~~~~~~~
In file included from /usr/include/arm-linux-gnueabihf/sys/stat.h:446,
from main.c:14:
/usr/include/arm-linux-gnueabihf/bits/statx.h:25:8: note: originally defined here
struct statx_timestamp
^~~~~~~~~~~~~~~
In file included from main.c:16:
/usr/include/linux/stat.h:99:8: error: redefinition of ‘struct statx’
struct statx {
^~~~~
In file included from /usr/include/arm-linux-gnueabihf/sys/stat.h:446,
from main.c:14:
/usr/include/arm-linux-gnueabihf/bits/statx.h:36:8: note: originally defined here
struct statx
^~~~~
make: *** [makefile:11: main.o] Error 1
install: cannot stat 'overlayfs-tools/overlay': No such file or directory
Created symlink /etc/systemd/system/basic.target.wants/zram-config.service → /etc/systemd/system/zram-config.service.

Reboot to activate zram-config
edit /etc/ztab to configure options

/zram-device-list: No such file or directory

● zram-config.service - zram-config
Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2019-10-04 15:10:37 JST; 1 day 6h ago
Main PID: 388 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 2077)
Memory: 0B
CGroup: /system.slice/zram-config.service

Oct 04 15:10:35 raspberrypi systemd[1]: Starting zram-config...
Oct 04 15:10:36 raspberrypi zram-config[388]: grep: /usr/local/share/zram-config/zram-device-list: No such file or directory
Oct 04 15:10:37 raspberrypi zram-config[388]: mv: cannot stat '/usr/local/share/zram-config/zram-device-list.new': No such file or directory
Oct 04 15:10:37 raspberrypi systemd[1]: Started zram-config.

zram dir read-only

I have one zram directory that cannot be written to (read only errors)
dir lz4 50M 300M /var/lib/openhab2 /openhab2.bind
The others work fine meanwhile.
log zstd 50M 250M /var/log /log.bind /volatile/oldlogs
dir lz4 10M 1000M /var/cache /cache.bind

Any idea ? I think it was writable for some time in the beginning after boot. Eventually the difference is that the amount of data written is larger than the mem_limit - could that be an explanation ?

zram device doesn't start at boot.

● zram-config.service - zram-config
Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2020-01-19 19:17:15 JST; 7h ago
Process: 352 ExecStart=/usr/local/bin/zram-config start (code=exited, status=0/SUCCESS)
Main PID: 352 (code=exited, status=0/SUCCESS)

Jan 19 19:17:12 raspberrypi systemd[1]: Starting zram-config...
Jan 19 19:17:14 raspberrypi zram-config[352]: entry swap /zram0 zra
Jan 19 19:17:15 raspberrypi systemd[1]: Started zram-config.

and there is no device.
but I restart systemd , it appears.

Permission error occurs.

;# dir alg mem_limit disk_size target_dir bind_dir
dir lz4 50M 150M /home/pi /pi.bind

pi@raspberrypi:~ $ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 184G 13G 164G 7% /
devtmpfs 433M 0 433M 0% /dev
tmpfs 438M 219M 220M 50% /dev/shm
tmpfs 438M 12M 426M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 438M 0 438M 0% /sys/fs/cgroup
tmpfs 438M 48K 438M 1% /tmp
/dev/sda1 43M 23M 21M 53% /boot
/dev/zram1 130M 24M 96M 20% /opt/zram/zram1
overlay1 130M 24M 96M 20% /home/pi
tmpfs 88M 0 88M 0% /run/user/1000

When I use hexchat, It occurs.

Who wants the project transferred to?

I am not developing this any more haven't picked up a Pi or SBC for months.
So if someone wants to take over please do.

The main problem is lack of tools with OverlayFS and the strange nature that OverlayFS is a default module in most distro's.
Aufs is the opposite has great tools but would require kernel mods...

I really thought by now we would have merge tools especially with their work with snapshots as to be able to rotate snapshots down to lower would be an awesome backup tool.

But hey and apols for being absent but just not involved anymore.

zram doesn't start properly after power fail

boot after power fail results in misconfiguration,
zram-config starts, but doesn't create zdevices, it considers them as already working.
Manual Stop and Start zram service restore functionality.
It will be good to do this automatically, somehow recognizing misconfiguration after power failure

====
pi@raspberrypi:~ $ sudo systemctl status zram-config.service
● zram-config.service - zram-config
Loaded: loaded (/etc/systemd/system/zram-config.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2020-05-08 08:30:09 EEST; 11min ago
Process: 322 ExecStart=/usr/local/bin/zram-config start (code=exited, status=0/SUCCESS)
Main PID: 322 (code=exited, status=0/SUCCESS)

May 08 08:30:09 raspberrypi systemd[1]: Starting zram-config...
May 08 08:30:09 raspberrypi zram-config[322]: entry swap /zram0 zram-config0 already exists as zram.
May 08 08:30:09 raspberrypi zram-config[322]: entry log /zram1 /var/log /log.bind already exists as zram.
May 08 08:30:09 raspberrypi systemd[1]: Started zram-config.

====
pi@raspberrypi:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 29.7G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 29.5G 0 part /

====
pi@raspberrypi:~ $ tail /usr/local/share/zram-config/log/zram-config.log
zram-config start 2020-05-08-08:30:09
ztab create swap lz4 250M 750M 75 0 20
ztab create log lz4 50M 150M /var/log /log.bind /opt/zram/oldlog

Stop warning when I delete files

When I delete files upon zram dir , system causes warning.
Usually , When I do it , files go to trash without warning.
This is prevent me from using zram-config dir for home folder.

Question about ram usage

Hi, its not an issue, I just want to ask a question to know if this project will fulfill my needs.
Currently i'm using overlayfs with tmpfs upper dir and read only lower dir on raspberry pi. The reason is to lower sd card wear. But after long uptime, the tmpfs is eating all the ram and i cannot find solution for that. Does this project adress this issue ? And if yes, how ?

Write-error on swap-device

Running Raspian Buster on a RPi4 4GB.

Zram-config works brilliantly until one or two days of uptime, when dmesg gets flooded with "write-error on swap-devices". Here's a sample of the last few lines:

[101734.099250] Write-error on swap-device (254:0:1134984) [101734.099300] Write-error on swap-device (254:0:1135016) [101734.099420] Write-error on swap-device (254:0:1135088) [101734.099473] Write-error on swap-device (254:0:1135104) [101734.099526] Write-error on swap-device (254:0:1135120) [101734.099577] Write-error on swap-device (254:0:1135136) [101734.099631] Write-error on swap-device (254:0:1135152) [101734.101754] Write-error on swap-device (254:0:1135448) [101734.339315] systemd-journald[119]: /dev/kmsg buffer overrun, some messages l ost. [101734.794086] oom_reaper: reaped process 581 (rclone), now anon-rss:0kB, file- rss:0kB, shmem-rss:0kB

I'm using the following (although default settings show the same error):

NAME ALGORITHM DISKSIZE DATA COMPR TOTAL STREAMS MOUNTPOINT /dev/zram1 lz4 450M 427.3M 92M 96.2M 4 /opt/zram/zram1 /dev/zram0 lz4 1.5G 271.7M 124.3M 128.5M 4 [SWAP]
I have deactivated the swap and am only using zram.

Bash Script to Update zram-config

A script to update zram-config to the latest version would be nice. This prevents having to do an uninstall followed by an install that overwrites the ztab configuration.

Would something like this work? (It seems to for me, but I'm not sure if I missed anything important...)

#!/usr/bin/env bash

if [[ "$(id -u)" -ne 0 ]]; then
  echo "ERROR: You need to be ROOT (sudo can be used)."
  exit 1
fi

if [[ ! -f /usr/local/sbin/zram-config ]]; then
  echo "ERROR: zram-config is not installed."
  exit 1
fi

if [[ $(systemctl is-active zram-config.service) == "active" ]]; then
  echo "ERROR: zram-config service is still running. Please run \"sudo systemctl stop zram-config.service\" to stop it and then uninstall before running this."
  exit 1
fi

if ! dpkg -s 'make' 'libattr1-dev' &> /dev/null; then
  apt-get install --yes make libattr1-dev || exit 1
fi

if [[ ! -f overlayfs-tools/overlay ]]; then
  rm overlayfs-tools/overlay
fi

cd overlayfs-tools || exit 1
make
cd ..

echo "Disabling zram-config service."
systemctl disable --now zram-config.service

install -m 755 zram-config /usr/local/sbin/
install -m 644 zram-config.service /etc/systemd/system/zram-config.service

if [[ ! -f /etc/ztab ]]; then
  install -m 644 ztab /etc/ztab
fi

if [[ ! -d /usr/local/share/zram-config/log ]]; then
  mkdir -p /usr/local/share/zram-config/log
fi

install -m 644 uninstall.bash /usr/local/share/zram-config/uninstall.bash
install -m 644 ro-root.sh /usr/local/share/zram-config/ro-root.sh

if [[ ! -f /etc/logrotate.d/zram-config ]]; then
  install -m 644 zram-config.logrotate /etc/logrotate.d/zram-config
fi

install -m 755 overlayfs-tools/overlay /usr/local/lib/zram-config/overlay

systemctl enable --now zram-config.service

echo "#####          zram-config has been updated.          #####"
echo "#####       edit /etc/ztab to configure options       #####"

bind_dir location

Is there a specific reason to have bind_dir always located under zdir (i.e. /opt/zram)? When I use for example "/var/log.bind" in ztab I would expect that bind_dir is at /var/log.bind, but it is at /opt/zram/var/log.bind!

updates to lower file system

I am using /var as overlay "dir". I am using RPi4 4GB with raspbian-lite as a router and few programs write to /var/lib as as well as /var/log. I see writes to SD card every few seconds (probably minutes) and "find" command indicates that the the lower file system files in "/opt/zram/var.bind" are getting updated. How often is this done and can I control this?

My entry in /etc/ztab:
dir lz4 500M 1500M /var /var.bind

Please make ztab line For pi3

This is Great job. :)
But I can understand only disk_size.
I want to get 75% phisical memory.
How do I do ?

Thank you :)
Yutayuta

It doesn't mount correctlly.

I install this script at raspbian and run .
It doesn't work well at all.
Try it please.

uname -a
Linux raspberrypi 5.10.11-v7+ #1399 SMP Thu Jan 28 12:06:05 GMT 2021 armv7l GNU/Linux

xattr version not building

The only difference of lzual750's branch is different header files ... <sys/xattr.h> does not exist on my stretch Raspbian, meanwhile <attr/xattr.h> exists (and defines ENOATTR to be ENODATA).
I don't understand neither why you introduced that distinction nor how to get hold of those sys headers.

Would you mind tagging a working version with a version tag ?
Either the master branch as of 12 days ago or the latest after fixing this issue.
I'm cloning your repo for use in openHABian but for this it shouldn't change as master does. Thanks.

pi@devpi:/tmp/z $ git clone -b fix_xattr_lib_include https://github.com/Izual750/overlayfs-tools
Klone nach 'overlayfs-tools' ...
remote: Enumerating objects: 96, done.
remote: Total 96 (delta 0), reused 0 (delta 0), pack-reused 96
Entpacke Objekte: 100% (96/96), Fertig.
pi@devpi:/tmp/z $ cd overlayfs-tools/
pi@devpi:/tmp/z/overlayfs-tools $ make
gcc -Wall -std=c99 -c main.c
gcc -Wall -std=c99 -c logic.c
logic.c: In function ‘is_opaquedir’:
logic.c:38:32: error: ‘ENOATTR’ undeclared (first use in this function)
if ((res < 0) && (errno != ENOATTR)) {
^~~~~~~
logic.c:38:32: note: each undeclared identifier is reported only once for each function it appears in
makefile:14: die Regel für Ziel „logic.o“ scheiterte
make: *** [logic.o] Fehler 1

missing dependencies

on proxmox ve 6.3 (debian buster) following the install instructions didn't work:

~/zram-config# ./install.bash
Installing needed packages (make, libattr1-dev)
gcc -Wall -std=c99 -c main.c
make: gcc: Command not found
make: *** [makefile:11: main.o] Error 127
Installing zram-config files
install: cannot stat 'overlayfs-tools/overlay': No such file or directory
Starting zram-config.service
Created symlink /etc/systemd/system/basic.target.wants/zram-config.service → /etc/systemd/system/zram-config.service.
#####   zram-config is now installed and running   #####
#####     edit /etc/ztab to configure options      #####

had to manually apt install make gcc, to make it work.

Remove cvt2f2fs

@StuartIanNaylor Do you have a problem with me removing the cvt2f2fs files? I don't see any real point in keeping them as they are completely unrelated to this utility.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.