3 Commits
Author SHA1 Message Date
jsthope b8273c0e39 runtime: buffer_at prefers an aliasing buffer that holds the whole view
With placed buffers aliasing in one heap, a large buffer B and a small S
inside it, a vertex or index view that starts in S and runs past its end
resolved to S, the closest start below the VA, and buffer_at cut it at
S's end: the rest read as out of bounds, though B holds all of it. Found
by traeb0n in the review of #2823.

BufferVaIndex::find takes the bytes the lookup needs and returns, among
the ranges that hold the VA, the closest start (larger ID on a tie) that
also holds all of them; when none does, the closest that holds the VA,
as before. Without overlaps the first range it looks at is still the
answer. With a fallback found, the walk stops once no range can hold all
the bytes, bounded by the longest live range. buffer_at passes the
requested size.

buffer_va_index_test checks views that fit in the small buffer, run past
it into the large one, run past every range and have size 0, and three
quarters of the random-table lookups now name a view of up to 32 KiB,
checked against a scan with the same rule.
2026-11-22 22:50:57 +01:00
jsthope 111b634c21 runtime: BufferVaIndex's longest-range bound follows the live ranges
The bound that stops a lookup's walk only grew: once a large buffer was
freed, every later miss still walked back as far as that buffer had
reached. With 20 000 buffers of 256 bytes, a 1 GiB range added then
removed left a miss past the last buffer at 250-600 us instead of ~50 ns
(found by @padhossein in review of #2823).

A multiset of the indexed sizes keeps the bound at the longest range
indexed now; insert and erase stay O(log n), find is unchanged. Inserting
the same (va, id) again replaces its size instead of leaving the old one
in the bound.

buffer_va_index_test checks the bound after erases (same sizes and a
smaller re-registration included), against the longest live range in all
200 random tables, and times the review's miss-after-free case.
2026-11-22 20:09:00 +01:00
jsthope 454ae0637c runtime: BufferVaIndex, an ordered VA -> buffer lookup
Buffers' VA ranges kept in a std::map by first VA: a lookup is a binary
search, walking down from the nearest start only while a range can still
reach the VA (bounded by the longest range), so aliasing placed buffers
that overlap still resolve, to the range that starts closest below the VA
(the larger ID on a tie).

buffer_va_index_test checks edges, overlapping and nested ranges,
re-registration and erase, then 200 random tables against a linear scan
with the same rule, and prints the lookup time against the scan over every
resource that buffer_at does today (--bench for 50k and 100k resources).
2026-11-22 19:17:52 +01:00