Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2863738rwb; Mon, 7 Aug 2023 04:59:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwUqA+DpMuq4U0NJuns2g0P70kQQsuyapsEFyfK7CeG1Cc9CPbo91mxnGCfow1Bcu2bVn/ X-Received: by 2002:a05:6a00:1915:b0:687:4802:38e1 with SMTP id y21-20020a056a00191500b00687480238e1mr8684538pfi.21.1691409569996; Mon, 07 Aug 2023 04:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691409569; cv=none; d=google.com; s=arc-20160816; b=jAyJIjhz1EhA46QtTM+zWZemGaMhSaihuj7wxuweyHWSS1QTTqBCqPpE0QvLajST4b PFdbU5P/wtKzewrKxdmonrQbhcGV15/F2iE+5I3S0dT/j6vus+tpBsPL8nue+n9oRP2d DD/yGy+13kdx6/ks9Rh6VHVECsBj6omekFiXw65uwXOe3ENZ16Sk+NsP67AhU1dcRWcB NQ20akNx1+EKkkDIxs5uCmIFRtuLJ79pkqAMUVa6KZLpViGu3ZpIU1bHe4pPyFTKAvMB 8FnqYlIMXkUdw0yBNkEMFFx55mzKzPdbYDS0Fa//wruVDg3vgoh/4ZNb2acTbySl8f95 lCRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v5vYJ8kE3O6JXdLxdEEyUgUMjz4KJqSKKSB151wqkNo=; fh=YzPvPJ+6Oqpv2hjhIsUQGxr59pZw+gLaOk6jI9nW6RU=; b=MiNnIyMSA5cPgV6S4aFcAGB5+IIGCCF5CK/MqRS4BL9ktK7m1MdbPhMwf65A/H/ptH 9VXHEGzNUmqd1BXzqkR0ugLMJ6Xn8V8obIDH7lXxLa1L2ZMtxBQl1oaRWu0B7+HRwVza 4EZCj/Krqiwq/armyoZ+CLhmHUgoNdwANwNcevuV0Kgrfb8/TPQ5gDdGg2VEu6Uyxp8m 0cKnCIBxjFeKrDeQibKXnKzXdseCPXJRqhXvdS0ipVmUrwDXaxlRvcK23GwrD3bFN7/J sKn8ggxrwkXERU/sKI9gRtnuTw/s1FO2yYouOzdddIDIVVXQX6jGOQkscOlCt47bO7vh IVag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=l0X9wRqf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay18-20020a056a00301200b0066e608447d4si5733247pfb.102.2023.08.07.04.59.17; Mon, 07 Aug 2023 04:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=l0X9wRqf; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232757AbjHGLdk (ORCPT + 99 others); Mon, 7 Aug 2023 07:33:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233165AbjHGLdV (ORCPT ); Mon, 7 Aug 2023 07:33:21 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B76B1BF4 for ; Mon, 7 Aug 2023 04:30:16 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id af79cd13be357-767b9cb3d3aso35255785a.1 for ; Mon, 07 Aug 2023 04:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407756; x=1692012556; 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=v5vYJ8kE3O6JXdLxdEEyUgUMjz4KJqSKKSB151wqkNo=; b=l0X9wRqfCnzpED5q51Na1qb31v1GQKKzxAx1ruSijD6CGMz3nEBErjbYmRBqCCcqyU n/hF/68SofAStrPP20KXYUugIGT6X89p2PvgEDamHUTC5dEVaNMtUscEn0zq3e/5kwpc r3Qr7WJRXkgR6rzJFsXQiD7s6XiH0kD+CWRahfNl+jPNLTMj10I2XtQETkn1z9i685Ha OLgSBnuQmsmC68Hk4i/eOJfXfA1iCp9QY7M9VnD+eyCg+E1SYxUPDnynbuUtm+yDlSpa AiHyUmOWaMv4IrzOFfXhbBWJcKEPtq+IaEB2/yCirxNzZYOFYp9q9Lg/AZtpaGczDDA9 gRgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407756; x=1692012556; 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=v5vYJ8kE3O6JXdLxdEEyUgUMjz4KJqSKKSB151wqkNo=; b=YncC0EPhsq3peoGaWe4smUTWDG18dCAByBscSveblnb3qHeGTA56YYlbbvOVqrjHJT 2h3Dtr/QOfTeQa3XQ8LcEJ9yti/hAG4AsmTDmE8BURYlzaV2J6rfrAHGILidt6P/8Onx XJS8noLWC3f0MXTJTTezKbamJyRcGeUY/z3iVtkix2u+yfVX+3kJYNB0wpTD27dw+PZa O6mke84kxXlS/BpvHlihEabCkf1p/IYbU1gq9Eu/z9BGXUqRFXjJaVuvumBMefhv3SUN TxpMcR9kpFCPaYAzZLqa9bu6tn1R+X4BW9dll/dJBXIKd1DzcF16JRhmPC6XkbibqSNZ j1Jg== X-Gm-Message-State: ABy/qLZS6SR14kuxgHl+c+11aGZtdaJDVhUHFFwBeqYfIPe40ONJ8L8E t49FQSIvrpTgjqHk3TJMz1DNQlbihWBqxWrQWc8= X-Received: by 2002:a17:90a:3f08:b0:268:1e3b:14c9 with SMTP id l8-20020a17090a3f0800b002681e3b14c9mr23486908pjc.2.1691407045970; Mon, 07 Aug 2023 04:17:25 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:17:25 -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 35/48] nfsd: dynamically allocate the nfsd-client shrinker Date: Mon, 7 Aug 2023 19:09:23 +0800 Message-Id: <20230807110936.21819-36-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the nfsd-client 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/nfs4state.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index ec49b200b797..f669444d5336 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -195,7 +195,7 @@ struct nfsd_net { int nfs4_max_clients; atomic_t nfsd_courtesy_clients; - struct shrinker nfsd_client_shrinker; + struct shrinker *nfsd_client_shrinker; struct work_struct nfsd_shrinker_work; }; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 8534693eb6a4..9e401db8a6d2 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4400,8 +4400,7 @@ static unsigned long nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { int count; - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_client_shrinker); + struct nfsd_net *nn = shrink->private_data; count = atomic_read(&nn->nfsd_courtesy_clients); if (!count) @@ -8149,12 +8148,17 @@ static int nfs4_state_create_net(struct net *net) INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); get_net(net); - nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; - nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; - nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; - - if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) + nn->nfsd_client_shrinker = shrinker_alloc(0, "nfsd-client"); + if (!nn->nfsd_client_shrinker) goto err_shrinker; + + nn->nfsd_client_shrinker->scan_objects = nfsd4_state_shrinker_scan; + nn->nfsd_client_shrinker->count_objects = nfsd4_state_shrinker_count; + nn->nfsd_client_shrinker->seeks = DEFAULT_SEEKS; + nn->nfsd_client_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_client_shrinker); + return 0; err_shrinker: @@ -8252,7 +8256,7 @@ nfs4_state_shutdown_net(struct net *net) struct list_head *pos, *next, reaplist; struct nfsd_net *nn = net_generic(net, nfsd_net_id); - unregister_shrinker(&nn->nfsd_client_shrinker); + shrinker_free(nn->nfsd_client_shrinker); cancel_work(&nn->nfsd_shrinker_work); cancel_delayed_work_sync(&nn->laundromat_work); locks_end_grace(&nn->nfsd4_manager); -- 2.30.2