From e00e7cbf37e1fd347019ed12588102acb1647ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 16:19:54 +0100 Subject: [PATCH 1/3] udev: queue and writeback settings for Apple's raw NAND The 32-bit boards' internal storage is raw NAND behind the SFTL translation layer (applesftl). Its own queue orders the I/O, so it runs without a scheduler, with a 512 KiB read-ahead, and with small dirty-page limits (16 MiB background, 64 MiB hard) so writeback comes in bursts the NAND absorbs instead of stalls of the desktop. [Orchard: from #264 (257c376, configure-nand-root); keyed on the applesftl device in the package's udev rules instead of written into the ARMv7 image, so every board with that storage gets it, installed ones too; the dirty limits set by the same rule] Assisted-by: LLM --- .../usr/lib/udev/rules.d/60-omarchy-apple-nand.rules | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules diff --git a/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules b/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules new file mode 100644 index 00000000..efa943a1 --- /dev/null +++ b/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules @@ -0,0 +1,9 @@ +# Apple's raw NAND behind its flash translation layer (applesftl, the internal +# storage of the 32-bit boards). The translation layer orders its own I/O, so +# no scheduler sits in front of it, and a 512 KiB read-ahead keeps sequential +# reads (app start, the package database) streaming. Writeback starts at 16 MiB +# of dirty pages and writers wait at 64 MiB: short bursts the slow NAND +# absorbs, instead of a percentage of RAM flushed at once that stalls the +# desktop. Measured on the iPhone 5 (N42) with its root on the NAND. +ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="applesftl[0-9]", ATTR{queue/read_ahead_kb}="512", ATTR{queue/scheduler}="none" +ACTION=="add", SUBSYSTEM=="block", KERNEL=="applesftl[0-9]", RUN+="/usr/bin/sysctl -q -w vm.dirty_background_bytes=16777216 vm.dirty_bytes=67108864" From 94ddbf3127fe74b5e016243a532074c39bbeb185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berkay=20K=C3=B6sebay?= Date: Wed, 2 Dec 2026 16:28:44 +0100 Subject: [PATCH 2/3] Restart the device when its NAND root stops answering With the root on Apple's raw NAND, a wedged NAND controller leaves PID 1 running in RAM while every program that needs the root hangs: the device looks alive and does nothing. omarchy-nand-rootcheck reads one random 4 KiB block of the root past the page cache every 10 s and feeds the service's watchdog only when the read succeeds; a hung read misses the 60 s watchdog, an I/O error fails the service at once, and either way FailureAction=reboot-force restarts the device. It only reads, so the NAND sees no extra page programs. [Orchard: from #264 (2ada1dd, n42-rootcheck); renamed for every board with that storage and started by udev when an applesftl disk appears instead of enabled in the ARMv7 image; it ends successfully when the root is not on the NAND (a RAM boot), so it can never restart such a boot. Not taken: the emergency-mode reboot (it would cut a USB serial rescue session), the global hardware watchdog and the sleep target masks (for every board, not keyed on the NAND)] Assisted-by: LLM --- .../overlay/usr/lib/omarchy-a/package-install | 4 +- .../system/omarchy-nand-rootcheck.service | 15 ++++++++ .../udev/rules.d/60-omarchy-apple-nand.rules | 4 ++ .../usr/libexec/omarchy-nand-rootcheck | 38 +++++++++++++++++++ tests/test_package.py | 4 +- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 system/overlay/usr/lib/systemd/system/omarchy-nand-rootcheck.service create mode 100755 system/overlay/usr/libexec/omarchy-nand-rootcheck diff --git a/system/overlay/usr/lib/omarchy-a/package-install b/system/overlay/usr/lib/omarchy-a/package-install index ebb18a89..e828f9f8 100755 --- a/system/overlay/usr/lib/omarchy-a/package-install +++ b/system/overlay/usr/lib/omarchy-a/package-install @@ -15,7 +15,9 @@ set -euo pipefail # orchard-usb-network are not here: restarting them would cut the SSH or USB # link an update may be running over, and what keeps running in them is # dropbear and busybox, not code of this package. The others are oneshots. -SERVICES=(omarchy-powerd.service) +# omarchy-nand-rootcheck runs only where the root is on Apple's raw NAND; +# try-restart leaves it alone everywhere else. +SERVICES=(omarchy-powerd.service omarchy-nand-rootcheck.service) # Only on a running system: in a chroot or an image build there is no PID 1 of # its own to ask, and the services start fresh at the first boot anyway. diff --git a/system/overlay/usr/lib/systemd/system/omarchy-nand-rootcheck.service b/system/overlay/usr/lib/systemd/system/omarchy-nand-rootcheck.service new file mode 100644 index 00000000..7e40b8df --- /dev/null +++ b/system/overlay/usr/lib/systemd/system/omarchy-nand-rootcheck.service @@ -0,0 +1,15 @@ +# Restart the device when its root on Apple's raw NAND stops answering reads +# (/usr/libexec/omarchy-nand-rootcheck). Started by 60-omarchy-apple-nand.rules +# when an applesftl disk appears, so only boards with that storage run it. +[Unit] +Description=Check the NAND root still answers reads +After=local-fs.target +FailureAction=reboot-force + +[Service] +Type=notify +NotifyAccess=all +ExecStart=/usr/libexec/omarchy-nand-rootcheck +WatchdogSec=60s +TimeoutStopSec=10s +OOMScoreAdjust=-900 diff --git a/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules b/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules index efa943a1..1c3c4c49 100644 --- a/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules +++ b/system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules @@ -7,3 +7,7 @@ # desktop. Measured on the iPhone 5 (N42) with its root on the NAND. ACTION=="add|change", SUBSYSTEM=="block", KERNEL=="applesftl[0-9]", ATTR{queue/read_ahead_kb}="512", ATTR{queue/scheduler}="none" ACTION=="add", SUBSYSTEM=="block", KERNEL=="applesftl[0-9]", RUN+="/usr/bin/sysctl -q -w vm.dirty_background_bytes=16777216 vm.dirty_bytes=67108864" +# The NAND root's watchdog (omarchy-nand-rootcheck.service): it restarts the +# device when the root stops answering, and ends at once where the root is +# elsewhere. +ACTION=="add", SUBSYSTEM=="block", KERNEL=="applesftl[0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}+="omarchy-nand-rootcheck.service" diff --git a/system/overlay/usr/libexec/omarchy-nand-rootcheck b/system/overlay/usr/libexec/omarchy-nand-rootcheck new file mode 100755 index 00000000..a369e616 --- /dev/null +++ b/system/overlay/usr/libexec/omarchy-nand-rootcheck @@ -0,0 +1,38 @@ +#!/bin/bash +# omarchy-nand-rootcheck: feed systemd's watchdog for omarchy-nand-rootcheck.service +# only while the root's NAND (applesftl) still answers reads. PID 1 lives in RAM +# and keeps running when the root is gone, so its liveness proves nothing. +# Every 10 s this reads one 4 KiB block of the root device past the page cache +# (O_DIRECT, or a flushed buffer cache where the device refuses O_DIRECT) and +# then notifies WATCHDOG=1. A read stuck in D state leaves the notify out and +# WatchdogSec fails the unit; an I/O error (a command that can no longer be +# loaded from the root, or the NAND controller stopped) exits non-zero and +# fails it at once. FailureAction=reboot-force then restarts the device instead +# of leaving it frozen with a dead root. +# It only reads: rewriting a stamp file every 10 s would be 8640 page programs +# a day and an always-open translation-layer block on the NAND. +# udev starts it when an applesftl disk appears; a root elsewhere (a RAM boot, +# another disk) leaves it nothing to watch, and it ends at once, successfully. +set -u +dev=$(findmnt -no SOURCE /) || dev= +case $dev in + /dev/applesftl*) ;; + *) echo "omarchy-nand-rootcheck: the root (${dev:-none}) is not on the NAND; nothing to watch" + systemd-notify --ready + exit 0 ;; +esac +[ -b "$dev" ] || { echo "omarchy-nand-rootcheck: the root ($dev) is no block device"; exit 1; } +blocks=$(($(blockdev --getsize64 "$dev") / 4096)) +[ "$blocks" -gt 0 ] || exit 1 +direct=iflag=direct +dd if="$dev" of=/dev/null bs=4096 count=1 $direct status=none 2> /dev/null || direct= +echo "omarchy-nand-rootcheck: probing $dev ($blocks blocks of 4 KiB) every 10 s, ${direct:-buffered after flushbufs}" +systemd-notify --ready +while :; do + blk=$(((RANDOM * 32768 + RANDOM) % blocks)) + [ -n "$direct" ] || blockdev --flushbufs "$dev" 2> /dev/null + dd if="$dev" of=/dev/null bs=4096 count=1 skip=$blk $direct status=none || + { echo "omarchy-nand-rootcheck: reading block $blk of $dev failed"; exit 1; } + systemd-notify WATCHDOG=1 + sleep 10 +done diff --git a/tests/test_package.py b/tests/test_package.py index b19baef3..306b12ce 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -289,7 +289,7 @@ def run_hook(self, root, *argv, booted=True, chroot=False, systemctl_fails=False def test_an_update_restarts_the_running_power_daemon_only_on_a_running_system(self): # A logout restarts the session, not its system services: an old # omarchy-powerd's lock requests fail against the new shell (#101). - restart = ['daemon-reload', '--no-block try-restart omarchy-powerd.service'] + restart = ['daemon-reload', '--no-block try-restart omarchy-powerd.service omarchy-nand-rootcheck.service'] oomd = restart + ['enable --now systemd-oomd.service'] for argv in (('post-install', '1-1'), ('post-upgrade', '0.4.11-1', '0.4.10-1')): with self.subTest(argv=argv), tempfile.TemporaryDirectory() as temporary: @@ -306,7 +306,7 @@ def test_an_update_restarts_the_running_power_daemon_only_on_a_running_system(se def test_oomd_is_enabled_once_not_on_every_upgrade(self): # An owner who turned systemd-oomd off keeps it off across later upgrades. - restart = ['daemon-reload', '--no-block try-restart omarchy-powerd.service'] + restart = ['daemon-reload', '--no-block try-restart omarchy-powerd.service omarchy-nand-rootcheck.service'] with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) (root / 'local/bin').mkdir(parents=True) From 39fe1106b59f9e46f1bef4e98c17affccb93563b Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sun, 6 Dec 2026 12:39:22 +0800 Subject: [PATCH 3/3] Changelog: NAND root settings and watchdog Assisted-by: LLM --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de2cb1c..f724d57c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,12 @@ release is checked here and released on by hand. ### System +- 32-bit boards with their root on the internal NAND (iPhone 5 and the + others with Apple's raw NAND): writes go out in small bursts instead of + stalling the desktop, reads stream with a larger read-ahead, and a device + whose NAND stops answering restarts by itself instead of hanging + (brkosebay). + - When memory runs out, the tablet closes the heaviest app instead of freezing: systemd-oomd is on, and it passes over the desktop itself (compositor, shell, keyboard) as long as an app is left to close. On a