Skip to content

zram/overlayfs: reliable swap init and image-owned init-script refresh - #254

Open
pdscomp wants to merge 2 commits into
mainfrom
doom/zram-init
Open

zram/overlayfs: reliable swap init and image-owned init-script refresh#254
pdscomp wants to merge 2 commits into
mainfrom
doom/zram-init

Conversation

@pdscomp

@pdscomp pdscomp commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

zram/overlayfs: reliable swap init and image-owned init-script refresh

Split from #252.

Why this PR

This revision greatly simplifies zram initialization compared with the original version of PR #252. It more closely follows the original script from @jamesturton while retaining added logging, comprehensive state and device checks, idempotent behavior, and bounded retry logic (as well as a test case to validate script execution on the host after any updates).

A CC1 boot that fails to bring zram online is the main OOM path during normal load or calibration. The old one-shot zram init could silently continue without swap. Separately, the persistent /etc overlay could keep stale package-owned init scripts after an image update, silently defeating runtime fixes.

Justification / measurements

Reliability change, not a performance change — no MiB claim.

  • New zram init: idempotent, waits for device/sysfs, picks first available compressor, verifies /dev/zram0 in /proc/swaps, retries once via module reload, logs failures.
  • Overlay refresh: on first boot after A/B update, removes only upper-layer copies/whiteouts shadowing scripts present in the new image. User-created scripts untouched.

Risk / rollback

Low. Reverts cleanly; worst case is reverting to previous one-shot zram init behavior.

@pdscomp
pdscomp temporarily deployed to approval-given July 19, 2026 14:35 — with GitHub Actions Inactive
@pdscomp

pdscomp commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Feedback from @suchmememanyskill

  • overlayfs-etc-preinit.sh.in: doesn't know what it's supposed to do.
  • init.d cleanup "should just be a single line rm -f /data/overlay-etc/upper/init.d/*" — user services should be re-symlinked manually per update, since the update could have broken their service anyway.

@pdscomp
pdscomp marked this pull request as ready for review July 19, 2026 15:57
@pdscomp
pdscomp temporarily deployed to approval-given July 19, 2026 15:57 — with GitHub Actions Inactive
@pdscomp

pdscomp commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@suchmememanyskill

  1. The overlayfs preinit block removes overlay copies of image-owned init scripts before /etc is mounted, so an OTA update's new init script isn't shadowed by a stale overlay copy. It only deletes files that also exist in the image's /etc/init.d.

  2. A single rm -f /data/overlay-etc/upper/init.d/* would delete user-added init scripts too. The current loop only removes overlays of image-owned scripts, matching the existing behavior we already had for other services.

@github-actions

Copy link
Copy Markdown

✅ Build Artifacts

Branch: doom/zram-init
Build: 9b0eb8b (merge into main)

Artifact Size
CC1 Firmware 91.31 MB

View workflow run

@pdscomp

pdscomp commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Validation

Ran meta-opencentauri/recipes-core/zram/tests/init-test.sh against the new zram init script.

All cases passed:

  • Normal startup: PASS — zram swap activates successfully.
  • Startup logging: PASS — successful activation is logged.
  • Idempotent startup: PASS — a second start detects active swap and is a no-op.
  • Transient module failure: PASS — recovers after one modprobe failure and succeeds on retry.
  • Retry logging: PASS — retry attempt is recorded.
  • Permanent module failure: PASS — setup fails cleanly after the bounded five-attempt limit.
  • Failure cleanup: PASS — no swap remains active after permanent failure.

Result: PASS

On-machine testing will be next once a formal PR build is complete.

pdscomp added 2 commits July 19, 2026 12:16
Replace the one-shot zram setup in meta-opencentauri/recipes-core/zram/files/init with an idempotent initializer that waits for and verifies active swap, retries transient setup failures, configures zram deterministically, logs failures, and handles stop/restart safely.

Add meta-opencentauri/recipes-core/zram/tests/init-test.sh with host-side coverage for successful startup, idempotence, transient recovery, and bounded permanent failure.

Update meta-opencentauri/images/files/overlayfs-etc-preinit.sh.in to remove overlayfs overrides and whiteouts for Cosmos-provided init scripts while preserving user-provided scripts across upgrades.
@pdscomp

pdscomp commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

On-machine CC1 validation

Validated the formal PR-254 build on carbon2u after reboot.

zram/swap

  • /proc/swaps: PASS — /dev/zram0 active, 229,308 KiB total, 9,216 KiB used, priority 100.
  • swapon --show: PASS — approximately 223.9 MiB zram swap online.
  • free -m: PASS — approximately 28.4 MiB RAM available with zram enabled.
  • Boot log: PASS — kernel added zram0, configured capacity, and enabled swap successfully.
  • Deployed init script: PASS — contains retry, verification, idempotence, and failure-bounding logic.
  • Live idempotence check: PASS — running /etc/init.d/zram start while active returned zram: already active.
  • VM tuning: PASS — swappiness 150, watermark boost 0, watermark scale 125, page-cluster 0, and vfs cache pressure 500.
  • No zram or out-of-memory failures were found in the inspected logs.

Service health

  • Klipper: PASS — running and API state ready.
  • Moonraker: PASS — connected to Klipper, no failed components reported.
  • uStreamer: PASS — running.
  • Printer API: PASS — reports Release - PR-254-9b0, state ready.
  • System uptime/load: PASS — approximately 7 minutes uptime, load average below 0.1.

The PR is now ready for review and possible merge.

@github-actions

Copy link
Copy Markdown

✅ Build Artifacts

Branch: doom/zram-init
Build: 3fceb5f (merge into main)

Artifact Size
CC1 Firmware 91.31 MB

View workflow run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant