Skip to content

util/idalloc: keep sparse allocations within their segment - #1438

Merged
DjDeveloperr merged 3 commits into
aurora-wipfrom
maint/carry-842-sparse-idalloc
Dec 2, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-wipfrom
maint/carry-842-sparse-idalloc

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 30, 2026 •

Copy link
Copy Markdown

What: The sparse ID allocator (util_idalloc_sparse, used for GL object names in src/mesa/main/hash.c) now bounds single allocations and one-ID ranges to the current segment before moving to the next, so a range can no longer run past a segment's end. This carries Ryan Murray's two signed commits from #842, including the single-ID range fix. The first parent is 7e3205c449e0 and the second is aurora-wip at 8b59f2b0a70e. The allocator implementation and its regression fixture are byte-identical to the original head, and both commits keep their IDs and sign-offs.
Tested: The allocator object and its regression test built in a warm Mesa build, and all four sparse rollover and range tests passed. J615 (MacBook Air M3, G15G) at this head: Vulkan memory, object-management and timeline-semaphore CTS lists matched the merge base with 0 GPU faults (row). The original J413 Piglit run covered the first fix only. Gallium GL at this head, same-boot A/B against the merge base with 0 GPU faults: J773g (M4 Mac mini, G16G) matched on 1,286 GL/GLES object-name and buffer CTS cases (0 diffs) and passed a sparse glGenBuffers name-uniqueness check (row), and on J700 (MacBook Neo, G17P) 4,456,448 glGenBuffers names across the 2^22 segment boundary are all unique (the base hands out 4194304 twice) with 991/991 GLES3 cases unchanged (row).
Risk: two-way door · all Macs: GL object names go through the sparse allocator, and the plain util_idalloc_alloc() it now shares a helper with is used across Gallium (for example resource and buffer IDs). Its search and growth are unchanged apart from the new exhaustion abort.
Not yet: nothing owed for merge.

RyanTheTide and others added 3 commits November 24, 2026 00:00
The lowest-free word can still point to a full final word. If a scan finds no free bit, the dense allocator grows beyond the segment and returns an ID belonging to the next segment. Freeing that ID then clears a different bitmap.

Bound the single-ID search and growth to the segment. If all its words are full, continue to the next segment and let free lower the search hint when space becomes available again.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
A one-ID range request still used the dense allocator directly. At a full sparse segment it grew that segment bitmap from 131072 to 262144 words before backing off to the next segment.

Route one-ID range requests through the bounded sparse allocator. Test allocated and reserved segment tails through both single-ID entry points, checking bitmap bounds, distinct IDs, freeing and tail reuse.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Keep both signed allocator commits, the bounded single-ID range regression tests and the current util_tests registration.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 30, 2026 23:56

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at c1740924ba3a

Blockers:

  • Complete the exact-head c1740924ba3a hardware verification noted in the PR body: repeat gl-1.5-gen-buffers-unique on J413 and a second Gallium GPU covering both the segment rollover fix and the single-ID range fix (7e3205c449).

Checked:

  • Audited the full 3-file diff (src/util/u_idalloc.c, src/util/tests/u_idalloc_test.cpp, src/util/meson.build, +100/-21, MERGEABLE against aurora-wip):
    • util_idalloc_try_alloc() bounds num_elements and growth (MIN2(MAX2(num_elements, 1) * 2, max_elements)) to max_elements, advances lowest_free_idx, and returns false when i >= max_elements instead of growing a full segment's bitmap.
    • util_idalloc_sparse_alloc_range() delegates num == 1 to util_idalloc_sparse_alloc(), closing the single-ID range rollover gap while keeping util_idalloc_alloc() semantics unchanged.
    • Parameterized idalloc_sparse gtest (u_idalloc_test.cpp) covers both alloc() and alloc_range(..., 1) across allocated-tail and reserved-tail rollover and tail reuse; all 4 tests passed on the carrier build.
