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: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
committed by
Pranav Vashi
parent
5570aaa915
commit
1bdea19fde
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -475,6 +475,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;
|
||||
@@ -491,6 +497,7 @@ out:
|
||||
sdcardfs_destroy_dentry_cache();
|
||||
packagelist_exit();
|
||||
}
|
||||
err:
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -500,6 +507,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");
|
||||
}
|
||||
|
||||
|
||||
@@ -654,4 +654,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_ */
|
||||
|
||||
Reference in New Issue
Block a user