From: Jeff Layton <jlayton@kernel.org>
To: xiubli@redhat.com
Cc: idryomov@gmail.com, vshankar@redhat.com, ceph-devel@vger.kernel.org
Subject: Re: [PATCH 1/3] ceph: move to a dedicated slabcache for ceph_cap_snap
Date: Wed, 16 Feb 2022 09:58:19 -0500 [thread overview]
Message-ID: <28350c955afc4f07030ba465cb492605bf5889da.camel@kernel.org> (raw)
In-Reply-To: <20220215122316.7625-2-xiubli@redhat.com>
On Tue, 2022-02-15 at 20:23 +0800, xiubli@redhat.com wrote:
> From: Xiubo Li <xiubli@redhat.com>
>
> There could be huge number of capsnap queued in a short time, on
> x86_64 it's 248 bytes, which will be rounded up to 256 bytes by
> kzalloc. Move this to a dedicated slabcache to save 8 bytes for
> each.
>
> For the kmalloc-256 slab cache, the actual size will be 512 bytes:
> kmalloc-256 21797 74656 512 32 4 : tunables, etc
>
> For a dedicated slab cache the real size is 312 bytes:
> ceph_cap_snap 0 0 312 52 4 : tunables, etc
>
> So actually we can save 200 bytes for each.
>
I dropped everything but the top paragraph in the description above. On
non-debug kernels, kmalloc-256 is indeed 256 bytes. The inflation you're
seeing is almost certainly from sort of kernel debugging options.
> Signed-off-by: Xiubo Li <xiubli@redhat.com>
> ---
> fs/ceph/snap.c | 5 +++--
> fs/ceph/super.c | 7 +++++++
> fs/ceph/super.h | 2 +-
> include/linux/ceph/libceph.h | 1 +
> 4 files changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
> index b41e6724c591..c787775eaf2a 100644
> --- a/fs/ceph/snap.c
> +++ b/fs/ceph/snap.c
> @@ -482,7 +482,7 @@ static void ceph_queue_cap_snap(struct ceph_inode_info *ci)
> struct ceph_buffer *old_blob = NULL;
> int used, dirty;
>
> - capsnap = kzalloc(sizeof(*capsnap), GFP_NOFS);
> + capsnap = kmem_cache_alloc(ceph_cap_snap_cachep, GFP_NOFS);
> if (!capsnap) {
> pr_err("ENOMEM allocating ceph_cap_snap on %p\n", inode);
> return;
> @@ -603,7 +603,8 @@ static void ceph_queue_cap_snap(struct ceph_inode_info *ci)
> spin_unlock(&ci->i_ceph_lock);
>
> ceph_buffer_put(old_blob);
> - kfree(capsnap);
> + if (capsnap)
> + kmem_cache_free(ceph_cap_snap_cachep, capsnap);
> ceph_put_snap_context(old_snapc);
> }
>
> diff --git a/fs/ceph/super.c b/fs/ceph/super.c
> index bf79f369aec6..978463fa822c 100644
> --- a/fs/ceph/super.c
> +++ b/fs/ceph/super.c
> @@ -864,6 +864,7 @@ static void destroy_fs_client(struct ceph_fs_client *fsc)
> */
> 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_dentry_cachep;
> struct kmem_cache *ceph_file_cachep;
> @@ -892,6 +893,9 @@ static int __init init_caches(void)
> ceph_cap_cachep = KMEM_CACHE(ceph_cap, SLAB_MEM_SPREAD);
> if (!ceph_cap_cachep)
> goto bad_cap;
> + ceph_cap_snap_cachep = KMEM_CACHE(ceph_cap_snap, SLAB_MEM_SPREAD);
> + if (!ceph_cap_snap_cachep)
> + goto bad_cap_snap;
> ceph_cap_flush_cachep = KMEM_CACHE(ceph_cap_flush,
> SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD);
> if (!ceph_cap_flush_cachep)
> @@ -931,6 +935,8 @@ static int __init init_caches(void)
> bad_dentry:
> kmem_cache_destroy(ceph_cap_flush_cachep);
> bad_cap_flush:
> + kmem_cache_destroy(ceph_cap_snap_cachep);
> +bad_cap_snap:
> kmem_cache_destroy(ceph_cap_cachep);
> bad_cap:
> kmem_cache_destroy(ceph_inode_cachep);
> @@ -947,6 +953,7 @@ static void destroy_caches(void)
>
> kmem_cache_destroy(ceph_inode_cachep);
> kmem_cache_destroy(ceph_cap_cachep);
> + kmem_cache_destroy(ceph_cap_snap_cachep);
> kmem_cache_destroy(ceph_cap_flush_cachep);
> kmem_cache_destroy(ceph_dentry_cachep);
> kmem_cache_destroy(ceph_file_cachep);
> diff --git a/fs/ceph/super.h b/fs/ceph/super.h
> index c0718d5a8fb8..2d08104c8955 100644
> --- a/fs/ceph/super.h
> +++ b/fs/ceph/super.h
> @@ -231,7 +231,7 @@ static inline void ceph_put_cap_snap(struct ceph_cap_snap *capsnap)
> if (refcount_dec_and_test(&capsnap->nref)) {
> if (capsnap->xattr_blob)
> ceph_buffer_put(capsnap->xattr_blob);
> - kfree(capsnap);
> + kmem_cache_free(ceph_cap_snap_cachep, capsnap);
> }
> }
>
> diff --git a/include/linux/ceph/libceph.h b/include/linux/ceph/libceph.h
> index edf62eaa6285..00af2c98da75 100644
> --- a/include/linux/ceph/libceph.h
> +++ b/include/linux/ceph/libceph.h
> @@ -284,6 +284,7 @@ DEFINE_RB_LOOKUP_FUNC(name, type, keyfld, nodefld)
>
> 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_dentry_cachep;
> extern struct kmem_cache *ceph_file_cachep;
--
Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2022-02-16 14:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-15 12:23 [PATCH 0/3] ceph: fix cephfs rsync kworker high load issue xiubli
2022-02-15 12:23 ` [PATCH 1/3] ceph: move to a dedicated slabcache for ceph_cap_snap xiubli
2022-02-15 15:29 ` Jeff Layton
2022-02-16 14:58 ` Jeff Layton [this message]
2022-02-17 0:54 ` Xiubo Li
2022-02-18 18:11 ` Luís Henriques
2022-02-18 18:56 ` Jeff Layton
2022-02-15 12:23 ` [PATCH 2/3] ceph: move kzalloc under i_ceph_lock with GFP_ATOMIC flag xiubli
2022-02-15 16:57 ` Jeff Layton
2022-02-16 0:29 ` Xiubo Li
2022-02-15 12:23 ` [PATCH 3/3] ceph: do no update snapshot context when there is no new snapshot xiubli
2022-02-15 17:05 ` Jeff Layton
2022-02-16 0:30 ` Xiubo Li
2022-02-15 18:35 ` Jeff Layton
2022-02-16 0:36 ` Xiubo Li
2022-02-17 3:03 ` Yan, Zheng
2022-02-17 10:55 ` Jeff Layton
2022-02-17 15:28 ` Yan, Zheng
2022-02-18 1:46 ` Xiubo Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28350c955afc4f07030ba465cb492605bf5889da.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=vshankar@redhat.com \
--cc=xiubli@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox