Zram not working accordingly on raspberry pi 5

that was fast! Thank you! ZRAM works:

openhabian@openHABMain:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G   15G   13G  54% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G  1.1M  1.9G   1% /dev/shm
tmpfs           769M  1.7M  768M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/mmcblk0p1  253M   51M  202M  20% /boot
/dev/zram1      721M  477M  192M  72% /opt/zram/zram1
/dev/zram2      974M   83M  824M  10% /opt/zram/zram2
tmpfs           385M     0  385M   0% /run/user/1000
/dev/zram3      721M   61M  608M  10% /opt/zram/zram3
overlay3        721M   61M  608M  10% /var/lib/openhab/persistence
/dev/zram4      974M   23M  884M   3% /opt/zram/zram4
overlay4        974M   23M  884M   3% /var/log

worked after it installed “meson”, just two warnings while compiling:


openhabian@openHABMain:~ $ sudo openhabian-config
2024-12-10_13:32:20_CET [openHABian] Checking for root privileges... OK
2024-12-10_13:32:20_CET [openHABian] Making sure router advertisements are available...
$ sysctl --load
net.ipv6.conf.all.accept_ra = 1
net.ipv6.conf.all.accept_ra_rt_info_max_plen = 64
OK
2024-12-10_13:32:20_CET [openHABian] Loading configuration file '/etc/openhabian.conf'... OK
2024-12-10_13:32:20_CET [openHABian] openHABian configuration tool version: [openHAB]{2024-12-09T10:29:33-07:00}(28756be)
2024-12-10_13:32:20_CET [openHABian] Checking for changes in origin branch openHAB... OK
2024-12-10_13:32:22_CET [openHABian] Switching to branch openHAB... OK
2024-12-10_13:32:22_CET [openHABian] Checking openHAB Signing Key expiry.
2024-12-10_13:32:22_CET [openHABian] Checking expiry date of apt keys... OK
2024-12-10_13:32:49_CET [openHABian] Updating Linux package information... OK
2024-12-10_13:32:49_CET [openHABian] Installing zram required package (meson)...
$ apt-get install --yes -o DPkg::Lock::Timeout= meson
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  ninja-build
The following NEW packages will be installed:
  meson ninja-build
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 658 kB of archives.
After this operation, 3,889 kB of additional disk space will be used.
Get:1 http://raspbian.raspberrypi.org/raspbian bookworm/main armhf ninja-build armhf 1.11.1-2~deb12u1 [110 kB]
Get:2 http://ftp.halifax.rwth-aachen.de/raspbian/raspbian bookworm/main armhf meson all 1.0.1-5 [548 kB]
Fetched 658 kB in 1s (694 kB/s)
Selecting previously unselected package ninja-build.
(Reading database ... 63930 files and directories currently installed.)
Preparing to unpack .../ninja-build_1.11.1-2~deb12u1_armhf.deb ...
Unpacking ninja-build (1.11.1-2~deb12u1) ...
Selecting previously unselected package meson.
Preparing to unpack .../archives/meson_1.0.1-5_all.deb ...
Unpacking meson (1.0.1-5) ...
Setting up ninja-build (1.11.1-2~deb12u1) ...
Setting up meson (1.0.1-5) ...
Processing triggers for man-db (2.11.2-2) ...
Updating FireMotD available updates count ...
OK
2024-12-10_13:33:06_CET [openHABian] Updating zram service...
$ systemctl stop zram-config.service

$ mkdir -p /usr/local/lib/zram-config/

$ rm -f /usr/local/lib/zram-config/overlay

$ install_zram_code /opt/zram
2024-12-10_13:33:07_CET [openHABian] Installing zram code...
$ mkdir -p /opt/zram

$ update_git_repo /opt/zram/zram-config openHAB
2024-12-10_13:33:07_CET [openHABian] Updating zram-config, openHAB branch from git...
$ git -C /opt/zram/zram-config fetch origin
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 4), reused 9 (delta 4), pack-reused 0 (from 0)
Unpacking objects: 100% (10/10), 7.16 KiB | 366.00 KiB/s, done.
From https://github.com/ecdye/zram-config
 + d3ad15f...168efb6 openHAB    -> origin/openHAB  (forced update)
   7a0460a..2d2e457  main       -> origin/main
 + a254418...9c14a28 sd         -> origin/sd  (forced update)

