Message ID | 20240205075144.431567-1-chentao@kylinos.cn |
---|---|
State | New |
Headers | show |
Series | jffs2: Simplify the allocation of slab caches | expand |
在 2024/2/5 15:51, Kunwu Chan 写道: > Use the new KMEM_CACHE() macro instead of direct kmem_cache_create > to simplify the creation of SLAB caches. > And change cache name from 'jffs2_tmp_dnode' to 'jffs2_tmp_dnode_info'. > > Signed-off-by: Kunwu Chan <chentao@kylinos.cn> > --- > fs/jffs2/malloc.c | 32 ++++++++------------------------ > 1 file changed, 8 insertions(+), 24 deletions(-) Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com> > > diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c > index ce1189793288..411de8b361b2 100644 > --- a/fs/jffs2/malloc.c > +++ b/fs/jffs2/malloc.c > @@ -33,27 +33,19 @@ static struct kmem_cache *xattr_ref_cache; > > int __init jffs2_create_slab_caches(void) > { > - full_dnode_slab = kmem_cache_create("jffs2_full_dnode", > - sizeof(struct jffs2_full_dnode), > - 0, 0, NULL); > + full_dnode_slab = KMEM_CACHE(jffs2_full_dnode, 0); > if (!full_dnode_slab) > goto err; > > - raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent", > - sizeof(struct jffs2_raw_dirent), > - 0, SLAB_HWCACHE_ALIGN, NULL); > + raw_dirent_slab = KMEM_CACHE(jffs2_raw_dirent, SLAB_HWCACHE_ALIGN); > if (!raw_dirent_slab) > goto err; > > - raw_inode_slab = kmem_cache_create("jffs2_raw_inode", > - sizeof(struct jffs2_raw_inode), > - 0, SLAB_HWCACHE_ALIGN, NULL); > + raw_inode_slab = KMEM_CACHE(jffs2_raw_inode, SLAB_HWCACHE_ALIGN); > if (!raw_inode_slab) > goto err; > > - tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode", > - sizeof(struct jffs2_tmp_dnode_info), > - 0, 0, NULL); > + tmp_dnode_info_slab = KMEM_CACHE(jffs2_tmp_dnode_info, 0); > if (!tmp_dnode_info_slab) > goto err; > > @@ -63,28 +55,20 @@ int __init jffs2_create_slab_caches(void) > if (!raw_node_ref_slab) > goto err; > > - node_frag_slab = kmem_cache_create("jffs2_node_frag", > - sizeof(struct jffs2_node_frag), > - 0, 0, NULL); > + node_frag_slab = KMEM_CACHE(jffs2_node_frag, 0); > if (!node_frag_slab) > goto err; > > - inode_cache_slab = kmem_cache_create("jffs2_inode_cache", > - sizeof(struct jffs2_inode_cache), > - 0, 0, NULL); > + inode_cache_slab = KMEM_CACHE(jffs2_inode_cache, 0); > if (!inode_cache_slab) > goto err; > > #ifdef CONFIG_JFFS2_FS_XATTR > - xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum", > - sizeof(struct jffs2_xattr_datum), > - 0, 0, NULL); > + xattr_datum_cache = KMEM_CACHE(jffs2_xattr_datum, 0); > if (!xattr_datum_cache) > goto err; > > - xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref", > - sizeof(struct jffs2_xattr_ref), > - 0, 0, NULL); > + xattr_ref_cache = KMEM_CACHE(jffs2_xattr_ref, 0); > if (!xattr_ref_cache) > goto err; > #endif >
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c index ce1189793288..411de8b361b2 100644 --- a/fs/jffs2/malloc.c +++ b/fs/jffs2/malloc.c @@ -33,27 +33,19 @@ static struct kmem_cache *xattr_ref_cache; int __init jffs2_create_slab_caches(void) { - full_dnode_slab = kmem_cache_create("jffs2_full_dnode", - sizeof(struct jffs2_full_dnode), - 0, 0, NULL); + full_dnode_slab = KMEM_CACHE(jffs2_full_dnode, 0); if (!full_dnode_slab) goto err; - raw_dirent_slab = kmem_cache_create("jffs2_raw_dirent", - sizeof(struct jffs2_raw_dirent), - 0, SLAB_HWCACHE_ALIGN, NULL); + raw_dirent_slab = KMEM_CACHE(jffs2_raw_dirent, SLAB_HWCACHE_ALIGN); if (!raw_dirent_slab) goto err; - raw_inode_slab = kmem_cache_create("jffs2_raw_inode", - sizeof(struct jffs2_raw_inode), - 0, SLAB_HWCACHE_ALIGN, NULL); + raw_inode_slab = KMEM_CACHE(jffs2_raw_inode, SLAB_HWCACHE_ALIGN); if (!raw_inode_slab) goto err; - tmp_dnode_info_slab = kmem_cache_create("jffs2_tmp_dnode", - sizeof(struct jffs2_tmp_dnode_info), - 0, 0, NULL); + tmp_dnode_info_slab = KMEM_CACHE(jffs2_tmp_dnode_info, 0); if (!tmp_dnode_info_slab) goto err; @@ -63,28 +55,20 @@ int __init jffs2_create_slab_caches(void) if (!raw_node_ref_slab) goto err; - node_frag_slab = kmem_cache_create("jffs2_node_frag", - sizeof(struct jffs2_node_frag), - 0, 0, NULL); + node_frag_slab = KMEM_CACHE(jffs2_node_frag, 0); if (!node_frag_slab) goto err; - inode_cache_slab = kmem_cache_create("jffs2_inode_cache", - sizeof(struct jffs2_inode_cache), - 0, 0, NULL); + inode_cache_slab = KMEM_CACHE(jffs2_inode_cache, 0); if (!inode_cache_slab) goto err; #ifdef CONFIG_JFFS2_FS_XATTR - xattr_datum_cache = kmem_cache_create("jffs2_xattr_datum", - sizeof(struct jffs2_xattr_datum), - 0, 0, NULL); + xattr_datum_cache = KMEM_CACHE(jffs2_xattr_datum, 0); if (!xattr_datum_cache) goto err; - xattr_ref_cache = kmem_cache_create("jffs2_xattr_ref", - sizeof(struct jffs2_xattr_ref), - 0, 0, NULL); + xattr_ref_cache = KMEM_CACHE(jffs2_xattr_ref, 0); if (!xattr_ref_cache) goto err; #endif
Use the new KMEM_CACHE() macro instead of direct kmem_cache_create to simplify the creation of SLAB caches. And change cache name from 'jffs2_tmp_dnode' to 'jffs2_tmp_dnode_info'. Signed-off-by: Kunwu Chan <chentao@kylinos.cn> --- fs/jffs2/malloc.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)