sdcardfs: use kmem_cache pool for struct sdcardfs_file_info

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:
Park Ju Hyung 2019-07-12 00:41:27 +09:00 committed by spakkkk
parent 096c92b442
commit 4c2bbf266f
3 changed files with 15 additions and 3 deletions

View File

@ -23,6 +23,8 @@
#include <linux/backing-dev.h>
#endif
struct kmem_cache *kmem_file_info_pool;
static ssize_t sdcardfs_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
@ -256,7 +258,7 @@ static int sdcardfs_open(struct inode *inode, struct file *file)
}
file->private_data =
kzalloc(sizeof(struct sdcardfs_file_info), GFP_KERNEL);
kmem_cache_zalloc(kmem_file_info_pool, GFP_KERNEL);
if (!SDCARDFS_F(file)) {
err = -ENOMEM;
goto out_revert_cred;
@ -278,7 +280,7 @@ static int sdcardfs_open(struct inode *inode, struct file *file)
}
if (err)
kfree(SDCARDFS_F(file));
kmem_cache_free(kmem_file_info_pool, SDCARDFS_F(file));
else
sdcardfs_copy_and_fix_attrs(inode, sdcardfs_lower_inode(inode));
@ -314,7 +316,7 @@ static int sdcardfs_file_release(struct inode *inode, struct file *file)
fput(lower_file);
}
kfree(SDCARDFS_F(file));
kmem_cache_free(kmem_file_info_pool, SDCARDFS_F(file));
return 0;
}

View File

@ -476,6 +476,12 @@ static int __init init_sdcardfs_fs(void)
pr_info("Registering sdcardfs " SDCARDFS_VERSION "\n");
kmem_file_info_pool = KMEM_CACHE(sdcardfs_file_info, SLAB_HWCACHE_ALIGN);
if (!kmem_file_info_pool) {
err = -ENOMEM;
goto err;
}
err = sdcardfs_init_inode_cache();
if (err)
goto out;
@ -492,6 +498,7 @@ out:
sdcardfs_destroy_dentry_cache();
packagelist_exit();
}
err:
return err;
}
@ -501,6 +508,7 @@ static void __exit exit_sdcardfs_fs(void)
sdcardfs_destroy_dentry_cache();
packagelist_exit();
unregister_filesystem(&sdcardfs_fs_type);
kmem_cache_destroy(kmem_file_info_pool);
pr_info("Completed sdcardfs module unload\n");
}

View File

@ -655,4 +655,6 @@ static inline bool qstr_case_eq(const struct qstr *q1, const struct qstr *q2)
#define QSTR_LITERAL(string) QSTR_INIT(string, sizeof(string)-1)
extern struct kmem_cache *kmem_file_info_pool;
#endif /* not _SDCARDFS_H_ */