$ git -C /opt/zram/zram-config fetch --tags --force --prune
From https://github.com/ecdye/zram-config
 - [deleted]         (none)     -> origin/gl

$ git -C /opt/zram/zram-config reset --hard origin/openHAB
HEAD is now at 168efb6 Add openHAB specific changes

$ git -C /opt/zram/zram-config clean --force -x -d

$ git -C /opt/zram/zram-config checkout openHAB
Already on 'openHAB'
Your branch is up to date with 'origin/openHAB'.

$ git -C /opt/zram/zram-config submodule update --init --recursive
Submodule path 'overlayfs-tools': checked out 'a1e1e33a5359e4cff7d7c60a51620eaa1b315e90'
OK
OK
OK
2024-12-10_13:33:09_CET [openHABian] Updating OverlayFS...
$ meson setup /opt/zram/zram-config/overlayfs-tools/builddir /opt/zram/zram-config/overlayfs-tools
The Meson build system
Version: 1.0.1
Source dir: /opt/zram/zram-config/overlayfs-tools
Build dir: /opt/zram/zram-config/overlayfs-tools/builddir
Build type: native build
Project name: overlayfs-tools
Project version: 2024.07
C compiler for the host machine: cc (gcc 12.2.0 "cc (Raspbian 12.2.0-14+rpi1) 12.2.0")
C linker for the host machine: cc ld.bfd 2.40
Host machine cpu family: arm
Host machine cpu: arm
Found pkg-config: /usr/bin/pkg-config (1.8.1)
Run-time dependency musl-fts found: NO (tried pkgconfig)
Library m found: YES
Program test_cases/run_tests.py found: YES (/opt/zram/zram-config/overlayfs-tools/test_cases/run_tests.py)
Build targets in project: 10

Found ninja-1.11.1 at /usr/bin/ninja

$ meson compile -C /opt/zram/zram-config/overlayfs-tools/builddir
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /opt/zram/zram-config/overlayfs-tools/builddir
ninja: Entering directory `/opt/zram/zram-config/overlayfs-tools/builddir'
[4/13] Compiling C object fsck.overlay.p/fsck.c.o
In file included from ../fsck.c:42:
../fsck.c: In function ‘ovl_open_dirs’:
../common.h:32:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘rlim_t’ {aka ‘long long unsigned int’} [-Wformat=]
   32 | #define _(x)    (x)
      |                 ^~~
../fsck.c:71:28: note: in expansion of macro ‘_’
   71 |                 print_info(_("Process fd number limit=%lu "
      |                            ^
../common.h:32:17: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘rlim_t’ {aka ‘long long unsigned int’} [-Wformat=]
   32 | #define _(x)    (x)
      |                 ^~~
../fsck.c:71:28: note: in expansion of macro ‘_’
   71 |                 print_info(_("Process fd number limit=%lu "
      |                            ^
[13/13] Linking target fsck.overlay

$ meson install -C /opt/zram/zram-config/overlayfs-tools/builddir
ninja: Entering directory `/opt/zram/zram-config/overlayfs-tools/builddir'
ninja: no work to do.
Installing overlay to /usr/local/bin
Installing fsck.overlay to /usr/local/bin
OK
2024-12-10_13:33:13_CET [openHABian] Updating zram logging files...
$ mkdir -p /usr/local/share/zram-config/log

$ install -m 644 /opt/zram/zram-config/service/zram-config.logrotate /etc/logrotate.d/zram-config

$ systemctl -q daemon-reload

$ systemctl restart zram-config.service
OK

just I’m not sure why, but I lost the information in the rrd4j-persistence of roughly 2,5 days while installing:
there’s no more information since Sunday night until now.

I was afraid of that. I still haven’t formally pushed the changes that will resolve the occasional issues with data loss when using zram. Hopefully in the next week or two it will be ready to go.

2 Likes

no worries. My main persistence is MariaDB, so no real losses.

1 Like

@binderth @massimiliano.casini @Bonsaif

