summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2015-09-15 16:54:56 -0700
committerJason Ekstrand <[email protected]>2015-09-17 17:44:20 -0700
commit8c6bc1e85d4b2eebf90a5ac862d650c9973bb126 (patch)
tree64df207f5fd7b4cfd047c7628d11465d6100fcc1
parent74bf7aa07c0e87cafb1a9fb085a2fe99a548c8de (diff)
anv/allocator: Create 2GB memfd up-front for the block pool
-rw-r--r--src/vulkan/anv_allocator.c21
-rw-r--r--src/vulkan/anv_private.h3
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)
{