From patchwork Mon Sep 11 09:44:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379108 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 48607EE7FF4 for ; Mon, 11 Sep 2023 09:50:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E43E96B024E; Mon, 11 Sep 2023 05:50:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF3DF6B024F; Mon, 11 Sep 2023 05:50:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBC726B0250; Mon, 11 Sep 2023 05:50:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BC4226B024E for ; Mon, 11 Sep 2023 05:50:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 98E828093F for ; Mon, 11 Sep 2023 09:50:04 +0000 (UTC) X-FDA: 81223845528.17.BDF2E79 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf23.hostedemail.com (Postfix) with ESMTP id CBA3514001C for ; Mon, 11 Sep 2023 09:50:02 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=E37smXqL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 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=1694425802; 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=6ZTXwNwx2asy91EMQXlbltwoITBr0NKqwsB4INdumqY=; b=c53TgwdmtboOOcsaBq9E70gRKRIeXh2qMhqaw3IiHq1Peruwad2XOz2W6+Hn+MChUwo5qq J/jeitPUacVeqW68HIXjdW7DtqNGhIjzmQlciV6x0sAZ3jpjhkFD1+YtkLdfvObhjFMBKI X/KTRNV3DR0lNdCABNrn0D8L8dpQlxc= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=E37smXqL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425802; a=rsa-sha256; cv=none; b=YA0GoNdbkFI/y2YSZEHdic2b08wdvzC1Pq24SStH/vfJwuSliDG5jshffQzWgFlPeGHGMN 1GeeSJxpS3WzviX0kqbjurpxktJGIC5kVq87CcYRHPSYkODbfvPFxv/d4uH/dtEDOc8b8N tTbV2xil1CzptEUZ7IYLNG+tPVnnNlE= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1c3c4eafe95so469425ad.1 for ; Mon, 11 Sep 2023 02:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425802; x=1695030602; darn=kvack.org; 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=6ZTXwNwx2asy91EMQXlbltwoITBr0NKqwsB4INdumqY=; b=E37smXqLJMlnxp1xcJjLsbyF+wbRyolLaL3uBfIQqg2en5+5xPlIziXgjmqqjsOV84 XOeNWQ8sjlRDZOR+5NYbtXVPwNVk/D810OFe8dNKTokMD3+mSiqMPlPFx0ocCVIRvOcO C4CGa8BN/vR9Hq+rXj7fVD2bb0zzwqkgEwD9fNx1c0kJbf5yPVFYI4Zlsuz6SCSULoKy U6vb7veovMaHqP19srnmSolGg1jd27g1jxiHZ3WqRXI/KVT9KdSlDRv0o01lLfmix0KV AlHj/rDufJVI4VKftJHor6Y+ynRf4duAZ3QqLvRY1ZytZ5jgrRwqEpveaJPWn+DEb5ca 1xaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425802; x=1695030602; 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=6ZTXwNwx2asy91EMQXlbltwoITBr0NKqwsB4INdumqY=; b=tYRQMKybS3qjkLJ4fikPPr4XZwhpGFwpg/i2nT3FwyBkO4O4mI31liCIzp9+ekqss/ Q5p2kbFWNikYUz0aNcZP6op3lIZkEtZzUpNpAWm4kvCV7Nk07Wqw2yiy/okkkgz4kYor DeGwSeK3AuZYdIk00yknj6A9bsvOxsErHXy+bUmAQT7HFKa1/4V7J5VL1iJO7fgFgpLJ BeAnzwtkDydaZ0YQhS1lW4I1hRqkKs2uCiiL/nDOWwZdHOcShHXkLnenE6+2Vb5aUGJj esZalAprR9KVG7ciPi+CFvMz0wo4bgxP3dfUJNRQlwgNaGk6VkgiVZ7YBqEVPlQS0qU8 k09Q== X-Gm-Message-State: AOJu0YzTWwCK5J/JGg86UHwzkpSuGz5ZelHl9Miscz9k6aN1sVBvrB4F WMOz5v+bMWJtC29WfMr2cz94oA== X-Google-Smtp-Source: AGHT+IEkexmOMmPsZvWCanh2pWTN/2CGfh7wrAzfAIoePXtjWRgsy+zRfdte7qLYby2W0F9SEkI+cA== X-Received: by 2002:a17:902:ced1:b0:1b8:a469:53d8 with SMTP id d17-20020a170902ced100b001b8a46953d8mr11188132plg.0.1694425801744; Mon, 11 Sep 2023 02:50:01 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:01 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Chuck Lever , Jeff Layton , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v6 32/45] nfsd: dynamically allocate the nfsd-client shrinker Date: Mon, 11 Sep 2023 17:44:31 +0800 Message-Id: <20230911094444.68966-33-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CBA3514001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: hwjabocm3qyrp5toopcrnowy3psy8ffy X-HE-Tag: 1694425802-114946 X-HE-Meta: U2FsdGVkX19GtQDCjtwpXg6ZLKupVQDQB5pR9iz+Pd/TxnsFp6dZ4ZMknVUEtLcQdmeToA3nY6Plou609rxZNRLEt81yPcsSvOqV6S1roiqT9ww/clYJAqP/BIks0aQqfcWeV2NObqmpOf636pyPoxWB0qWBTm/VgYudQsnyhSQny6MeAKudbLdgkMsCmry6ft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MWVXi3HOKqe5ryF1D0h0v0plG9V1CvSpbiKfCJR8bwjQX4w2GSYjUhOB9RvZS+coKb9I9GpSEVwm1qZUAImCf9bpmBMkTx9nGu22GjWYcdL6PUiMkvIqKI99MWcgphITSAC/O8gnYwaKM2IEersUFVq7k7OydSc+OWLwId42oaEWGi7KWqliipd2Q7p3bLbkfsxjTimqUmO2pXE5T+8T8BwP76lU4ps8bNYimgdDOzr6vmnoyw3pQU0ur4za6l3KvNT3iYUW1KZHCaKAWrScYgTs4pOJ/TPN3rM0/xQ7IZFbV421IKQqWI5OnRYKRTid1zjuByzfDdh3iL8GWHLIK/Wjmg= 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-client shrinker, so that it can be freed asynchronously via 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 CC: Jeff Layton CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfs4state.c | 19 +++++++++++-------- 2 files changed, 12 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..23b3b38c8cda 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,16 @@ 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->private_data = nn; + + shrinker_register(nn->nfsd_client_shrinker); + return 0; err_shrinker: @@ -8252,7 +8255,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);