From patchwork Mon Aug 7 11:09:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343689 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BBCCC04FE1 for ; Mon, 7 Aug 2023 11:17:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBA826B007E; Mon, 7 Aug 2023 07:17:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E428C8D0003; Mon, 7 Aug 2023 07:17:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBD518D0002; Mon, 7 Aug 2023 07:17:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B5E086B007E for ; Mon, 7 Aug 2023 07:17:41 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 854961A0820 for ; Mon, 7 Aug 2023 11:17:41 +0000 (UTC) X-FDA: 81097058322.08.F011413 Received: from mail-io1-f47.google.com (mail-io1-f47.google.com [209.85.166.47]) by imf14.hostedemail.com (Postfix) with ESMTP id AE5E8100011 for ; Mon, 7 Aug 2023 11:17:39 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ip0wYuQW; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691407059; a=rsa-sha256; cv=none; b=S75iK88Vsz+ztZzE3/mf0ow4frGAOPxe9DZl2FzEaDIvYSysHFfjzJFahds8WJK7zWW908 cdPphdfFBjXUoEq3Zrmz2Dj/Zzp1BW7Q+v9FwrJ1nDYTMzTvY6F2HrqYYePXTfi8BKZAGb nXmUEXAuUWpqvA7Kz/TF8wYj8Rlyyn0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=ip0wYuQW; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691407059; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=7fRlZzvX3sfl1mEw15PE0pSkq3SbSsj052FjG03sGXRsoqWoxtddHru+uhrrbfO/Wy77DZ til/0IuIYmfOTFXENGPoBHNhO/BSKHwh/FcNzJ7aHgTAHF12StJookxOdKliZTBA/cmIwx V+zRM7cCj9MR/C8do0/pxaJQFp4QkA0= Received: by mail-io1-f47.google.com with SMTP id ca18e2360f4ac-790b6761117so45137739f.0 for ; Mon, 07 Aug 2023 04:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407059; x=1692011859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=ip0wYuQW2+/exFbWgV8xiqSMo5oTQ+OAdV6N1Ar0LEuRT0eIq620KDbMvERQspVuIX AL+wevZXKdon9YRPQjclhoX9H3SrxByFFe9jR5690ffz3lESe4Q0ZFhT9ousgzw0xt/w 5RRxxYEFUQ/KP/U5y/hPXXWHBw2c8mi1xHmKIZ7mZeQKJVTuYBj/qteoNFG9SyZ1tjUE RbAUg65PVJJ+WhDtWwqZYb434jDUE36PynN0DkYIbM09s/1BNwwPxkk2HM9wFLeNzyaL lqpAqgXw+Mhtz5SgHNy0c1hVzxk4Y6rOc9m8zwrbUN+lDejRoW7+lKGMq2jSF6Ub2+cH D5RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407059; x=1692011859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f+7Rjo519K3FhaZ9jqPWNUITMom2L2BqSXFVMuCYJXE=; b=U+hAwfsWY8Sf10oq/bE54YgYjEL91+/XWXFR1P57lm4h/ZjTjAf1tWZ4LbrKoo+7Ht 4zkIx2BwMNAqKuch5urEqpv3cqr460d42Oe9Y2LjXHzdRPYxr75IZ0JAF17cf0IotrM9 q4YheJj7QC6TBkRCxMD8PoD7wRy8+4Eusg2Z9w9h65fPcc5q3gMQ0U0/i/8j8Pjx3IVW lM6CS3ZQjGzPUSlEK5gDYFqUNjL/Codjm57M05APg56xRb1xE3YXlQUclgizs/LVz9wb vMLpoyspQsJlgjTDgR1ZMIvbkpIvbKjjCaNjo5egFBIT9HCaMuOXBwLqeNcZmuSNE8mP S+KQ== X-Gm-Message-State: ABy/qLayUDRrVkC9XofrOpqQIh05JW95v/3tdgDhMmNP8ldSCTqIIOG7 VVD/DZCh9ycCwyLxZoVE4F7h/A== X-Google-Smtp-Source: APBJJlEqWtJMEzUOeETqs91YS6OhZnccr6gvE839NK54utINPmY3rqSAbE5saT2wFNMSrRFNpkUXNA== X-Received: by 2002:a05:6e02:8ef:b0:349:1d60:7250 with SMTP id n15-20020a056e0208ef00b003491d607250mr23020165ilt.0.1691407058833; Mon, 07 Aug 2023 04:17:38 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:17:38 -0700 (PDT) From: Qi Zheng To: 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, simon.horman@corigine.com, dlemoal@kernel.org 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, Qi Zheng , Chuck Lever , Jeff Layton Subject: [PATCH v4 36/48] nfsd: dynamically allocate the nfsd-reply shrinker Date: Mon, 7 Aug 2023 19:09:24 +0800 Message-Id: <20230807110936.21819-37-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AE5E8100011 X-Stat-Signature: ixgea8arbmb4dup4w6kdiwthyqy7dtus X-HE-Tag: 1691407059-308498 X-HE-Meta: U2FsdGVkX1/y21BKer0X8Vs5RpIVqWzITVG5+Ib5vuGrp/drOvIx0u/Fdi07Y9qKkuNCxTwXFpWrGN5s08YwlnB/di/oYif/KPuqwfFvaklJ1j1WQIPNhxBrWYxT14La2wcxUzt3AkJ8FeULOIvU3SFBmoBOFZOZR+wjZGP7rz5gqY73mpJjrYvXoXC72G9Xr2E09joIwhlgPeYdcTfIwv4jt731kkyP7LDfnV2EUVFqQMvNxSf8a85u2MqGWuztXNCT3nLrs7IsFWmvGIHzeSnFGRJoLtt99bgqOTDNQJMxe6KkaYrita2eqatFRemICUknjpJiq3guV1q0PSJZgw17STgHXKA1kurfN9Is7FX2YRGut/cp27mk8vKUAtXN3bY+gK7meKqD4XV1rNBKp48ET+UeuOm8OJnAm/rusjQ1huHz2vSxzmsFyf+S2VMCMidJSEJGLrNbSZTZdulT1y9ZhzcZCrKORhLqG2KVzhxZ5NMEk5OIEgCwI59bgWPc5KcTw07XOp5G5n1qZXXrrWPBBBG7rHXp4Ynu7Vt1+MktNMlZmgjc1wwsYyWRPKSWwBP4LYSarX2n0WxRkhnQTyExqGd8MRetkY1UqRWdG62moQky57x5poObmOluePeyTPHxt+DRKXwQB6A3lZCGgYPqotF7zXhlx3sI8XhqpBdbSjEERgvCk4Mh1RclRN049g9wYGDoIY5yppPnz1vbBkuAPeYMPCgg0RApwZRYF+j1POvSlOolrFRXrPKOOn+FROyxnaYrkOZWUFYPVF2zVghVz+qt3h+Z2cDdUCFD1/wm8TBekOrqMJDkDPvMb5BRdFN2EEiGJ0n+zFDYCYBF9stIELXG5Y10F8rnURQZh3Sfn0TF9TtSExbdiXw3DONpPPGr2GD829pv2bf3jNwiTKBVXlFOzaFgS2iC+habgnvM4olMPy2/CQ+LYwKEOdf5uO0wTygfrWg/qJXzt+P 5+bMoNyQ LXom7lCKAR9/FyAiJBGu0iQ/gFOafCVucINmhcHwF/zQup66WohyzAuIzbq8hsoGxzuKdqLyc2zrHM95xLxZit2KPzoOOvbMSBnsu/J6d8VqPRD2M6eP6J9yoehQ9noKZ/7/kewzLc13hkyltJT/bRzW34/Md4KTglwVCoutLgQ7kZYM4F0MW79ZVDTRyefJH7saDPMytexoMFScUFkldB1qPoaxSEXMdT8Bt+n9CDUz68zLyLZgqe0K8isCLv4F0SpxOG4/saI8AhrEoFebMO1rXjewaYiC4FF2oOhhLTKQEuh9JRuqdRd1NdngoU0sr7woduzKOEbtVvN8NHrv8Cl49akP62OOWa21Ie0bI4APmqEL4pMrWwRcWAeOZVjuenkKivVdewYe1yXOlaW3VuhUQYupykKDvhXoO5k0qN7qrX8zyszE/13/RH8Lls4GPDIVU6qO6hfxOdl1/lneUrKKOJ2dM8KPseTP8IfsLAY4xpXpjHISbD1ItJw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Signed-off-by: Qi Zheng Acked-by: Chuck Lever Acked-by: Jeff Layton --- 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 80621a709510..fd56a52aa5fb 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -201,26 +201,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); @@ -229,7 +232,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; } @@ -239,7 +242,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_free(nn->nfsd_reply_cache_shrinker); for (i = 0; i < nn->drc_hashsize; i++) { struct list_head *head = &nn->drc_hashtbl[i].lru_head; @@ -323,8 +326,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); } @@ -343,8 +345,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;