From patchwork Mon Aug 7 11:09:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13343512 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 12D83C001DF for ; Mon, 7 Aug 2023 11:17:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC3FB6B007D; Mon, 7 Aug 2023 07:17:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A72E88D0003; Mon, 7 Aug 2023 07:17:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 912888D0002; Mon, 7 Aug 2023 07:17:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7B0896B007D for ; Mon, 7 Aug 2023 07:17:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E858CA0A30 for ; Mon, 7 Aug 2023 11:17:28 +0000 (UTC) X-FDA: 81097057776.08.C9E29E0 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf19.hostedemail.com (Postfix) with ESMTP id 203FF1A000D for ; Mon, 7 Aug 2023 11:17:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SddB5W7T; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.171 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=1691407047; 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=v5vYJ8kE3O6JXdLxdEEyUgUMjz4KJqSKKSB151wqkNo=; b=UxVJonGA2pXPiJxiyYCdEeodMe4PHCyJXb0KK7y+WYtIKF0CmgZ1ZD3l+0awEH4L/ShjEO Ltbcc1j+72XNnlHrAknQjYJbs+gVPEOCgNYfk4NAznsv1XRlHR6reaB8KwvrWJzM2IgqBe fZU/UDCoQAHqUKS5K5FysARbGI2YG90= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SddB5W7T; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691407047; a=rsa-sha256; cv=none; b=phiOBcEC8pkCWR7c8Nba9nbhQySyCE1qllMOpEgswNQbSeKB05oJn8Z6NAoQiEMfkDnrt7 KnVtA5mxDed2Imm7Vy2Ug6ge83kJrYYAOf3kUhcPT3oe2WK9RZT8vXcnVD7+fyQkshdBpY 42p/XdJqyXcsFXBrGwOJPDxwrHneaGc= Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-51f64817809so360825a12.1 for ; Mon, 07 Aug 2023 04:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407046; x=1692011846; 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=SddB5W7TBGS4uOBB54oAwQadrL7fhf6DQuFGu8VJel4YD8JvtkF5mhOckA/6vdi9nq hlVTmdr/Kx1D4xlpvO2OSKYXB5RvVMiR6sESxeeh8/ktD09qDCXXwpDE4WqRU8hY11FY G6KR4LUZZolsNcExYWQgBloqrZSLljdTAa93b1m2N036gRwi9BwogxNRXUsItZlswdeV RttwDZcFyg1S8l+4ePFxtqYFv2AYsGXbvb/zq8emVyERgALeuEVi3b9ZjwWVeQ9iauxk xcZs9+wDP4Bgr5Tw0/5OxVGHY2k5SYNUfTOTk9l9GbDIx4PuLA8GEzMw0rmzVwGr35V7 B6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407046; x=1692011846; 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=h9+LE4QLubYFE/t+QSvl2vOF7MdJRck3Nlj+c9/8frBP3m7+BAMPi9iwMwzWRhADKS D2QX9q//o/kiyAJTVZQW/MPGxgkG96FF2GCuh5CFtJwVcfoGbYaCFYMlWlZewP1DJyQA sISpKr1Xqp7c/v8aPyw1Ir5fvJyeEb7ex3ZOxVQ/57CeE5IOz9ShjVG2FWJ0YuoIsvoW cXJMVdghfU2LP+gJoXJiuuLJE0oCvDhrf6BXXJwNrBNMEp//DOGvjqfYqlbuJC87nx1Y EJRYGyfNsyhIhyYjAkpD06UjYf5yK68AFL0bXI0+pVvNnvoqJaP3/8fzc9YEBbx+dtIp PE/Q== X-Gm-Message-State: ABy/qLblqOrkevFY0JtCBLPbiK9OMB63KRFKiCd6qI3YWuwW9VIQDwE0 2wmg6rgzuUnvps0mHDngZdDrSg== X-Google-Smtp-Source: APBJJlFyAF6s6JefOZNl/scuUGwKU5q0BmH7yK6Qf+JZ3E1mrAS2lh5NuGQm2RRGuEVfms4+14afyQ== 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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E9kcEuUR3Uu4Kd6AIqitUHbaDOX8vzQ5YtkiBfHFNct0 6Z/uL1rU MgAQey0tQnHgSLy18t1Nc2bQFQ7ZtqHPcaQhGk2VqeqVaYFOjm7FkS0SfAURBwyQIp3zSQSpg3knlXMdZrVVcXKsdUiohEfGM7x+pOf4ePcR/mVHBDymfxryNo0wvACpqa9hEfvdm2QT/r5s0yTlzXygsM+sVb0IYPZSK+reYRO2uDr3IhKpoxCtdCEtZeYiX7Q/af9AWNBPXhLwNbNAzQr44jMUnhPg7Z1HA0OIc34gGII5IPsbUkrZLCGps8Nq+aNGEfNKMYRTyE463Y6DzV8VTYOMXTS4pog4P0ZKXV3PD2jAtTHXqlankWQKXd+HFytB5gTm4jc6xLg3Om13BGmQZevyvutXZeWXxEQ8X0mbuiAw/arFIIm6AvpT5rQiJOPIAFJfxIFn7bjn/DhfPvcEURF/qoNigSqN1U23ZwbcqelC1OZfOsH7GBiIPcvKq3DfeH7GbR+da9BYI7onNEUylloMfR573CCQQxmDw9WkyFbCIFiNJ4Wp6ZA== 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 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);