From 774d7449d50161164c61dd51e66d36e6a1cc23b7 Mon Sep 17 00:00:00 2001 From: Park Ju Hyung Date: Fri, 12 Jul 2019 01:16:18 +0900 Subject: [PATCH] dma_buf: use kmem_cache pool for struct sync_file These get allocated and freed millions of times on this kernel tree. Use a dedicated kmem_cache pool and avoid costly dynamic memory allocations. Signed-off-by: Park Ju Hyung Signed-off-by: Adam W. Willis --- drivers/dma-buf/sync_file.c | 12 +++++++++--- init/main.c | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index aa670ad2e9fb..d61be5b93a48 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -27,12 +27,18 @@ #include static const struct file_operations sync_file_fops; +static struct kmem_cache *kmem_sync_file_pool; + +void __init init_sync_kmem_pool(void) +{ + kmem_sync_file_pool = KMEM_CACHE(sync_file, SLAB_HWCACHE_ALIGN | SLAB_PANIC); +} static struct sync_file *sync_file_alloc(void) { struct sync_file *sync_file; - sync_file = kzalloc(sizeof(*sync_file), GFP_KERNEL); + sync_file = kmem_cache_zalloc(kmem_sync_file_pool, GFP_KERNEL); if (!sync_file) return NULL; @@ -48,7 +54,7 @@ static struct sync_file *sync_file_alloc(void) return sync_file; err: - kfree(sync_file); + kmem_cache_free(kmem_sync_file_pool, sync_file); return NULL; } @@ -277,7 +283,7 @@ static int sync_file_release(struct inode *inode, struct file *file) if (test_bit(POLL_ENABLED, &sync_file->flags)) dma_fence_remove_callback(sync_file->fence, &sync_file->cb); dma_fence_put(sync_file->fence); - kfree(sync_file); + kmem_cache_free(kmem_sync_file_pool, sync_file); return 0; } diff --git a/init/main.c b/init/main.c index c140b7b0f497..c79aca9ab31f 100644 --- a/init/main.c +++ b/init/main.c @@ -554,6 +554,7 @@ static void __init mm_init(void) pti_init(); } +void __init init_sync_kmem_pool(void); void __init init_dma_buf_kmem_pool(void); asmlinkage __visible void __init start_kernel(void) { @@ -753,6 +754,7 @@ asmlinkage __visible void __init start_kernel(void) cgroup_init(); taskstats_init_early(); delayacct_init(); + init_sync_kmem_pool(); init_dma_buf_kmem_pool(); check_bugs();