From patchwork Mon Sep 11 09:44:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379066 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 55CA3EEB57E for ; Mon, 11 Sep 2023 09:47:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00FC56B01B3; Mon, 11 Sep 2023 05:47:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F02EE6B01F0; Mon, 11 Sep 2023 05:46:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DCAC66B01F1; Mon, 11 Sep 2023 05:46:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id CD2BB6B01B3 for ; Mon, 11 Sep 2023 05:46:59 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A4DC1140916 for ; Mon, 11 Sep 2023 09:46:59 +0000 (UTC) X-FDA: 81223837758.06.33B219B Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf10.hostedemail.com (Postfix) with ESMTP id D0CCDC000C for ; Mon, 11 Sep 2023 09:46:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=QjaVHwBm; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425617; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=B1G2WO6/xLybPLKaX4Dr+/HrbdrurAoh3vWthknuURZNnG/ohuypuKxvHyNl83/CJy4KUB vepxRGXNjy0Olidp5VWdpGRivHr5kHi0KjDsymHontMtN2kB0ChA0CqnAEue2X2/9RMKA1 UVDlyRdb7VKEYel+hxdO9RdgHWUxbAk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425617; a=rsa-sha256; cv=none; b=OBR2aj8m/ZJC0wOjyLzAg9WjFruD80oK9rrw24ENU8kVSNSLeyYnUN8PMp/HIjMjKtjs7O zllyucj+EU85N+ij6TFLQIMnxgHTI+ra+V2wTmTJwxC4SieWrwrXywipZXfyWe+2XNeCvs 9uYM0wV0KwBoZDbR+p+osxT8f1eqJX0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=QjaVHwBm; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1c39500767aso6232515ad.0 for ; Mon, 11 Sep 2023 02:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425617; x=1695030417; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=QjaVHwBm8pcIgPfyIyk8dwJSuK6E4nZCXrq1mCkuejEqcYCgh4fPuh2YrF/QJnaGPb N7/W/uf7pG3+/usIZ5yY8ov5fS62odP9MpvjVIX7g1mG9eZ76I/A8rrTaRcyFTvxPPh+ 31bIjQ1RwKzfyldKlhVpri3T3fmA/kvffjuy+73jIMybvDpWtl7y7IQnBWBU6PxBznJ8 z4AYUxTz4hZcfhxu5h5HX3aN17wkjyOOARFsA42wasP7BcbJBgAVFmhsqn2Imi9n/oyA rCorvl5E1mG8FGx7GTk2jJWDp21mg5fjZPp84wyqJkJYCeSJA6p+YoLKqznuyvZ09p51 JmQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425617; x=1695030417; 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=FXa1LVTr7cMGrveLuEzAv2/sv0TRtu2+M0j9hstuDhg=; b=TfGwh7Codp4hKBqr+9pM2zWoSd9SYPvZRI0U+iiQf3aLf3e6APQvxwcZYn7g1zm5YN OxfhbDyhcp7rCwI9qEveOUpavtUfNKycQUegE/7SsmmatxUR+3XKFwQKmwe4ZCLK5FND oe2XCThNGDdU/4QvnoDGipz4XNze5kPhPDubALAOW9O3tO02tsPneT1KU9sETrdW3egd m/51kfkmcwlKjWksl51b+QaJAmghOU1R1UDvwrbQLMLgKjP0RFZl7x9dIoPWhUGNCVDU MZRH9Uwzsb2JHQZHKl7OU14TVEPEIBX6WfxU0A8HmVWt3/GUx6pJSIpF+7M8611sEBDM 4gxw== X-Gm-Message-State: AOJu0YyP0faS0AM0D+kW8IalYJw6Vc1kNH6/EmCkbjH1hb7nt8T40KFT PSVGAa0kATSRgN50J8sFREKNYg== X-Google-Smtp-Source: AGHT+IHKZ7oB5FMEwi+qCC0j2E1ekjFtKsjq/92jKkTijP5Pj32E0W6thfocXbY8FqhF+sPzRd82Ug== X-Received: by 2002:a17:902:d508:b0:1c1:fbec:bc32 with SMTP id b8-20020a170902d50800b001c1fbecbc32mr10679560plg.6.1694425616764; Mon, 11 Sep 2023 02:46:56 -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.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:56 -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 , Muchun Song , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v6 12/45] nfsd: dynamically allocate the nfsd-filecache shrinker Date: Mon, 11 Sep 2023 17:44:11 +0800 Message-Id: <20230911094444.68966-13-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: D0CCDC000C X-Rspam-User: X-Stat-Signature: x5ktdyhf59cabbo9efu18biu5p9cst7x X-Rspamd-Server: rspam03 X-HE-Tag: 1694425617-236244 X-HE-Meta: U2FsdGVkX18snRbtYS2sqfQ+gV1hvaAX6xrzG+Jx7r15ffHgrMkM49TqQopkHGhioidKCkwiP4AW6wYWw6N3yhoYpqtYBWn/baglYMrhAvGe7YZSVYXqlIH8Xc00YomE/cUT0KIgLFEZlKONskRckFj3d6BgHzMgfKuJ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aEOVOL+T4WRzzT/LWc7TmQm2h2XTMS8rvR7ITOi0vz9BElPyifjAzkuTVGjwdzmxIFlrnmarOjnL7nLJ1bOSRAS3N1HXZVo/V6r4DAGMCIHzxnY3R2N7fNVXeJuVSdD5pdbpOUby58jkPrD9ypuxjn5w+dCjKjFk0TIr4PJ0lyp19wgBuabbK2l6/KYqkpiHdRWm9idNe39jUQ5XL21PaN0wq/jvY+KYclj55xp0b/NwJ9/OOs+6MJvevkHPnfrY3WfUEAsUlSD8yvrbYn148/d7VknJTNVqKyYeG/VYKTet7hVH4UJ0UL7lMqOyj3r5rNQfv+a4/Q94cuRZPACbZyEfVdIu0freIO9vFsqkGJqewXv6fETzWPAhGJS38= 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: Use new APIs to dynamically allocate the nfsd-filecache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chuck Lever CC: Jeff Layton CC: Neil Brown CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org --- fs/nfsd/filecache.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ee9c923192e0..9c62b4502539 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -521,11 +521,7 @@ nfsd_file_lru_scan(struct shrinker *s, struct shrink_control *sc) return ret; } -static struct shrinker nfsd_file_shrinker = { - .scan_objects = nfsd_file_lru_scan, - .count_objects = nfsd_file_lru_count, - .seeks = 1, -}; +static struct shrinker *nfsd_file_shrinker; /** * nfsd_file_cond_queue - conditionally unhash and queue a nfsd_file @@ -746,12 +742,19 @@ nfsd_file_cache_init(void) goto out_err; } - ret = register_shrinker(&nfsd_file_shrinker, "nfsd-filecache"); - if (ret) { - pr_err("nfsd: failed to register nfsd_file_shrinker: %d\n", ret); + nfsd_file_shrinker = shrinker_alloc(0, "nfsd-filecache"); + if (!nfsd_file_shrinker) { + ret = -ENOMEM; + pr_err("nfsd: failed to allocate nfsd_file_shrinker\n"); goto out_lru; } + nfsd_file_shrinker->count_objects = nfsd_file_lru_count; + nfsd_file_shrinker->scan_objects = nfsd_file_lru_scan; + nfsd_file_shrinker->seeks = 1; + + shrinker_register(nfsd_file_shrinker); + ret = lease_register_notifier(&nfsd_file_lease_notifier); if (ret) { pr_err("nfsd: unable to register lease notifier: %d\n", ret); @@ -774,7 +777,7 @@ nfsd_file_cache_init(void) out_notifier: lease_unregister_notifier(&nfsd_file_lease_notifier); out_shrinker: - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); out_lru: list_lru_destroy(&nfsd_file_lru); out_err: @@ -891,7 +894,7 @@ nfsd_file_cache_shutdown(void) return; lease_unregister_notifier(&nfsd_file_lease_notifier); - unregister_shrinker(&nfsd_file_shrinker); + shrinker_free(nfsd_file_shrinker); /* * make sure all callers of nfsd_file_lru_cb are done before * calling nfsd_file_cache_purge