[PATCH v2 16/18] fs/ceph/snap: add a kmem_cache for struct ceph_snap_realm

Max Kellermann <[email protected]>
Newsgroups org.kernel.vger.ceph-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
There will be lots of ceph_snap_realm instances, and having a separate
kmem_cache seems worthwile.

Signed-off-by: Max Kellermann <[email protected]>
---
 fs/ceph/snap.c               | 4 ++--
 fs/ceph/super.c              | 9 +++++++++
 include/linux/ceph/libceph.h | 1 +
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index f064b5ad3bf4..12f80df4b651 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -118,7 +118,7 @@ static struct ceph_snap_realm *ceph_create_snap_realm(
 
 	lockdep_assert_held_write(&mdsc->snap_rwsem);
 
-	realm = kzalloc_obj(*realm, GFP_NOFS);
+	realm = kmem_cache_zalloc(ceph_snap_realm_cachep, GFP_NOFS);
 	if (!realm)
 		return ERR_PTR(-ENOMEM);
 
@@ -205,7 +205,7 @@ static void __destroy_snap_realm(struct ceph_mds_client *mdsc,
 	kfree(realm->prior_parent_snaps);
 	kfree(realm->snaps);
 	ceph_put_snap_context(realm->cached_context);
-	kfree(realm);
+	kmem_cache_free(ceph_snap_realm_cachep, realm);
 }
 
 /*
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index c05fbd4237f8..73c316c23315 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -910,6 +910,7 @@ struct kmem_cache *ceph_inode_cachep;
 struct kmem_cache *ceph_cap_cachep;
 struct kmem_cache *ceph_cap_snap_cachep;
 struct kmem_cache *ceph_cap_flush_cachep;
+struct kmem_cache *ceph_snap_realm_cachep;
 struct kmem_cache *ceph_dentry_cachep;
 struct kmem_cache *ceph_file_cachep;
 struct kmem_cache *ceph_dir_file_cachep;
@@ -945,6 +946,11 @@ static int __init init_caches(void)
 	if (!ceph_cap_flush_cachep)
 		goto bad_cap_flush;
 
+	ceph_snap_realm_cachep = KMEM_CACHE(ceph_snap_realm,
+					    SLAB_RECLAIM_ACCOUNT);
+	if (!ceph_snap_realm_cachep)
+		goto bad_snap_realm;
+
 	ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info,
 					SLAB_RECLAIM_ACCOUNT);
 	if (!ceph_dentry_cachep)
@@ -984,6 +990,8 @@ static int __init init_caches(void)
 bad_file:
 	kmem_cache_destroy(ceph_dentry_cachep);
 bad_dentry:
+	kmem_cache_destroy(ceph_snap_realm_cachep);
+bad_snap_realm:
 	kmem_cache_destroy(ceph_cap_flush_cachep);
 bad_cap_flush:
 	kmem_cache_destroy(ceph_cap_snap_cachep);
@@ -1006,6 +1014,7 @@ static void destroy_caches(void)
 	kmem_cache_destroy(ceph_cap_cachep);
 	kmem_cache_destroy(ceph_cap_snap_cachep);
 	kmem_cache_destroy(ceph_cap_flush_cachep);
+	kmem_cache_destroy(ceph_snap_realm_cachep);
 	kmem_cache_destroy(ceph_dentry_cachep);
 	kmem_cache_destroy(ceph_file_cachep);
 	kmem_cache_destroy(ceph_dir_file_cachep);
diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
index 63e0e2aa1ce9..379629cafbce 100644
--- a/include/linux/ceph/libceph.h
+++ b/include/linux/ceph/libceph.h
@@ -276,6 +276,7 @@ extern struct kmem_cache *ceph_inode_cachep;
 extern struct kmem_cache *ceph_cap_cachep;
 extern struct kmem_cache *ceph_cap_snap_cachep;
 extern struct kmem_cache *ceph_cap_flush_cachep;
+extern struct kmem_cache *ceph_snap_realm_cachep;
 extern struct kmem_cache *ceph_dentry_cachep;
 extern struct kmem_cache *ceph_file_cachep;
 extern struct kmem_cache *ceph_dir_file_cachep;
-- 
2.47.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.