[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d79d3ef43b3a61be99e53a77fa9eb19af7fc550f.camel@kernel.org>
Date: Mon, 24 Jul 2023 08:17:52 -0400
From: Jeff Layton <jlayton@...nel.org>
To: Qi Zheng <zhengqi.arch@...edance.com>, akpm@...ux-foundation.org,
david@...morbit.com, tkhai@...ru, vbabka@...e.cz,
roman.gushchin@...ux.dev, djwong@...nel.org, brauner@...nel.org,
paulmck@...nel.org, tytso@....edu, steven.price@....com,
cel@...nel.org, senozhatsky@...omium.org, yujie.liu@...el.com,
gregkh@...uxfoundation.org, muchun.song@...ux.dev
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org, x86@...nel.org,
kvm@...r.kernel.org, xen-devel@...ts.xenproject.org,
linux-erofs@...ts.ozlabs.org,
linux-f2fs-devel@...ts.sourceforge.net, cluster-devel@...hat.com,
linux-nfs@...r.kernel.org, linux-mtd@...ts.infradead.org,
rcu@...r.kernel.org, netdev@...r.kernel.org,
dri-devel@...ts.freedesktop.org, linux-arm-msm@...r.kernel.org,
dm-devel@...hat.com, linux-raid@...r.kernel.org,
linux-bcache@...r.kernel.org,
virtualization@...ts.linux-foundation.org,
linux-fsdevel@...r.kernel.org, linux-ext4@...r.kernel.org,
linux-xfs@...r.kernel.org, linux-btrfs@...r.kernel.org,
Chuck Lever <chuck.lever@...cle.com>
Subject: Re: [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply
shrinker
On Mon, 2023-07-24 at 17:43 +0800, Qi Zheng wrote:
> In preparation for implementing lockless slab shrink, use new APIs to
> dynamically allocate the nfsd-reply shrinker, so that it can be freed
> asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU
> read-side critical section when releasing the struct nfsd_net.
>
> Acked-by: Chuck Lever <chuck.lever@...cle.com>
> Signed-off-by: Qi Zheng <zhengqi.arch@...edance.com>
> ---
> fs/nfsd/netns.h | 2 +-
> fs/nfsd/nfscache.c | 31 ++++++++++++++++---------------
> 2 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
> index f669444d5336..ab303a8b77d5 100644
> --- a/fs/nfsd/netns.h
> +++ b/fs/nfsd/netns.h
> @@ -177,7 +177,7 @@ struct nfsd_net {
> /* size of cache when we saw the longest hash chain */
> unsigned int longest_chain_cachesize;
>
> - struct shrinker nfsd_reply_cache_shrinker;
> + struct shrinker *nfsd_reply_cache_shrinker;
>
> /* tracking server-to-server copy mounts */
> spinlock_t nfsd_ssc_lock;
> diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
> index 6eb3d7bdfaf3..9f0ab65e4125 100644
> --- a/fs/nfsd/nfscache.c
> +++ b/fs/nfsd/nfscache.c
> @@ -200,26 +200,29 @@ int nfsd_reply_cache_init(struct nfsd_net *nn)
> {
> unsigned int hashsize;
> unsigned int i;
> - int status = 0;
>
> nn->max_drc_entries = nfsd_cache_size_limit();
> atomic_set(&nn->num_drc_entries, 0);
> hashsize = nfsd_hashsize(nn->max_drc_entries);
> nn->maskbits = ilog2(hashsize);
>
> - nn->nfsd_reply_cache_shrinker.scan_objects = nfsd_reply_cache_scan;
> - nn->nfsd_reply_cache_shrinker.count_objects = nfsd_reply_cache_count;
> - nn->nfsd_reply_cache_shrinker.seeks = 1;
> - status = register_shrinker(&nn->nfsd_reply_cache_shrinker,
> - "nfsd-reply:%s", nn->nfsd_name);
> - if (status)
> - return status;
> -
> nn->drc_hashtbl = kvzalloc(array_size(hashsize,
> sizeof(*nn->drc_hashtbl)), GFP_KERNEL);
> if (!nn->drc_hashtbl)
> + return -ENOMEM;
> +
> + nn->nfsd_reply_cache_shrinker = shrinker_alloc(0, "nfsd-reply:%s",
> + nn->nfsd_name);
> + if (!nn->nfsd_reply_cache_shrinker)
> goto out_shrinker;
>
> + nn->nfsd_reply_cache_shrinker->scan_objects = nfsd_reply_cache_scan;
> + nn->nfsd_reply_cache_shrinker->count_objects = nfsd_reply_cache_count;
> + nn->nfsd_reply_cache_shrinker->seeks = 1;
> + nn->nfsd_reply_cache_shrinker->private_data = nn;
> +
> + shrinker_register(nn->nfsd_reply_cache_shrinker);
> +
> for (i = 0; i < hashsize; i++) {
> INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head);
> spin_lock_init(&nn->drc_hashtbl[i].cache_lock);
> @@ -228,7 +231,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn)
>
> return 0;
> out_shrinker:
> - unregister_shrinker(&nn->nfsd_reply_cache_shrinker);
> + kvfree(nn->drc_hashtbl);
> printk(KERN_ERR "nfsd: failed to allocate reply cache\n");
> return -ENOMEM;
> }
> @@ -238,7 +241,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn)
> struct nfsd_cacherep *rp;
> unsigned int i;
>
> - unregister_shrinker(&nn->nfsd_reply_cache_shrinker);
> + shrinker_unregister(nn->nfsd_reply_cache_shrinker);
>
> for (i = 0; i < nn->drc_hashsize; i++) {
> struct list_head *head = &nn->drc_hashtbl[i].lru_head;
> @@ -322,8 +325,7 @@ nfsd_prune_bucket_locked(struct nfsd_net *nn, struct nfsd_drc_bucket *b,
> static unsigned long
> nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc)
> {
> - struct nfsd_net *nn = container_of(shrink,
> - struct nfsd_net, nfsd_reply_cache_shrinker);
> + struct nfsd_net *nn = shrink->private_data;
>
> return atomic_read(&nn->num_drc_entries);
> }
> @@ -342,8 +344,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc)
> static unsigned long
> nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc)
> {
> - struct nfsd_net *nn = container_of(shrink,
> - struct nfsd_net, nfsd_reply_cache_shrinker);
> + struct nfsd_net *nn = shrink->private_data;
> unsigned long freed = 0;
> LIST_HEAD(dispose);
> unsigned int i;
Acked-by: Jeff Layton <jlayton@...nel.org>
Powered by blists - more mailing lists