From 2c05488be169a4bb0f8c73744ed7d07237d085e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 19 Mar 2025 12:47:49 -0700 Subject: [PATCH] anv: Align size of bos larger than 1MB to 64k to enable 64k pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BOs larger than 1MB don't go memory pool due the size but applications tend to use a lot of VkMemory with size larger than 1MB so to reduce the number of pages and improve performance here I'm aligning the size of BOs larger than 1MB to 64kb, this allows 64kb pages to be used at least on Xe KMD. This bring substantial perfomance benefit in exchange of a small memory waste. Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: --- src/intel/vulkan/anv_allocator.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index ed0d9eccd77..5397ea7245d 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -489,6 +489,15 @@ anv_device_has_perf_improvement_with_2mb_pages(struct anv_device *device) return device->info->verx10 >= 110; } +static bool +anv_device_has_perf_improvement_with_64k_pages(struct anv_device *device) +{ + if (device->info->has_local_mem || device->info->verx10 < 110) + return false; + + return device->info->kmd_type == INTEL_KMD_TYPE_XE; +} + /** Grows and re-centers the block pool. * * We grow the block pool in one or both directions in such a way that the @@ -1672,6 +1681,14 @@ anv_device_alloc_bo(struct anv_device *device, size = align64(size, 4096); } + /* bos larger than 1MB can't be allocated with slab but to reduce pages we + * could align size to 64k pages to gain performance with minimum memory + * waste. + */ + if ((size > (1 * 1024 * 1024)) && + anv_device_has_perf_improvement_with_64k_pages(device)) + size = align64(size, 64 * 1024); + const struct intel_memory_class_instance *regions[2]; uint32_t nregions = 0;