Repository navigation
Conversation
…of the page cache - The checkpoint writer flushes and fsyncs each file every `ckpt.write_sync_mib` MiB (64 by default) and drops each synced range from the page cache with posix_fadvise(DONTNEED). The end of a write no longer waits for a whole rank file of dirty pages, and checkpoints stop accumulating in the page cache, which counts against the container's memory cgroup. - With `ckpt.async_save`, the pinned staging buffers are allocated right after the first optimizer step instead of by the first save. - Checkpoint disk metrics are read in one background thread, and the first rank of every node reads its cgroup v2 memory usage there (rank 0 logs `system/memory_*`, each node warns once near its limit). A failed disk read keeps the last values.
MarioSieg
marked this pull request as ready for review
December 3, 2026 19:45
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CheckpointWriterwrites files asPacedFiles that flush and fsync everyckpt.write_sync_mibMiB (new field, default 64;Nonesyncs once at the end of each file as DCP does). DCP otherwise leaves a whole rank file dirty until its end, and the final fsync stalls any file operation of the training loop on that filesystem, holding every rank at the next collective. In an async-save benchmark (132 GB per save, one node), the step where the write ended went from 24-30 s over the median step to under 0.05 s over.posix_fadvise(DONTNEED). Checkpoint pages count against the container's memory cgroup and otherwise pile up save after save (an NFS client even keeps pages of files another node deleted forkeep_last). Once the cgroup is at its limit, every allocation reclaims synchronously and one slow rank stalls all. Measured: page cache added per save went from about 34 GiB per node to about 0, and the longest step on a node close to its limit went from 5.3-7.5 s to 1.5 s.ckpt.async_save,CheckpointManager.prepare_async_saveallocates the pinned staging buffers right after the first optimizer step, while memory is plentiful, instead of inside the first save.system/ckpt_disk_*is read in one long-lived daemon thread (BackgroundSystemMetrics), so a step never blocks on a filesystem that is flushing; each step logs the latest finished read, and a failed read keeps the last values. Under a cgroup v2 memory limit, every node's first rank also reads its cgroup and warns once above 90% of the limit, and rank 0 logssystem/memory_{used,limit,page_cache,shmem}_gib.write_sync_mib = 64).--ckpt.write-sync-mib Nonerestores DCP's one fsync per file (the page cache is still dropped at file end).Test plan
uvx ruff check/uvx ruff formaton the changed files.PacedFilewrites the same bytes, and calls fadvise exactly on(0,64K),(64K,64K),(128K,64K),(192K,rest)for a 200 KiB file at 64 KiB syncs (whole file once withNone).PacedFilehas 0 of its 51,200 pages resident (mincore), compared with 51,200 for a plain write.dcp.save/dcp.loadround trip throughCheckpointWriter(paced,None, and smallmax_file_bytes) loads identical tensors, and the.distcpfiles are byte-identical to stockFileSystemWriter's.BackgroundSystemMetricsagainst a fake cgroup: metrics, warning near the limit, keeps last disk values after a failed read, stops memory metrics after a failed memory read, returns{}with nothing to read.CheckpointConfigparseswrite_sync_mib(64 default,None, rejects 0), and--trainer.ckpt.write-sync-mibshows up inrl --help.Note
Medium Risk
Touches checkpoint persistence, async-save memory timing, and training-step metrics; misconfiguration could affect resume correctness or mask I/O stalls, but changes are localized and default-on with an escape hatch (
write_sync_mib = None).Overview
Checkpoint I/O now writes DCP shards through
PacedFile/PacedFileSystem, flushing and fsyncing everyckpt.write_sync_mibMiB (default 64, or once per file when set toNone), then dropping each synced range from the page cache viaposix_fadvise(DONTNEED). That applies to sync and async saves viaCheckpointWriterand the new_storage_writerhelper.Async save staging gains
prepare_async_save, called after the first optimizer step in RL and SFT so pinned host buffers are sized up front instead of on the first save under memory pressure. Async save setup is factored into_setup_async_save.Observability:
get_ckpt_disk_metricson the hot path is replaced byBackgroundSystemMetrics(daemon thread on each node’s local rank 0). Rank 0 logs the latest completed disk stats; under cgroup v2 limits it also logssystem/memory_*metrics and warns once above 90% usage.Documentation in
training.mdis expanded for host memory, page cache behavior, and system metrics.Reviewed by Cursor Bugbot for commit 5d60715. Bugbot is set up for automated code reviews on this repo. Configure here.