>From e7f68291aada1535016c767a4f5a5fcfb19a1de6 Mon Sep 17 00:00:00 2001 From: KB Date: Wed, 25 May 2016 22:41:22 +0200 Subject: [PATCH 6/7] static cachep Signed-off-by: KB --- fs/freevxfs/vxfs_extern.h | 4 +++- fs/freevxfs/vxfs_inode.c | 24 +++++++++++++++++++++++- fs/freevxfs/vxfs_super.c | 26 ++++++++++---------------- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/fs/freevxfs/vxfs_extern.h b/fs/freevxfs/vxfs_extern.h index 4d8298b..cc43fd0 100644 --- a/fs/freevxfs/vxfs_extern.h +++ b/fs/freevxfs/vxfs_extern.h @@ -55,7 +55,6 @@ extern const struct inode_operations vxfs_immed_symlink_iops; /* vxfs_inode.c */ extern const struct address_space_operations vxfs_immed_aops; -extern struct kmem_cache *vxfs_inode_cachep; extern void vxfs_dumpi(struct vxfs_inode_info *, ino_t); extern struct inode * vxfs_get_fake_inode(struct super_block *, struct vxfs_inode_info *); @@ -66,6 +65,9 @@ extern struct inode * vxfs_iget(struct super_block *, ino_t); extern void vxfs_evict_inode(struct inode *); extern void vxfs_inode_info_free(struct vxfs_inode_info *vip); extern void vxfs_destroy_inode(struct inode *ip); +extern int vxfs_ii_cache_init(void); +extern void vxfs_ii_cache_destroy(void); + /* vxfs_lookup.c */ extern const struct inode_operations vxfs_dir_inode_ops; diff --git a/fs/freevxfs/vxfs_inode.c b/fs/freevxfs/vxfs_inode.c index 9b45ad7..73ac417 100644 --- a/fs/freevxfs/vxfs_inode.c +++ b/fs/freevxfs/vxfs_inode.c @@ -41,7 +41,7 @@ #include "vxfs_extern.h" -struct kmem_cache *vxfs_inode_cachep; +static struct kmem_cache *vxfs_inode_cachep; #ifdef DIAGNOSTIC @@ -428,3 +428,25 @@ void vxfs_inode_info_free(struct vxfs_inode_info *vip) { kmem_cache_free(vxfs_inode_cachep, vip); } + + +int vxfs_ii_cache_init(void) +{ + vxfs_inode_cachep = kmem_cache_create("vxfs_inode", + sizeof(struct vxfs_inode_info), 0, + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); + + return vxfs_inode_cachep ? 0 : -ENOMEM; +} + + +void vxfs_ii_cache_destroy(void) +{ + /* + * Make sure all delayed rcu free inodes are flushed before we + * destroy cache. + */ + rcu_barrier(); + kmem_cache_destroy(vxfs_inode_cachep); +} + diff --git a/fs/freevxfs/vxfs_super.c b/fs/freevxfs/vxfs_super.c index 11a535a..7579500 100644 --- a/fs/freevxfs/vxfs_super.c +++ b/fs/freevxfs/vxfs_super.c @@ -306,29 +306,23 @@ MODULE_ALIAS("vxfs"); static int __init vxfs_init(void) { - int rv; + int rc = vxfs_ii_cache_init(); - vxfs_inode_cachep = kmem_cache_create("vxfs_inode", - sizeof(struct vxfs_inode_info), 0, - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD, NULL); - if (!vxfs_inode_cachep) - return -ENOMEM; - rv = register_filesystem(&vxfs_fs_type); - if (rv < 0) - kmem_cache_destroy(vxfs_inode_cachep); - return rv; + if (!rc) { + rc = register_filesystem(&vxfs_fs_type); + if (rc < 0) + vxfs_ii_cache_destroy(); + } + printk(KERN_DEBUG "%s: **** %s %s rc %d\n", __func__, __DATE__, __TIME__, rc); + + return rc; } static void __exit vxfs_cleanup(void) { unregister_filesystem(&vxfs_fs_type); - /* - * Make sure all delayed rcu free inodes are flushed before we - * destroy cache. - */ - rcu_barrier(); - kmem_cache_destroy(vxfs_inode_cachep); + vxfs_ii_cache_destroy(); } module_init(vxfs_init); -- 1.7.3.4