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 <qkrwngud825@gmail.com> Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
This commit is contained in:
parent
515f0624db
commit
774d7449d5
@ -27,12 +27,18 @@
|
||||
#include <uapi/linux/sync_file.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user