Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion system/overlay/usr/lib/omarchy-a/package-install
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions system/overlay/usr/lib/udev/rules.d/60-omarchy-apple-nand.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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"
# 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"
38 changes: 38 additions & 0 deletions system/overlay/usr/libexec/omarchy-nand-rootcheck
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Loading