Skip to content

core: the whole-checkpoint prefetch competes with the load path on slow storage #950

Description

@FeathBow

Description

WeightPrefetch::spawn reads the whole checkpoint into the page cache on eight threads while the load path reads the same file through its mmap. On fast storage the prefetch runs far enough ahead that the load path lands in cache and the load gets faster. On slow storage neither is true: the two contend for the same device, and the checkpoint is larger than the page cache can hold anyway, so pages warmed early are evicted before the load path reaches them.

Measured on one box with the same 22.18 GiB checkpoint held on two devices, cold in both arms:

source prefetch on prefetch off
SSD, 2.3 GB/s single-stream 4.87 s 6.26 s
array, 0.32 GB/s single-stream 162.7 s 136.3 s

The prefetch is worth 22% on the SSD and costs 16% on the array. The clearest signal is a phase that should not depend on the source at all: submitting one allocation and one staging plan per tensor takes 40 ms on the SSD and 10.7 to 15.6 s on the array with the prefetch running, falling to 0.7 to 2.3 s when it is off. The main thread is queued behind the prefetch on the device.

There is a second case with the same shape. When the checkpoint is already in the page cache, a warm restart for instance, the prefetch has nothing to warm and still reads all of it, competing with the load path for memory bandwidth. Measured warm, it costs 14% on the SSD copy and 11% on the array copy, and the rate it observes in that state is high, so a slowness test alone never catches it.

Proposed Plan

  • Have the prefetch measure the rate it is already achieving and stand down when the source is too slow for it to get ahead. Its own read rate is the device rate, so no probe is needed.
  • Ask the kernel, per chunk, whether the page cache already holds it, and skip the read if so. A residency answer is exact where a rate is a proxy, and doing it per chunk means a partly resident checkpoint still gets the missing part warmed.

Acceptance Criteria

  • On fast storage the cold load is unchanged. On slow storage it matches the prefetch-off arm. On a resident checkpoint it matches never spawning the prefetch at all. No new environment variable, no operator knowledge required.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions