Skip to content

Commit 1c3238a

Browse files
committed
make-disk-image: limit dirty page accumulation to prevent OOM
Set dirty_bytes and dirty_background_bytes to low thresholds (10MB/5MB) before copying the nix store into the VM image. This forces the kernel to write back dirty pages almost immediately instead of letting them accumulate. Clean page cache is evicted automatically under memory pressure, so this prevents OOM even when copying files larger than available VM RAM.
1 parent c4d34f2 commit 1c3238a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/make-disk-image.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ let
155155
# systems, while -P 4 is ~30% slower. Cap at 8 but use fewer workers if the
156156
# system has fewer cores.
157157
mkdir -p "$rootMountPoint"/nix/store
158+
# Limit dirty page accumulation to prevent OOM in the VM.
159+
# The kernel evicts clean page cache under memory pressure, but dirty
160+
# pages must be written back first. Low thresholds force early writeback
161+
# so dirty pages never pile up enough to trigger the OOM killer,
162+
# even when copying files larger than available RAM.
163+
echo 10000000 > /proc/sys/vm/dirty_bytes
164+
echo 5000000 > /proc/sys/vm/dirty_background_bytes
158165
${
159166
if cfg.copyNixStoreThreads == "auto" then
160167
''

0 commit comments

Comments
 (0)