The changes have officially been published, I would welcome testing of them.
If you simply run sudo openhabian-config and allow the tool to update, if you have zram-config installed still it will auto update it just this first time to fix the issues with sync on shutdown/reboot.

If you give it a shot, let me know if you have any questions or observe any issues.

not sure, what you mean by that! :wink:
I fired up openhabian-config and openhabian did update itself. How can i test your changes? de-activate ZRAM and re-activate it again? do a reboot
? :wink:

I fired up openhabian-config and openhabian did update itself

After I update zram and this is log. Are “normal” the warnig messages during the compilation?

2024-12-18_08:28:34_CET [openHABian] Updating Linux package information... OK
2024-12-18_08:28:34_CET [openHABian] Updating zram service... 
$ systemctl stop zram-config.service 

$ mkdir -p /usr/local/lib/zram-config/ 

$ install_zram_code /opt/zram 
2024-12-18_08:28:51_CET [openHABian] Installing zram code... 
$ mkdir -p /opt/zram 

$ update_git_repo /opt/zram/zram-config openHAB 
2024-12-18_08:28:52_CET [openHABian] Updating zram-config, openHAB branch from git... 
$ git -C /opt/zram/zram-config fetch origin 
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 19 (delta 11), reused 15 (delta 8), pack-reused 0 (from 0)
Unpacking objects: 100% (19/19), 8.49 KiB | 107.00 KiB/s, done.
From https://github.com/ecdye/zram-config
 + 168efb6...23a4fe8 openHAB    -> origin/openHAB  (forced update)
   2d2e457..0b83593  main       -> origin/main
 + 9c14a28...2293996 sd         -> origin/sd  (forced update)

$ git -C /opt/zram/zram-config fetch --tags --force --prune 

$ git -C /opt/zram/zram-config reset --hard origin/openHAB 
HEAD is now at 23a4fe8 Add openHAB specific changes

$ git -C /opt/zram/zram-config clean --force -x -d 

$ git -C /opt/zram/zram-config checkout openHAB 
Already on 'openHAB'
Your branch is up to date with 'origin/openHAB'.

$ git -C /opt/zram/zram-config submodule update --init --recursive 
Submodule path 'overlayfs-tools': checked out 'a1e1e33a5359e4cff7d7c60a51620eaa1b315e90'
OK
OK

$ install -m 755 /opt/zram/zram-config/zram-config /usr/local/sbin 

$ install -m 644 /opt/zram/zram-config/service/SystemD/zram-config.service /etc/systemd/system/zram-config.service 

$ install -m 755 /opt/openhabian/includes/zram-sync /usr/local/sbin 

$ install -m 644 /opt/openhabian/includes/SD/zsync.service /opt/openhabian/includes/SD/zsync.timer /etc/systemd/system/ 
OK
2024-12-18_08:28:58_CET [openHABian] Updating OverlayFS... 
$ rm -f /usr/local/lib/zram-config/overlay 

$ meson setup /opt/zram/zram-config/overlayfs-tools/builddir /opt/zram/zram-config/overlayfs-tools 
The Meson build system
Version: 1.0.0
Source dir: /opt/zram/zram-config/overlayfs-tools
Build dir: /opt/zram/zram-config/overlayfs-tools/builddir
Build type: native build
Project name: overlayfs-tools
Project version: 2024.07
C compiler for the host machine: cc (gcc 10.2.1 "cc (Raspbian 10.2.1-6+rpi1) 10.2.1 20210110")
C linker for the host machine: cc ld.bfd 2.35.2
Host machine cpu family: arm
Host machine cpu: armv7l
Found pkg-config: /usr/bin/pkg-config (0.29.2)
Run-time dependency musl-fts found: NO (tried pkgconfig)
Library m found: YES
Program test_cases/run_tests.py found: YES (/opt/zram/zram-config/overlayfs-tools/test_cases/run_tests.py)
Build targets in project: 10

Found ninja-1.10.1 at /usr/bin/ninja

$ meson compile -C /opt/zram/zram-config/overlayfs-tools/builddir 
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /opt/zram/zram-config/overlayfs-tools/builddir
ninja: Entering directory `/opt/zram/zram-config/overlayfs-tools/builddir'
[5/13] Compiling C object fsck.overlay.p/fsck.c.o
In file included from ../fsck.c:42:
../fsck.c: In function ‘ovl_open_dirs’:
../common.h:32:15: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘rlim_t’ {aka ‘long long unsigned int’} [-Wformat=]
   32 | #define _(x)  (x)
      |               ^~~
../fsck.c:71:14: note: in expansion of macro ‘_’
   71 |   print_info(_("Process fd number limit=%lu "
      |              ^
../common.h:32:15: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘rlim_t’ {aka ‘long long unsigned int’} [-Wformat=]
   32 | #define _(x)  (x)
      |               ^~~
../fsck.c:71:14: note: in expansion of macro ‘_’
   71 |   print_info(_("Process fd number limit=%lu "
      |              ^
[13/13] Linking target fsck.overlay

$ meson install -C /opt/zram/zram-config/overlayfs-tools/builddir 
ninja: Entering directory `/opt/zram/zram-config/overlayfs-tools/builddir'
ninja: no work to do.
Installing overlay to /usr/local/bin
Installing fsck.overlay to /usr/local/bin
OK
2024-12-18_08:29:18_CET [openHABian] Updating zram logging files... 
$ mkdir -p /usr/local/share/zram-config/log 

$ install -m 644 /opt/zram/zram-config/service/zram-config.logrotate /etc/logrotate.d/zram-config 

$ systemctl -q daemon-reload 

$ systemctl restart zram-config.service
OK 
openhabian@cm3home:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root        29G  6.6G   22G  24% /
devtmpfs        454M     0  454M   0% /dev
tmpfs           486M     0  486M   0% /dev/shm
tmpfs           195M  1.9M  193M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/mmcblk0p1  255M   52M  204M  21% /boot
/dev/zram1      347M  188M  134M  59% /opt/zram/zram1
/dev/zram2      672M  153M  471M  25% /opt/zram/zram2
tmpfs            98M     0   98M   0% /run/user/1000
/dev/zram3      347M   36K  321M   1% /opt/zram/zram3
overlay3        347M   36K  321M   1% /var/lib/openhab/persistence
/dev/zram4      672M   72M  552M  12% /opt/zram/zram4
overlay4        672M   72M  552M  12% /var/log

Hi Ethan,
I recently updated my zram-installation with uninstall and reinstall over openhabian-config. It works fine.

My question is, when will the sync function work properly with openhab.service?
When I use the command /usr/local/sbin/zram-config “sync” to manually sync to sd-card, the openhab.service is restarting too.

I would prefer to sync the changes to sd-card at night ones a day without any service restarts. Only syncing from zram-device to sd-card.
Is it actually possible, maybe with a systemd-timer (zsync.service, zsync.timer)?

Best regards and thanks for your efforts

You may find some information at this link

I’m afraid the answer is “yes, but”. If you don’t restart the openHAB service, logging will stop working. See:

That’s not right. You can issue any log:set command after a sync that’ll reenable logging.

Thanks, that seems like a better work-around than restarting the service. :+1: Is this zram configuration using log:set rather than systemctl restart openhab part of openHABian, or has to be adjusted manually?

Hello again,
if I use the sync-timer in systemd, it doesn’t matter. It’s the same like manually run the command /usr/local/sbin/zram-config “sync”.

Manually and with the systemd-timer my openhab, influxdb an grafana-service restarts on every zram-sync.

Here my ztab config:

# swap	alg		mem_limit	disk_size	swap_priority	page-cluster	swappiness
swap	lzo-rle		300M		1G		75		0		150

# dir	alg		mem_limit	disk_size	target_dir			bind_dir
dir	zstd		300M		1G		/var/lib/openhab/persistence	/persistence.bind
dir	zstd		150M		350M		/var/lib/influxdb		/influxdb.bind

# log	alg		mem_limit	disk_size	target_dir		bind_dir		oldlog_dir
log	zstd		600M		1G		/var/log		/log.bind

So, log:set is not an option for me. :thinking:

A Zram sync means to un- and remount so this is to be expected.
You shouldn’t be running InfluxDB off zram anyway that’s not supported. Dangerous, too.

Ok, so not with the systemd zsync.service, which is installed with zram. I will try it with un- and remount.

And thanks for this hint. I will take it out. :+1: