Received: by 2002:ac8:45c5:0:b0:405:464a:c27a with SMTP id e5csp996917qto; Thu, 27 Jul 2023 01:22:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9poPpkGEM0yc8Eiahy8tn4b1id3kkaOr4t5X8HKkEMOnkd6FkojRVHw+hWOZRVnHjk05k X-Received: by 2002:a05:6a00:1681:b0:674:8fe0:126f with SMTP id k1-20020a056a00168100b006748fe0126fmr6548943pfc.27.1690446120817; Thu, 27 Jul 2023 01:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446120; cv=none; d=google.com; s=arc-20160816; b=wzFJ3c9EPC3i1tyEdB4XEBORg09xi3YBLcIGeQBxZKYs2h5HaSwS9XDYOVZFr0phy7 3aVRIqqs5yhfK8Ff86F/WFZKgmF5bU2bDk/YhyauhvBKfx2kAWalAgfzorB0Q1uQpzCf tfAvUXe13hjDcV6JjEIjlPuMcZ+jnAkNaTrv89p5it93AxrIjKzCXKcJxygFkFNg1IRv u61vf3OWrDukj2sMkypkDZXSqW8YNg0TGfZZ41iTK3MEjcD9Ot/ZXQv5KkTAaz2Tc+Co 45gF/Sp8FEXiPbK52hWr8ii0ldoWPIGy7Ssp2/jvzhlrLrqKDvd03dmwJjBzEczJrbsU 9FUQ== 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; fh=NxkGAd430gburLVd9IjvP+jLcLBa8IzZa5IqPWgCN1g=; b=XkmTcQqMHdq/u+8CCVHzUKysgPsEJoImktvzgW921sTESl6dkKpnsZAXouKPq25Lrb TQFQv2b8hGthL4G0xSnRbBdiFpECIsRitUw7ecbMcpTqxFMgQn4UMwEcBgu2V+YfydIp 0BohOXMyamM34SN/13XpeqpKdvr01Lh4qI/gXIp5RqdXkXtrrWYk1yi+6oNRRYqJ4NxN woYCsRKP+RIIVgvzUJ0G2tjQUTSKFRWx6TCMAv9AYv2hUAIo3/eufFHetF1DjgUEhvb6 36ZJgwN242iWYwDXEu4+IUo1lKIMkkhaCtZO+GhV+xV12tFxx5OV6tAzOn+luSxAk7Qd YBAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=f78FOiI4; 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 cw23-20020a056a00451700b00682c8951d45si1005324pfb.271.2023.07.27.01.21.47; Thu, 27 Jul 2023 01:22:00 -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=f78FOiI4; 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 S232745AbjG0IRb (ORCPT + 99 others); Thu, 27 Jul 2023 04:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233844AbjG0IPd (ORCPT ); Thu, 27 Jul 2023 04:15:33 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EE8D30FC for ; Thu, 27 Jul 2023 01:09:54 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-682b1768a0bso174893b3a.0 for ; Thu, 27 Jul 2023 01:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445345; x=1691050145; 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; b=f78FOiI4CNId+Ml2PzU7mY1IxHereBLlHPf7s7X8Gy+u8ge3z2zcNtZJbXgkJ1G/QR Bypsj3Qfs4NqFk8L9OHPUra+lfok5RS+DDluwPHI9kxnAJLSgVKbtyU1LC00kLM6jzmr VkgjJJoznrUMJZqGeb8qVz0Juy94c4XL4Hr58JZjfVBDwwW2089Gloj9mnDr01+e3vie ATN8u6YkhMkKc+i92NbP56LSIJl/sZe4eRd/+9U9Zz62iXDekK8cKEfr5HTH0aUYxIkr BT13YNvigorKsMJZpm5Ugf1VrzOLWJZerOzcVEByhulhpkn1iKJBA5Dz0oLwz2cUXQdL iC6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445345; x=1691050145; 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=XxxR7cKF9GXj8MC2HKPXqv6o5/ypcgPst5/afOqmqdU=; b=V3BfEPPd4d3g0OJah9DlH7RZO/BWHrdelH0AVVbF06LP/iwnvb3kMWk6JwaXv96/Z6 JgEqm4nWea1qbZAD+52fbgVU5wbarmQAyo2crSux/Iw6VuEFW/JuNQDBf7We/dHC7qTF wiRNAoeuCYffqzHrpRUOlDGURgtZXZnDB919gv+6K0tAjO88mHyZUJ+C/qegZ17N2qR9 gqWitnX6VUe+J/MELpaxgUScuEo7C3y36CCO2MuybArDgL+ihUdjfalFqQjIY58F4bSd kvj0eA2nUatas+t8Xud/rQ2p7JRTxsVCs6G/FLQphOSBfKCi5Z67SL9S9ODNKRafZkoZ JBaQ== X-Gm-Message-State: ABy/qLbySsQu6BTuBvC/S+1fOJd/x/GaUra7EyjpqNrD2/Z2P0eCAe+W XBLnBmIKatPpZxi4+vEP+ZBXPw== X-Received: by 2002:a05:6a00:4a10:b0:686:b990:560f with SMTP id do16-20020a056a004a1000b00686b990560fmr4379620pfb.2.1690445344746; Thu, 27 Jul 2023 01:09:04 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:09:04 -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, 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 , Muchun Song Subject: [PATCH v3 16/49] nfsd: dynamically allocate the nfsd-filecache shrinker Date: Thu, 27 Jul 2023 16:04:29 +0800 Message-Id: <20230727080502.77895-17-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-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_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Use new APIs to dynamically allocate the nfsd-filecache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- fs/nfsd/filecache.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index ee9c923192e0..872eb9501965 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,18 @@ 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) { + 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 +776,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 +893,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 -- 2.30.2