AGC: on lavapipe, released descriptor sets stay allocated in chain pools that still hold a live set (about 30 per frame in Ghost of Yōtei PPSA26344) #6608

Closed
opened 2026-10-15 22:46:11 +00:00 by Dextroid17 · 0 comments
Dextroid17 commented 2026-10-15 22:46:11 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T22:46:11Z.


What

The debt entry "Descriptor pool recycling" (#1333, docs/dev/debt/libSceAgcDriver.md) says "A cached set can retain unused slots in an exhausted pool until eviction; peak gameplay pool memory remains unmeasured." I measured it in Ghost of Yōtei (PPSA26344) on lavapipe.

DescriptorCache::Free resets a chain pool only after its last live set is released. Until then, every set released from that pool stays allocated in Vulkan. On a tree based on current main, the sets still allocated in Vulkan grew by about 30 per presented frame during gameplay, and memory grew with them. With each set freed individually, the count stayed flat.

Measurements (tree based on main 31cbb55d7)

Two 900 s runs with the same binary, with the shader cache deleted before each run. The only difference was a local switch that creates chain pools with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT and frees each set in Free with vkFreeDescriptorSets, as the code did before #1333. The pool chain and the reset of an emptied pool are kept. A local probe wraps the Vulkan descriptor pool and set calls, counts the sets still allocated, and reads the cgroup's memory.current and the process's memfd sizes every 10 s.

cgroup memory.current, at the first probe at or after each presented frame:

 frame                     1        25       50       75       100      125
 pools reset when empty    11.2 GiB 13.6 GiB 14.5 GiB 15.3 GiB 16.1 GiB 16.5 GiB
   sets still allocated    243      1,026    1,817    2,489    3,293    4,037
 sets freed individually   11.2 GiB 11.7 GiB 11.7 GiB 11.7 GiB 11.7 GiB 11.7 GiB
   sets still allocated    244      271      273      273      273      332

At 900 s:

                          frames   sets still   sets per frame   memory.current   lavapipe "allocation fd"
                                   allocated    (gameplay)                        memfd
 pools reset when empty    141      4,444        +30.0            17,393 MiB       9,185 MiB
 sets freed individually   253        352         +0.4            12,021 MiB       4,476 MiB
  • VkDeviceMemory was the same in both runs (8,036 MiB live at the end). The allocation fd memfd accounts for 4,709 MiB of the 5,372 MiB memory.current difference. I did not measure the size of each set.
  • Live descriptor pools of all kinds: 41 against 43 at the end (42 in most probes of the run with individual frees), so the extra sets sit in pools that are not reset, not in extra pools.
  • The set count includes sets held by Recycle in both runs. With individual frees it stayed between 271 and 352, so Recycle's lists do not account for the growth.
  • Neither run reached the 22 GiB limit or used swap. The run without individual frees reached gameplay later (first frame at 544 s against 372 s), so it covered only 141 frames. Both runs started gameplay at 11.2 GiB, which is why the tables compare them at the same frame. In the four earlier runs, first frames ranged from 211 s to 322 s with no pattern by arm. I make no frame-rate claim.
  • No validation errors, terminations or crashes in either log.

On a tree based on main a08de68 (before #1201), four runs gave about 79 sets per frame without individual frees (peaks 22,027 and 22,141 MiB against the 22 GiB limit; one run used 5.8 GiB of swap) and a flat 11.8 GiB with them. I have not measured how much of the lower rate on current main comes from #1201.

Why lavapipe

In Mesa 26.2.4, lvp_descriptor_set_create (src/gallium/frontends/lavapipe/lvp_descriptor_set.c) allocates a block for each set in llvmpipe's allocation fd memfd. The block is freed only by vkFreeDescriptorSets, vkResetDescriptorPool or vkDestroyDescriptorPool. Freed blocks are reused, but the memfd does not shrink. So each released set in a pool that is not reset keeps its memory. Drivers that carve sets out of one buffer per pool should not use more memory for these sets. I did not measure RADV, NVIDIA or Windows.

I did not find which sets keep the pools alive. Candidates: cached sets (the case in the debt entry) and, on current main, released draw sets held by Recycle (up to 4,096 per layout), which never reach Free.

Why this is an issue and not a PR

The local switch is the individually freed path that #1333 removed because RADV 26.2.2 can place a set past a FREE_DESCRIPTOR_SET pool's buffer. It is not a fix for main. Possible directions:

  1. Allocate long-lived sets from a pool chain of their own, so that a held set never pins a pool of per-draw sets.
  2. On lavapipe only (VK_DRIVER_ID_MESA_LLVMPIPE), create chain pools with FREE_DESCRIPTOR_SET and free each set. RADV keeps the reset-only pools that #1333 needs. The device already branches on the driver ID in FragmentBarycentric.hpp and SubgroupClock.cpp.
  3. Use smaller chain pools, so that one held set pins fewer released sets. This creates more pools on every driver.

I can measure any of these in the same scene.

Environment

  • CachyOS, kernel 7.2.9, Intel Core i9-11900K (16 threads), 32 GB RAM. Each run was limited with systemd-run --scope -p MemoryMax=22G -p MemorySwapMax=8G.
  • lavapipe (Mesa 26.2.4, llvmpipe LLVM 23.1.1, 256 bits), GALLIUM_OVERRIDE_CPU_CAPS=avx. -O2 build (CMAKE_CXX_FLAGS=-O2, no build type) with GCC 16.2.1.
  • Tree: main 31cbb55d7 (contains #1201) plus the first two commits of #6054 and local changes that let the title reach gameplay. Only the switch and the probe touch DescriptorCache. One local change adds a separate reset-only descriptor ring in TextureDetiler for a channel-extract compute pass; the probe counts its pools and sets in both runs. ShaderResources.cpp and ShaderResources.hpp are unchanged on main 5d9dcc42d.

Related: #1333 (pool recycling), #1201 (draw sets released through Recycle), #6567 (open: reuse a recycled descriptor set only for a table of its own size).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5875104135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/6608). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-15T22:46:11Z. --- ### What The debt entry "Descriptor pool recycling" (#1333, `docs/dev/debt/libSceAgcDriver.md`) says "A cached set can retain unused slots in an exhausted pool until eviction; peak gameplay pool memory remains unmeasured." I measured it in Ghost of Yōtei (PPSA26344) on lavapipe. `DescriptorCache::Free` resets a chain pool only after its last live set is released. Until then, every set released from that pool stays allocated in Vulkan. On a tree based on current `main`, the sets still allocated in Vulkan grew by about 30 per presented frame during gameplay, and memory grew with them. With each set freed individually, the count stayed flat. ### Measurements (tree based on main `31cbb55d7`) Two 900 s runs with the same binary, with the shader cache deleted before each run. The only difference was a local switch that creates chain pools with `VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT` and frees each set in `Free` with `vkFreeDescriptorSets`, as the code did before #1333. The pool chain and the reset of an emptied pool are kept. A local probe wraps the Vulkan descriptor pool and set calls, counts the sets still allocated, and reads the cgroup's `memory.current` and the process's memfd sizes every 10 s. cgroup `memory.current`, at the first probe at or after each presented frame: ``` frame 1 25 50 75 100 125 pools reset when empty 11.2 GiB 13.6 GiB 14.5 GiB 15.3 GiB 16.1 GiB 16.5 GiB sets still allocated 243 1,026 1,817 2,489 3,293 4,037 sets freed individually 11.2 GiB 11.7 GiB 11.7 GiB 11.7 GiB 11.7 GiB 11.7 GiB sets still allocated 244 271 273 273 273 332 ``` At 900 s: ``` frames sets still sets per frame memory.current lavapipe "allocation fd" allocated (gameplay) memfd pools reset when empty 141 4,444 +30.0 17,393 MiB 9,185 MiB sets freed individually 253 352 +0.4 12,021 MiB 4,476 MiB ``` - `VkDeviceMemory` was the same in both runs (8,036 MiB live at the end). The `allocation fd` memfd accounts for 4,709 MiB of the 5,372 MiB `memory.current` difference. I did not measure the size of each set. - Live descriptor pools of all kinds: 41 against 43 at the end (42 in most probes of the run with individual frees), so the extra sets sit in pools that are not reset, not in extra pools. - The set count includes sets held by `Recycle` in both runs. With individual frees it stayed between 271 and 352, so `Recycle`'s lists do not account for the growth. - Neither run reached the 22 GiB limit or used swap. The run without individual frees reached gameplay later (first frame at 544 s against 372 s), so it covered only 141 frames. Both runs started gameplay at 11.2 GiB, which is why the tables compare them at the same frame. In the four earlier runs, first frames ranged from 211 s to 322 s with no pattern by arm. I make no frame-rate claim. - No validation errors, terminations or crashes in either log. On a tree based on main `a08de68` (before #1201), four runs gave about 79 sets per frame without individual frees (peaks 22,027 and 22,141 MiB against the 22 GiB limit; one run used 5.8 GiB of swap) and a flat 11.8 GiB with them. I have not measured how much of the lower rate on current `main` comes from #1201. ### Why lavapipe In Mesa 26.2.4, `lvp_descriptor_set_create` (`src/gallium/frontends/lavapipe/lvp_descriptor_set.c`) allocates a block for each set in llvmpipe's `allocation fd` memfd. The block is freed only by `vkFreeDescriptorSets`, `vkResetDescriptorPool` or `vkDestroyDescriptorPool`. Freed blocks are reused, but the memfd does not shrink. So each released set in a pool that is not reset keeps its memory. Drivers that carve sets out of one buffer per pool should not use more memory for these sets. I did not measure RADV, NVIDIA or Windows. I did not find which sets keep the pools alive. Candidates: cached sets (the case in the debt entry) and, on current `main`, released draw sets held by `Recycle` (up to 4,096 per layout), which never reach `Free`. ### Why this is an issue and not a PR The local switch is the individually freed path that #1333 removed because RADV 26.2.2 can place a set past a `FREE_DESCRIPTOR_SET` pool's buffer. It is not a fix for `main`. Possible directions: 1. Allocate long-lived sets from a pool chain of their own, so that a held set never pins a pool of per-draw sets. 2. On lavapipe only (`VK_DRIVER_ID_MESA_LLVMPIPE`), create chain pools with `FREE_DESCRIPTOR_SET` and free each set. RADV keeps the reset-only pools that #1333 needs. The device already branches on the driver ID in `FragmentBarycentric.hpp` and `SubgroupClock.cpp`. 3. Use smaller chain pools, so that one held set pins fewer released sets. This creates more pools on every driver. I can measure any of these in the same scene. ### Environment - CachyOS, kernel 7.2.9, Intel Core i9-11900K (16 threads), 32 GB RAM. Each run was limited with `systemd-run --scope -p MemoryMax=22G -p MemorySwapMax=8G`. - lavapipe (Mesa 26.2.4, llvmpipe LLVM 23.1.1, 256 bits), `GALLIUM_OVERRIDE_CPU_CAPS=avx`. `-O2` build (`CMAKE_CXX_FLAGS=-O2`, no build type) with GCC 16.2.1. - Tree: main `31cbb55d7` (contains #1201) plus the first two commits of #6054 and local changes that let the title reach gameplay. Only the switch and the probe touch `DescriptorCache`. One local change adds a separate reset-only descriptor ring in `TextureDetiler` for a channel-extract compute pass; the probe counts its pools and sets in both runs. `ShaderResources.cpp` and `ShaderResources.hpp` are unchanged on main `5d9dcc42d`. Related: #1333 (pool recycling), #1201 (draw sets released through `Recycle`), #6567 (open: reuse a recycled descriptor set only for a table of its own size).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#6608
No description provided.