Repository navigation
fix(layer-stream): align a pinned staging arena whose base is off a sector boundary (#1531) - #1621
Conversation
…ector boundary (MakazhanAlpamys#1531) plan_pinned_arenas keeps placements sector-aligned within their arena, but torch's caching host allocator can hand back a base at a multiple of only 512 bytes, and one misaligned region turned direct I/O off for the whole store. Shift the arena's placements by the base's distance to the next sector when its slack allows, else take the next power of two, which always has room; pinned_bytes counts the arenas actually held.
…sole (MakazhanAlpamys#1531) When the staging is not sector-aligned the source reads the whole store through the page cache and said so only in the logger, which a soup train user does not see. The source now records staging_aligned and _build_source prints the same line on the console.
82b8111 to
413e351
Compare
MakazhanAlpamys
left a comment
There was a problem hiding this comment.
@ybai08, thank you, this is a careful fix. Two things stood out. You turned the arena allocation into a small seam (_allocate_pinned_arena), so a CPU test can force the 512-byte offset without faking torch itself. And you measure the shift again on the replacement arena instead of reusing the first one. test_the_shift_is_measured_again_on_the_bigger_arena is the only test that catches the loss of that line, so it earns its place. Keeping item 3 as its own commit on top of #1536 made the review easy.
What I checked on 413e3510 (CPU only):
- The next size always has room.
plan_pinned_arenasfloors every arena atalign, so a staging arena is at least 4096 bytes and2 * size - fill >= size, which is more than any shift.direct_ioisFalsewhenever the staging is unaligned, because every drive keeps the buffered opener. - Your new file passes: 12 passed. The same file on current
maingives 4 failed, 5 errors, 3 passed. The three that pass there are the helper check, the formerpragma: no coverbranch and the logger-only path, as expected. - A trial merge with current
mainis clean. On the merged tree, 16 test files that build or patch the disk source give 860 passed, 47 skipped, andruff checkis clean. - 12 mutations, all caught. Seven are in
_allocate_staging: the first shift forced to 0, the next-size branch disabled, the shift not measured again,pinned_bytesback to the plan's figure,>turned into>=, the replacement atsizeinstead of2 * size, and the shift ignored when slicing. One forcesstaging_alignedtoTrue. Four are on the console path, among them thegetattrdefault flipped, whichtest_v07200.pycatches.
To your question: please keep the per-drive message out of this PR. #1615 covers it, together with the ready line and stats(), and it now has its own contributor.
The CUDA run of the layer-streaming test files (the issue's third criterion) stays with us, as agreed on the issue. From my side this is ready: it now waits only on the required checks (the full matrix starts when it carries ci:full).
|
Closing and reopening only to make CI test this against today's main (a dependency release broke CI repo-wide, fixed by #1637). Nothing for you to do; the approval stands. |
|
Merged as |
What does this PR do?
Closes #1531, on current
main(after #1536), in two commits. The second is item 3 on its own, as asked in the issue.1. A misaligned arena base no longer turns direct I/O off (
_allocate_staging)plan_pinned_arenaskeeps the placements on sector boundaries relative to their arena, so the regions are aligned only when the arena's base is. The base is now read right after the arena is allocated:(-base) % SECTOR_BYTESinside the same arena.pinned_bytescounts the arenas that are held, so a bigger arena shows there.The allocation is a module-level function,
_allocate_pinned_arena(size), so a CPU test can replace it. Thepragma: no coveron the page-cache branch is gone.2. The fallback is said on the console (item 3)
When the staging is still not sector-aligned, the source read the whole store through the page cache and said so only in
logger.warning. The source now recordsstaging_aligned, and_build_sourceprints the same line on the console at both places it returns a disk source.direct_io, whichstream_probe.pyrecords, is alreadyFalsein that case after #1536. I did not put the per-drive "direct I/O is unavailable there" message from #1536 on the console: that is a property of the volume, not this fallback. Tell me if you want it there too.Tests (
tests/test_issue1531_pinned_arena_alignment.py, 12 tests, CPU only: the arena allocation is replaced by pageable memory at a forced 512-byte offset)pinned_bytesis the bigger arena.direct_ioisFalse, direct I/O is not probed, the logger says it (the formerpragma: no coverbranch).Each guard was removed in turn: 12 mutations, 12 caught (6 in
_allocate_staging, 6 in the console path). One survived my first version of the tests, the re-measured shift, which is why that test is there.What I ran
pytest tests/test_issue1531_pinned_arena_alignment.py --no-cov: 12 passed; 8 passed at the first commit alone._build_sourceorAsyncDiskSource: 901 passed, 45 skipped. Six tests intest_v07200.pyandtest_disk_tier_stripe_read_ahead_advice.pybuild the source from a stand-in class, so_build_sourcereadsstaging_alignedwith a default of aligned.pytest tests/ -q --no-cov: 32866 passed, 254 skipped, 2 failed. That run was on the head before the re-measured-shift test was added (a test-only change). The two failures aretests/test_v0537.py::TestToolEndpointsLive::test_bash_tool_bounded_streaming_kills_massive_outputand::test_bash_tool_environment_secret_isolation. They fail the same way onmainon this machine: the sandboxedpython3exits 72 because of the state of this Mac's Xcode tools.ruff checkon the three changed files: clean.Type of change
Checklist
ruff check src/soup_cli/ scripts/ tests/passes (run on the changed files)pytest tests/ -vpasses (2 failures that also fail onmainon this machine, see above)README.mdand the matching page underdocs/) if needed (the direct I/O paragraph indocs/performance-and-quantization.mddoes not describe this fallback)