Evidence
  • Head: c1740924ba3a383750c6c0b40affe88ba2cfea96 (base aurora-wip, MERGEABLE, carries signed commits 0a7f4b2e93 and 7e3205c449 cleanly).
  • No code defects found; ready to approve once exact-head Piglit gl-1.5-gen-buffers-unique rows are posted.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at c1740924: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA c1740924, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text no add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at c1740924ba3a

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Audited the full 3-file diff (src/util/u_idalloc.c, src/util/tests/u_idalloc_test.cpp, src/util/meson.build, +100/-21, MERGEABLE against aurora-wip):

  • util_idalloc_try_alloc() bounds num_elements and growth (MIN2(MAX2(num_elements, 1) * 2, max_elements)) to max_elements, advances lowest_free_idx, and returns false when i >= max_elements instead of growing a full segment's bitmap.
  • util_idalloc_sparse_alloc_range() delegates num == 1 to util_idalloc_sparse_alloc(), closing the single-ID range rollover gap while keeping util_idalloc_alloc() semantics unchanged.
  • Parameterized idalloc_sparse gtest (u_idalloc_test.cpp) covers both alloc() and alloc_range(..., 1) across allocated-tail and reserved-tail rollover and tail reuse; all 4 tests passed on the carrier build.

Follow-ups (not blocking): exact-head gl-1.5-gen-buffers-unique on J413 (2nd GPU not required)

@RyanTheTide

Copy link
Copy Markdown

Row: c1740924ba3a + J615 (MacBook Air M3, T8122, G15G C0) + PASS: 0 regressions vs base, 0 GPU faults.

  • Setup: two ICDs cross-built from this head and from its merge-base 8b59f2b0a70e with the same meson options, swapped through VK_DRIVER_FILES on one boot (no install, no reboot). Kernel 7.3.0-aurora-edge, SELinux Enforcing.
  • VK-GL-CTS, base vs PR:
    • memory.allocation.basic + api.object_management.{single,multiple_shared_resources} + api.smoke + compute.pipeline.basic: 283/284 pass (1 not supported)
    • memory.{binding,device_group_allocation} (every 4th case): 28 pass, 106 not supported
    • synchronization{,2}.timeline_semaphore.* (5153 listed): 3517 pass before the run aborted, at the same case on base and PR: synchronization2.timeline_semaphore.one_to_n.write_copy_buffer_read_vertex_input.buffer_262144 returns VK_ERROR_OUT_OF_DEVICE_MEMORY from vkEndCommandBuffer. That's pre-existing on G15 and not from this PR.
    • Every case has the same status on base and PR (3828 Pass -> Pass, 1 ResourceError -> ResourceError).
  • Kernel log during the run: 0 GPU faults, timeouts or recoveries.

@DjDeveloperr

Copy link
Copy Markdown
Author

Merge train status at c1740924ba3a. The merge result on aurora-wip bf62a48b5585 (all three PR files unchanged) passed the Arm64 Asahi build and tests. The description now has What/Tested/Risk/Not yet lines, and Risk names the plain util_idalloc_alloc() users as well as the sparse GL-name path.

Still owed:

  • gl-1.5-gen-buffers-unique and a GL object-name CTS subset at this head on two Gallium generations (J773g and J700 requested);
  • an independent review.

@DjDeveloperr

Copy link
Copy Markdown
Author

J700 (G17P) row: mesa#1438 · J700 MacBook Neo (A18 Pro, G17P B1), stock Fedora 44 7.3.0-41.fc44.aurora.aarch64, same boot, base 8b59f2b vs head c174092: PASS — glnames (4456448 names via glGenBuffers(99991) across the 2^22 segment boundary): base returned name 4194304 twice (1 duplicate); head all unique, objects/delete/teardown clean; 1438-gles3 991/991 compared, base 991 Pass → head 991 Pass, 0 status changes; 0 GPU faults, 0 kernel WARNINGs; stock handback verified.

Kit B payload 5c0239c4471e71ad…, target evidence 91796765eaa899d7… (Mini: work/j700-mesa-batch-b-20261202/evidence/receipt-WfPHHaNB). The run started about 08:44 UTC and spent 347 s on target under the Neo lease. The stock fingerprint and both Apple partners were identical before and after.

@DjDeveloperr

Copy link
Copy Markdown
Author

Row: c1740924ba3a + J773g (Apple M4 Mac mini, T8132, G16G B0 / HAL200 / AGX3B, kernel 7.3.0-ARCH-m4main-6c83a2a6, boot_id=21564087-69fe-448d-be51-ec60300e9bc4) + PASS: same-boot native Asahi Gallium + Borealis A/B vs base 8b59f2b0a70e, 1,286 GL/GLES object-name/buffer CTS cases with 0 diffs, sparse glGenBuffers uniqueness check PASS, Vulkan render.postfx --verify valid, 0 GPU faults.

  • Sparse buffer/texture/FBO name uniqueness check (test_gen_buffers_unique, GL 4.6, 10,000 glGenBuffers + 64 sparse user-assigned buffer IDs across segments + 2,000 delete/re-gen + 4,096 textures + 1,024 FBOs):
    • Base git-8b59f2b0a7: PASS (zero=0 dup=0 glerr=0x0).
    • Head git-c1740924ba: PASS (zero=0 dup=0 glerr=0x0).
  • GL / GLES CTS A/B (surfaceless FBO 256x256, MESA_SHADER_CACHE_DISABLE=true):
    • dEQP-GLES3.functional.{lifetime,buffer}.*: 753/753 Pass on both base and head (0 diffs).
    • KHR-GL46.{direct_state_access,buffer,vertex_attrib_binding,shader_storage_buffer}*: 533 cases (531 Pass, 1 CompatibilityWarning, 1 InternalError) on both base and head (0 diffs).
  • Vulkan check (gpubench-vk --verify render.postfx): base 1248 fps → head 1256 fps, CRC 4707efa8 (valid=true).
  • GPU health: health: failed 0 errno 0 degraded 0, recoveries 0, hang_kills 0, 0 dmesg faults.

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE

Blockers: none.

Checked:

  • src/util/u_idalloc.c: util_idalloc_try_alloc() bounds both the scan (MIN2(buf->num_elements, max_elements)) and growth (MIN2(MAX2(num_elements, 1) * 2, max_elements)) to the segment limit, advances lowest_free_idx safely without overflowing, and returns false when full so util_idalloc_sparse_alloc() moves cleanly to the next segment. util_idalloc_sparse_alloc_range() delegates num == 1 to util_idalloc_sparse_alloc(), closing the single-ID range rollover bug. Plain util_idalloc_alloc() keeps its 2^32 capacity with explicit exhaustion abort.
  • src/util/tests/u_idalloc_test.cpp + src/util/meson.build: parameterized GoogleTest suite covers both util_idalloc_sparse_alloc and util_idalloc_sparse_alloc_range(..., 1) across allocated-tail and reserved-tail segment boundaries plus tail reuse. (Non-blocking note: u_idalloc_test.cpp carries SPDX-License-Identifier: GPL-2.0-only; fine for a standalone test binary since licenses/GPL-2.0-only exists in the tree, though switching it to MIT in a follow-up would match the rest of src/util/tests/.)
  • Clean merge state (MERGEABLE), PR metadata complete (What/Tested/Risk/Not yet), fork ARM64 Asahi build and test CI passed (46830114864), and exact-head c1740924ba3a hardware PASS rows across three generations: J615 (M3, 3,828 Vulkan CTS Pass->Pass), J700 (A18 Pro, reproduced the base 4194304 duplicate bug and verified fixed on head + 991/991 GLES3 CTS), and J773g (M4, test_gen_buffers_unique PASS + 1,286 GL/GLES CTS 0 diffs + Vulkan verify).
Evidence
  • Audited full 3-file diff (+100/-21) at c1740924ba3a alongside surrounding util_idalloc_resize() and util_idalloc_sparse_*() helpers in src/util/u_idalloc.c.
  • Verified fork ARM64 CI pass (https://github.com/DjDeveloperr/mesa/actions/runs/46830114864) and exact-head hardware receipts on J615 (#issuecomment-7331454035), J700 (base repro -> head fix), and J773g.

@DjDeveloperr DjDeveloperr removed needs-review No approving review from Core or Omarchy Mac yet (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Local CI on the merge tree (hosted Actions is off, so this stands in for the Arm64 Asahi build-test job). Head c1740924ba3a merged onto aurora-wip 056b5efd7e42 gives merge 18c77527dece, tree 9a78d55d9e88, with no conflicts. It ran in the Fedora 44 CI image on x86_64 (pc):

Step Result
.github/ci/mesa-arm64.sh (asahi + poly suites) Ok 387, Fail 0, Skipped 1
Same script with -march=x86-64-v3 -funsigned-char Ok 387, Fail 0, Skipped 1
util_tests --gtest_filter=*idalloc*, both builds 4/4 passed
meson test --suite util Ok 19, Fail 0
meson test --suite asahi --suite vulkan --suite poly Ok 445, Fail 0, Skipped 1

The J773g and J700 Gallium rows at this head are linked under Tested. Merging at c1740924ba3a.

@DjDeveloperr
DjDeveloperr merged commit dde0cbe into aurora-wip Dec 2, 2026
1 check passed
@DjDeveloperr
DjDeveloperr deleted the maint/carry-842-sparse-idalloc branch December 2, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants