Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eccb867f authored by Park Ju Hyung's avatar Park Ju Hyung Committed by KakatkarAkshay
Browse files

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: default avatarPark Ju Hyung <qkrwngud825@gmail.com>
Signed-off-by: default avatarAdam W. Willis <return.of.octobot@gmail.com>
Signed-off-by: default avatarLibXZR <xzr467706992@163.com>
parent 9c52a628
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -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;
}

@@ -276,7 +282,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;
}
+2 −0
Original line number Diff line number Diff line
@@ -552,6 +552,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)
{
@@ -755,6 +756,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();