Skip to content

turbo-persistence: read SST metadata blocks once with pread - #100288

Open
lukesandberg wants to merge 1 commit into
canaryfrom
fleet/turbo-persistence-heap-block-offsets
Open

lukesandberg wants to merge 1 commit into
canaryfrom
fleet/turbo-persistence-heap-block-offsets

Conversation

@lukesandberg

@lukesandberg lukesandberg commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What?

Reads each SST's block-offset table and index block once at open, with positional reads, store the data in a heap buffer, instead of dereferencing the mmap

The offset table becomes a validated BlockOffsets value. Lookup handles keep the index block as an owned array of entries. Both are owned outside the backing enums.

Why?

Every block access needs two offset-table entries, and every lookup binary searches the index block. Reading both with pread and keeping them in memory means locating a block never reads either of them through the mmap.

Currently the offset block is advised as WILLNEED on open, but this is not sufficient, it will ensure it is quickly availble after startup, but the memory remains madvise(RANDOM) so it does not participate in recency accounting. However, these are the hottest blocks in any SST since all accesses reference them.

Alternatively we could madvise(DEFAULT) this range, but the pread is more accurate (our data is not page aligned anyway, but the pread is perfectly accurate

The difference will probably only matter if mmap table pages are being reclaimed.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 1a7c6b2

@github-actions github-actions Bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Oct 16, 2026
@sokra

sokra commented Oct 16, 2026

Copy link
Copy Markdown
Member

Fleet, do some benchmarks to proof that this has a performance benefit. TBH I'm a bit in doubt as memory paged should be similar to in RAM. I don't buy the eviction argument as RAM pages could also be evicted.

Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
@lukesandberg
lukesandberg force-pushed the fleet/turbo-persistence-heap-block-offsets branch from 2189627 to bf09594 Compare October 17, 2026 00:48
@lukesandberg lukesandberg changed the title turbo-persistence: keep SST block-offset tables in memory in mmap mode turbo-persistence: read SST block-offset tables once with pread Oct 17, 2026
@lukesandberg
lukesandberg force-pushed the fleet/turbo-persistence-heap-block-offsets branch from bf09594 to 53350c3 Compare October 17, 2026 01:08
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Comment thread turbopack/crates/turbo-persistence/src/static_sorted_file.rs Outdated
Read every SST's block-offset table and index block at open with positional reads in both access modes. Decode and validate the offset table in place, and keep it outside the backing enums for lookups and compaction iterators.

Keep index entries in memory for lookups, removing mmap-ranged index entries. Use fs_err for positional reads so I/O errors name the SST.

Co-authored-by: Luke Sandberg <210140+lukesandberg@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
@lukesandberg
lukesandberg force-pushed the fleet/turbo-persistence-heap-block-offsets branch from 53350c3 to 1a7c6b2 Compare October 17, 2026 02:04
@lukesandberg lukesandberg changed the title turbo-persistence: read SST block-offset tables once with pread turbo-persistence: read SST metadata blocks once with pread Oct 17, 2026
@lukesandberg
lukesandberg marked this pull request as ready for review October 17, 2026 06:09
@lukesandberg
lukesandberg requested a review from sokra October 17, 2026 06:09
@lukesandberg

Copy link
Copy Markdown
Contributor Author

Fleet, do some benchmarks to proof that this has a performance benefit. TBH I'm a bit in doubt as memory paged should be similar to in RAM. I don't buy the eviction argument as RAM pages could also be evicted.

fair to be skeptical. the issue is about how the OS treats madvise RANDOM and madvise SEQUENTIAL files.

both of those settings disable LRU accounting for mapped memory. So even if the index and offset tables are 'hot' the kernel doesn't track it and so they are just as likely to be paged out as any other mmap'd page. However these are exactly the blocks we know apriori are hot, so pulling them onto the heap is a strong signal. It is true they can still be paged out, but now they are subject to LRU accounting, so only cold ones will be paged out.

This branch has not been deployed

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

Labels

created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants