From 8c6bc1e85d4b2eebf90a5ac862d650c9973bb126 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 15 Sep 2015 16:54:56 -0700 Subject: [PATCH] anv/allocator: Create 2GB memfd up-front for the block pool --- src/vulkan/anv_allocator.c | 21 ++++++++++++--------- src/vulkan/anv_private.h | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/vulkan/anv_allocator.c b/src/vulkan/anv_allocator.c index 201cc931cbb..1b116a3a49a 100644 --- a/src/vulkan/anv_allocator.c +++ b/src/vulkan/anv_allocator.c @@ -254,6 +254,18 @@ anv_block_pool_init(struct anv_block_pool *pool, pool->bo.offset = 0; pool->block_size = block_size; pool->free_list = ANV_FREE_LIST_EMPTY; + + pool->fd = memfd_create("block pool", MFD_CLOEXEC); + if (pool->fd == -1) + return; + + /* Just make it 2GB up-front. The Linux kernel won't actually back it + * with pages until we either map and fault on one of them or we use + * userptr and send a chunk of it off to the GPU. + */ + if (ftruncate(pool->fd, BLOCK_POOL_MEMFD_SIZE) == -1) + return; + anv_vector_init(&pool->mmap_cleanups, round_to_power_of_two(sizeof(struct anv_mmap_cleanup)), 128); @@ -300,15 +312,6 @@ anv_block_pool_grow(struct anv_block_pool *pool, uint32_t old_size) goto fail; *cleanup = ANV_MMAP_CLEANUP_INIT; - if (old_size == 0) - pool->fd = memfd_create("block pool", MFD_CLOEXEC); - - if (pool->fd == -1) - goto fail; - - if (ftruncate(pool->fd, size) == -1) - goto fail; - /* First try to see if mremap can grow the map in place. */ map = MAP_FAILED; if (old_size > 0) diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index 5e4fa35e208..5931e0af98d 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -268,6 +268,9 @@ struct anv_block_pool { struct anv_block_state state; }; +/* Block pools are backed by a fixed-size 2GB memfd */ +#define BLOCK_POOL_MEMFD_SIZE (1ull << 32) + static inline uint32_t anv_block_pool_size(struct anv_block_pool *pool) { -- 2.30.2