From ea761a40d596edca419132f6625126616b475c65 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 17 Nov 2021 16:45:20 -0500 Subject: [PATCH] zink: use pb_slab_alloc_reclaimed(reclaim_all) for BAR heap sometimes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this forces a full slab reclaim any time the device is known to have a too-small BAR in order to keep memory usage at a minimum when it might otherwise balloon out and crash us Reviewed-by: Marek Olšák Part-of: --- src/gallium/drivers/zink/zink_bo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/zink/zink_bo.c b/src/gallium/drivers/zink/zink_bo.c index 083d6d9fa50..6623e99c82e 100644 --- a/src/gallium/drivers/zink/zink_bo.c +++ b/src/gallium/drivers/zink/zink_bo.c @@ -579,12 +579,20 @@ zink_bo_create(struct zink_screen *screen, uint64_t size, unsigned alignment, en } struct pb_slabs *slabs = get_slabs(screen, alloc_size, flags); - entry = pb_slab_alloc(slabs, alloc_size, heap); + bool reclaim_all = false; + if (heap == ZINK_HEAP_DEVICE_LOCAL_VISIBLE && !screen->resizable_bar) { + unsigned low_bound = 128 * 1024 * 1024; //128MB is a very small BAR + if (screen->info.driver_props.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY) + low_bound *= 2; //nvidia has fat textures or something + unsigned heapidx = screen->info.mem_props.memoryTypes[screen->heap_map[heap]].heapIndex; + reclaim_all = screen->info.mem_props.memoryHeaps[heapidx].size <= low_bound; + } + entry = pb_slab_alloc_reclaimed(slabs, alloc_size, heap, reclaim_all); if (!entry) { /* Clean up buffer managers and try again. */ clean_up_buffer_managers(screen); - entry = pb_slab_alloc(slabs, alloc_size, heap); + entry = pb_slab_alloc_reclaimed(slabs, alloc_size, heap, true); } if (!entry) return NULL;