From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Layton Date: Mon, 24 Jul 2023 08:17:52 -0400 Subject: [Cluster-devel] [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> Message-ID: List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 > Signed-off-by: Qi Zheng > --- > 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F2638C0015E for ; Tue, 25 Jul 2023 06:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690267411; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=O6V9Yr9vx1M0oUVyKSvmXT6DbWSOGlg9o6S1/ERsrTE=; b=eqcV0guGUnX73u+BZCwJ2/hCfRmFOcCcfflIIaIrAwdxzSTRJwx4UPBhxuz9MryRmwS0g8 SZDvt9DQ7EOW2c6Q2iRnFIZ0vFjs6yIfWhKgd1/7N/lwqoeLFE4GxhEdsqSOAGNn120kh/ XG8SfJ48OH9mDmAmAlG+D+sxoozgHRg= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-626-sIMPi1JfOY64iZLQ8R2yZg-1; Tue, 25 Jul 2023 02:43:27 -0400 X-MC-Unique: sIMPi1JfOY64iZLQ8R2yZg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A81A43C11C8C; Tue, 25 Jul 2023 06:42:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97283F66A0; Tue, 25 Jul 2023 06:42:57 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8CBD71946A50; Tue, 25 Jul 2023 06:42:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B07681946588 for ; Mon, 24 Jul 2023 12:24:59 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 77EC81415115; Mon, 24 Jul 2023 12:24:59 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F493140E952 for ; Mon, 24 Jul 2023 12:24:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 41289185A78F for ; Mon, 24 Jul 2023 12:24:59 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-620-uWt2weEzPVC2e11KwuFx3Q-1; Mon, 24 Jul 2023 08:24:57 -0400 X-MC-Unique: uWt2weEzPVC2e11KwuFx3Q-1 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 397746113E; Mon, 24 Jul 2023 12:17:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7639DC433C7; Mon, 24 Jul 2023 12:17:53 +0000 (UTC) Message-ID: From: Jeff Layton To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Date: Mon, 24 Jul 2023 08:17:52 -0400 In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mailman-Approved-At: Tue, 25 Jul 2023 06:42:42 +0000 Subject: Re: [dm-devel] [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, x86@kernel.org, cluster-devel@redhat.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, linux-arm-msm@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Chuck Lever , linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org Errors-To: dm-devel-bounces@redhat.com Sender: "dm-devel" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 > Signed-off-by: Qi Zheng > --- > 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 -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0041C0015E for ; Mon, 24 Jul 2023 12:18:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230488AbjGXMSk (ORCPT ); Mon, 24 Jul 2023 08:18:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjGXMSh (ORCPT ); Mon, 24 Jul 2023 08:18:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 950AB1BCB; Mon, 24 Jul 2023 05:18:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3973C6113D; Mon, 24 Jul 2023 12:17:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7639DC433C7; Mon, 24 Jul 2023 12:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690201076; bh=SgqvEHTSsoLx88OM4JQmZh6whPE6BGZ/uEOL9QxuZhc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HeauOjdE48WDStWMcmbZe0QJCu1PZbrw2jnOfPPp5Y0n0Q1TK60SYgINluh0tVUHu HMa9pGy9YrA2Xid5ZQCkD41aahatrfHq9vVHLjbuzLzQBP/bIUW5s/kQBvStLkPbEr 52wVvvm4TuW1EIIyQppWxFYEv7SoUq895jOWh1zWA+5Bhuu0CwPKUfnKQ6aPaR+FNu w4bgci3LfqcgT2vztkyr4DzF2/4Hyf1LGlp6Z0shJe1d8GJLzPQbDhc3dh09sCIq3l N9zzfqaN5HsWy8Vmt4P1E7EQFqQrkFrxcJ7/1W6yEYc3GiEERam+zZN0XSQm/ELIIc 3urjqaifuO8iw== Message-ID: Subject: Re: [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker From: Jeff Layton To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Chuck Lever Date: Mon, 24 Jul 2023 08:17:52 -0400 In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bcache@vger.kernel.org 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. >=20 > Acked-by: Chuck Lever > Signed-off-by: Qi Zheng > --- > fs/nfsd/netns.h | 2 +- > fs/nfsd/nfscache.c | 31 ++++++++++++++++--------------- > 2 files changed, 17 insertions(+), 16 deletions(-) >=20 > 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; > =20 > - struct shrinker nfsd_reply_cache_shrinker; > + struct shrinker *nfsd_reply_cache_shrinker; > =20 > /* 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 =3D 0; > =20 > nn->max_drc_entries =3D nfsd_cache_size_limit(); > atomic_set(&nn->num_drc_entries, 0); > hashsize =3D nfsd_hashsize(nn->max_drc_entries); > nn->maskbits =3D ilog2(hashsize); > =20 > - nn->nfsd_reply_cache_shrinker.scan_objects =3D nfsd_reply_cache_scan; > - nn->nfsd_reply_cache_shrinker.count_objects =3D nfsd_reply_cache_count; > - nn->nfsd_reply_cache_shrinker.seeks =3D 1; > - status =3D register_shrinker(&nn->nfsd_reply_cache_shrinker, > - "nfsd-reply:%s", nn->nfsd_name); > - if (status) > - return status; > - > nn->drc_hashtbl =3D kvzalloc(array_size(hashsize, > sizeof(*nn->drc_hashtbl)), GFP_KERNEL); > if (!nn->drc_hashtbl) > + return -ENOMEM; > + > + nn->nfsd_reply_cache_shrinker =3D shrinker_alloc(0, "nfsd-reply:%s", > + nn->nfsd_name); > + if (!nn->nfsd_reply_cache_shrinker) > goto out_shrinker; > =20 > + nn->nfsd_reply_cache_shrinker->scan_objects =3D nfsd_reply_cache_scan; > + nn->nfsd_reply_cache_shrinker->count_objects =3D nfsd_reply_cache_count= ; > + nn->nfsd_reply_cache_shrinker->seeks =3D 1; > + nn->nfsd_reply_cache_shrinker->private_data =3D nn; > + > + shrinker_register(nn->nfsd_reply_cache_shrinker); > + > for (i =3D 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) > =20 > 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; > =20 > - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); > + shrinker_unregister(nn->nfsd_reply_cache_shrinker); > =20 > for (i =3D 0; i < nn->drc_hashsize; i++) { > struct list_head *head =3D &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 *s= c) > { > - struct nfsd_net *nn =3D container_of(shrink, > - struct nfsd_net, nfsd_reply_cache_shrinker); > + struct nfsd_net *nn =3D shrink->private_data; > =20 > return atomic_read(&nn->num_drc_entries); > } > @@ -342,8 +344,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struc= t shrink_control *sc) > static unsigned long > nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc= ) > { > - struct nfsd_net *nn =3D container_of(shrink, > - struct nfsd_net, nfsd_reply_cache_shrinker); > + struct nfsd_net *nn =3D shrink->private_data; > unsigned long freed =3D 0; > LIST_HEAD(dispose); > unsigned int i; Acked-by: Jeff Layton From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62AFFC001DE for ; Mon, 24 Jul 2023 12:18:09 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=HeauOjdE; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4R8fM40BPbz301r for ; Mon, 24 Jul 2023 22:18:08 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=HeauOjdE; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2604:1380:4641:c500::1; helo=dfw.source.kernel.org; envelope-from=jlayton@kernel.org; receiver=lists.ozlabs.org) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4R8fLx4bW3z2yVR for ; Mon, 24 Jul 2023 22:18:01 +1000 (AEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 397746113E; Mon, 24 Jul 2023 12:17:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7639DC433C7; Mon, 24 Jul 2023 12:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690201076; bh=SgqvEHTSsoLx88OM4JQmZh6whPE6BGZ/uEOL9QxuZhc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HeauOjdE48WDStWMcmbZe0QJCu1PZbrw2jnOfPPp5Y0n0Q1TK60SYgINluh0tVUHu HMa9pGy9YrA2Xid5ZQCkD41aahatrfHq9vVHLjbuzLzQBP/bIUW5s/kQBvStLkPbEr 52wVvvm4TuW1EIIyQppWxFYEv7SoUq895jOWh1zWA+5Bhuu0CwPKUfnKQ6aPaR+FNu w4bgci3LfqcgT2vztkyr4DzF2/4Hyf1LGlp6Z0shJe1d8GJLzPQbDhc3dh09sCIq3l N9zzfqaN5HsWy8Vmt4P1E7EQFqQrkFrxcJ7/1W6yEYc3GiEERam+zZN0XSQm/ELIIc 3urjqaifuO8iw== Message-ID: Subject: Re: [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker From: Jeff Layton To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Date: Mon, 24 Jul 2023 08:17:52 -0400 In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, x86@kernel.org, cluster-devel@redhat.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, linux-arm-msm@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Chuck Lever , linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 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. >=20 > Acked-by: Chuck Lever > Signed-off-by: Qi Zheng > --- > fs/nfsd/netns.h | 2 +- > fs/nfsd/nfscache.c | 31 ++++++++++++++++--------------- > 2 files changed, 17 insertions(+), 16 deletions(-) >=20 > 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; > =20 > - struct shrinker nfsd_reply_cache_shrinker; > + struct shrinker *nfsd_reply_cache_shrinker; > =20 > /* 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 =3D 0; > =20 > nn->max_drc_entries =3D nfsd_cache_size_limit(); > atomic_set(&nn->num_drc_entries, 0); > hashsize =3D nfsd_hashsize(nn->max_drc_entries); > nn->maskbits =3D ilog2(hashsize); > =20 > - nn->nfsd_reply_cache_shrinker.scan_objects =3D nfsd_reply_cache_scan; > - nn->nfsd_reply_cache_shrinker.count_objects =3D nfsd_reply_cache_count; > - nn->nfsd_reply_cache_shrinker.seeks =3D 1; > - status =3D register_shrinker(&nn->nfsd_reply_cache_shrinker, > - "nfsd-reply:%s", nn->nfsd_name); > - if (status) > - return status; > - > nn->drc_hashtbl =3D kvzalloc(array_size(hashsize, > sizeof(*nn->drc_hashtbl)), GFP_KERNEL); > if (!nn->drc_hashtbl) > + return -ENOMEM; > + > + nn->nfsd_reply_cache_shrinker =3D shrinker_alloc(0, "nfsd-reply:%s", > + nn->nfsd_name); > + if (!nn->nfsd_reply_cache_shrinker) > goto out_shrinker; > =20 > + nn->nfsd_reply_cache_shrinker->scan_objects =3D nfsd_reply_cache_scan; > + nn->nfsd_reply_cache_shrinker->count_objects =3D nfsd_reply_cache_count= ; > + nn->nfsd_reply_cache_shrinker->seeks =3D 1; > + nn->nfsd_reply_cache_shrinker->private_data =3D nn; > + > + shrinker_register(nn->nfsd_reply_cache_shrinker); > + > for (i =3D 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) > =20 > 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; > =20 > - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); > + shrinker_unregister(nn->nfsd_reply_cache_shrinker); > =20 > for (i =3D 0; i < nn->drc_hashsize; i++) { > struct list_head *head =3D &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 *s= c) > { > - struct nfsd_net *nn =3D container_of(shrink, > - struct nfsd_net, nfsd_reply_cache_shrinker); > + struct nfsd_net *nn =3D shrink->private_data; > =20 > return atomic_read(&nn->num_drc_entries); > } > @@ -342,8 +344,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struc= t shrink_control *sc) > static unsigned long > nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc= ) > { > - struct nfsd_net *nn =3D container_of(shrink, > - struct nfsd_net, nfsd_reply_cache_shrinker); > + struct nfsd_net *nn =3D shrink->private_data; > unsigned long freed =3D 0; > LIST_HEAD(dispose); > unsigned int i; Acked-by: Jeff Layton From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D8293C41513 for ; Mon, 24 Jul 2023 12:18:19 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1qNuW0-0002lU-DF; Mon, 24 Jul 2023 12:18:17 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qNuVz-0002lL-A9 for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jul 2023 12:18:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Transfer-Encoding:Content-Type :References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RDXDydZCMBYMIrczKDE4bVsTDeQMx3KqkW665iu8SKc=; b=TkoTk6ghnTEbmZgzav+wv2GDWW yQmEoSyefT30fURu6GWO4e6CGwMb4d7vuHj9CHTD0O1ujLTlJPrhbQkB4SD4Eg6bJfo1V5vo76Jvh WunxjWNgkSWE0H3fllDi3L1l7nzY6RcYepnL50ZIcVg0LhcbCC/AX9CN2SIU8U0k2wLA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Transfer-Encoding:Content-Type:References: In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RDXDydZCMBYMIrczKDE4bVsTDeQMx3KqkW665iu8SKc=; b=abTYVmdYd8giqlhhI0dSvTgzTp JHVVB7rSIf3EXQSN1gKzMleJiqGFWfdRHwW+bihARbOmfhUP4CMC254InssEJF3ECiQ6mR63xHFzn wDzEzrIYOrGJhTvLWWVVhzdcay+NdXH65Xj0IqibFfchKtS2Dap1l/RK24fkX14M6aK0=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1qNuVn-0000wu-KO for linux-f2fs-devel@lists.sourceforge.net; Mon, 24 Jul 2023 12:18:04 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 397746113E; Mon, 24 Jul 2023 12:17:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7639DC433C7; Mon, 24 Jul 2023 12:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690201076; bh=SgqvEHTSsoLx88OM4JQmZh6whPE6BGZ/uEOL9QxuZhc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HeauOjdE48WDStWMcmbZe0QJCu1PZbrw2jnOfPPp5Y0n0Q1TK60SYgINluh0tVUHu HMa9pGy9YrA2Xid5ZQCkD41aahatrfHq9vVHLjbuzLzQBP/bIUW5s/kQBvStLkPbEr 52wVvvm4TuW1EIIyQppWxFYEv7SoUq895jOWh1zWA+5Bhuu0CwPKUfnKQ6aPaR+FNu w4bgci3LfqcgT2vztkyr4DzF2/4Hyf1LGlp6Z0shJe1d8GJLzPQbDhc3dh09sCIq3l N9zzfqaN5HsWy8Vmt4P1E7EQFqQrkFrxcJ7/1W6yEYc3GiEERam+zZN0XSQm/ELIIc 3urjqaifuO8iw== Message-ID: From: Jeff Layton To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Date: Mon, 24 Jul 2023 08:17:52 -0400 In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-Headers-End: 1qNuVn-0000wu-KO Subject: Re: [f2fs-dev] [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-mm@kvack.org, dm-devel@redhat.com, linux-mtd@lists.infradead.org, x86@kernel.org, cluster-devel@redhat.com, xen-devel@lists.xenproject.org, linux-ext4@vger.kernel.org, linux-arm-msm@vger.kernel.org, rcu@vger.kernel.org, linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-xfs@vger.kernel.org, Chuck Lever , linux-fsdevel@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-btrfs@vger.kernel.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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 > Signed-off-by: Qi Zheng > --- > 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 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52EBCC001DE for ; Mon, 24 Jul 2023 12:18:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Y3fjVQZVjO/n8ZrS10XeRKNs3J05iHks1ERdIKg+ed0=; b=clYavec3EohXhM 1YNDJBnb8/1JKhCagwZla4Nw6iRcYWxSBRkeCB+yRBkSrfyhBg+5QZJ/EtJrgse627c4fwGsVRZUN ot2bysnispgiL2V6JCeR5yMXS3hAnkAeKUSsaOnozOSC+ZFmUCBORdO2rWxBoUt3/cT58Teo4FAuP Zf/7gAVKCgozKCKadw7YGyCWkpBqgRbg7rOxyc8dn4eR7yNJWehdwIHia05OahOP2AP093KE3F6cu XvP2xVp5SBOIf31jN9zp2HynEesbhek9brEsbxMw6u5EACMBsy4uWt5dGxN11mSCJXooJ9lv2YYrg S3vl69m1dVM8BFbadRqQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qNuVl-004Cb0-1J; Mon, 24 Jul 2023 12:18:01 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qNuVh-004CZC-2s for linux-mtd@lists.infradead.org; Mon, 24 Jul 2023 12:17:59 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 397746113E; Mon, 24 Jul 2023 12:17:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7639DC433C7; Mon, 24 Jul 2023 12:17:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690201076; bh=SgqvEHTSsoLx88OM4JQmZh6whPE6BGZ/uEOL9QxuZhc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=HeauOjdE48WDStWMcmbZe0QJCu1PZbrw2jnOfPPp5Y0n0Q1TK60SYgINluh0tVUHu HMa9pGy9YrA2Xid5ZQCkD41aahatrfHq9vVHLjbuzLzQBP/bIUW5s/kQBvStLkPbEr 52wVvvm4TuW1EIIyQppWxFYEv7SoUq895jOWh1zWA+5Bhuu0CwPKUfnKQ6aPaR+FNu w4bgci3LfqcgT2vztkyr4DzF2/4Hyf1LGlp6Z0shJe1d8GJLzPQbDhc3dh09sCIq3l N9zzfqaN5HsWy8Vmt4P1E7EQFqQrkFrxcJ7/1W6yEYc3GiEERam+zZN0XSQm/ELIIc 3urjqaifuO8iw== Message-ID: Subject: Re: [PATCH v2 35/47] nfsd: dynamically allocate the nfsd-reply shrinker From: Jeff Layton To: Qi Zheng , akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Chuck Lever Date: Mon, 24 Jul 2023 08:17:52 -0400 In-Reply-To: <20230724094354.90817-36-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-36-zhengqi.arch@bytedance.com> User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230724_051758_016348_A5A5D827 X-CRM114-Status: GOOD ( 19.69 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org 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 > Signed-off-by: Qi Zheng > --- > 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 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/