From a0a600ca5fab4dee6df3f36910b138f7656467e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 22 Apr 2025 12:09:58 -0700 Subject: [PATCH] anv: Skip anv_bo_pool if memory pool is enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The whole purpose of anv_bo_pool is to reduce the number of gem_create/destroy calls in command buffers that is something with a short life span. But slab_bo/memory pool does the same with even other benefits like doing 2MB allocations to enable THP. So here skipping the meat of anv_bo_pool_free() to directly return the bo to slab_bo. This change is also necessary because the way anv_bo_pool stores freed buffers it requires that all bos has a unique gem handle, what not true of buffer allocated by anv_slab. Reviewed-by: Lionel Landwerlin Suggested-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_allocator.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index e7d3005af3e..df853ca81ce 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -1294,6 +1294,19 @@ anv_bo_pool_free(struct anv_bo_pool *pool, struct anv_bo *bo) { VG(VALGRIND_MEMPOOL_FREE(pool, bo->map)); + /* When a BO is part of a slab, don't put it on the free list. First + * it doesn't have a GEM handle that we could use in managing the free + * list, second the BO is going to return to the slab and will not + * necessarily get freed immediately which is what the bo_pool is also + * trying to achieve. + */ + if (anv_bo_get_real(bo) != bo) { + VG(VALGRIND_MALLOCLIKE_BLOCK(bo->map, bo->size, 0, 1)); + anv_device_release_bo(pool->device, bo); + + return; + } + assert(util_is_power_of_two_or_zero(bo->size)); const unsigned size_log2 = util_logbase2_ceil(bo->size); const unsigned bucket = size_log2 - 12;