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:
parent
096c92b442
commit
4c2bbf266f
@ -23,6 +23,8 @@
|
|||||||
#include <linux/backing-dev.h>
|
#include <linux/backing-dev.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct kmem_cache *kmem_file_info_pool;
|
||||||
|
|
||||||
static ssize_t sdcardfs_read(struct file *file, char __user *buf,
|
static ssize_t sdcardfs_read(struct file *file, char __user *buf,
|
||||||
size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
@ -256,7 +258,7 @@ static int sdcardfs_open(struct inode *inode, struct file *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
file->private_data =
|
file->private_data =
|
||||||
kzalloc(sizeof(struct sdcardfs_file_info), GFP_KERNEL);
|
kmem_cache_zalloc(kmem_file_info_pool, GFP_KERNEL);
|
||||||
if (!SDCARDFS_F(file)) {
|
if (!SDCARDFS_F(file)) {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
goto out_revert_cred;
|
goto out_revert_cred;
|
||||||
@ -278,7 +280,7 @@ static int sdcardfs_open(struct inode *inode, struct file *file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
kfree(SDCARDFS_F(file));
|
kmem_cache_free(kmem_file_info_pool, SDCARDFS_F(file));
|
||||||
else
|
else
|
||||||
sdcardfs_copy_and_fix_attrs(inode, sdcardfs_lower_inode(inode));
|
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);
|
fput(lower_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
kfree(SDCARDFS_F(file));
|
kmem_cache_free(kmem_file_info_pool, SDCARDFS_F(file));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,6 +476,12 @@ static int __init init_sdcardfs_fs(void)
|
|||||||
|
|
||||||
pr_info("Registering sdcardfs " SDCARDFS_VERSION "\n");
|
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();
|
err = sdcardfs_init_inode_cache();
|
||||||
if (err)
|
if (err)
|
||||||
goto out;
|
goto out;
|
||||||
@ -492,6 +498,7 @@ out:
|
|||||||
sdcardfs_destroy_dentry_cache();
|
sdcardfs_destroy_dentry_cache();
|
||||||
packagelist_exit();
|
packagelist_exit();
|
||||||
}
|
}
|
||||||
|
err:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,6 +508,7 @@ static void __exit exit_sdcardfs_fs(void)
|
|||||||
sdcardfs_destroy_dentry_cache();
|
sdcardfs_destroy_dentry_cache();
|
||||||
packagelist_exit();
|
packagelist_exit();
|
||||||
unregister_filesystem(&sdcardfs_fs_type);
|
unregister_filesystem(&sdcardfs_fs_type);
|
||||||
|
kmem_cache_destroy(kmem_file_info_pool);
|
||||||
pr_info("Completed sdcardfs module unload\n");
|
pr_info("Completed sdcardfs module unload\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
#define QSTR_LITERAL(string) QSTR_INIT(string, sizeof(string)-1)
|
||||||
|
|
||||||
|
extern struct kmem_cache *kmem_file_info_pool;
|
||||||
|
|
||||||
#endif /* not _SDCARDFS_H_ */
|
#endif /* not _SDCARDFS_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user