From patchwork Mon Sep 11 09:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379064 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 60E1AEE57DF for ; Mon, 11 Sep 2023 09:46:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2B8D6B01AA; Mon, 11 Sep 2023 05:46:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EDB796B01AB; Mon, 11 Sep 2023 05:46:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA4E46B01AE; Mon, 11 Sep 2023 05:46:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CAEFF6B01AA for ; Mon, 11 Sep 2023 05:46:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A0AF0140918 for ; Mon, 11 Sep 2023 09:46:41 +0000 (UTC) X-FDA: 81223837002.22.F613040 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf28.hostedemail.com (Postfix) with ESMTP id A6214C0019 for ; Mon, 11 Sep 2023 09:46:39 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="WI5Un/yt"; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 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=1694425599; 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=pHpuYVUzN3jckjN0g3IoL6/kLBn9YHZf3O2ocrsGP0s=; b=gh/+UNVm2w4UQB7BiKmTojowwKJym2TlvXDj9ZV2vxVpTejum42AC31eD6t8u5HzaxwliJ NbeZNyiuYjCVuVCMY2Fsg6cAcY+HyVTnPG15Iuc+nUzOKam0FvPm/uCeK8HKOgQ/2SEjVd 7LmhNeRCCR5OB8gs5NW1zt56sYxLkzU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425600; a=rsa-sha256; cv=none; b=lLWbFbpgSmKOVMqP7W/Qox4IBD00ZYdLslh/bJJRAGo+LYiW+4JsJypm7tS+NrPA8O2lfV Yw//kWu6Wevznlx6g/wffM8vMG0lRNdLb0gctIUFfZ7GWox/p1AN+7aatdk89uo6cmwfZQ 9bnud0DdAlabquMxYk/tHVVRy1fUPbE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="WI5Un/yt"; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1c3c4eafe95so464795ad.1 for ; Mon, 11 Sep 2023 02:46:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425598; x=1695030398; 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=pHpuYVUzN3jckjN0g3IoL6/kLBn9YHZf3O2ocrsGP0s=; b=WI5Un/ytlvn36q4LjWMWBwWTJRWOyDw2pg/XPJZ3QqQ5NQwwJD9r5eyGkB0qicOjrB b2T2g7kAdIHQarkjfPBj8EfI/Jaj6hgK8hJgmJ8JdRSkz+YqqY710GRvAY1KPZMxTc2L yxNjjKaTIWbcq+z3JkIH/pizX/gAvQb8j3aEMuIx3bskH4x6T+mjc2SZZRJL7SRHVbcY b5+o9r7bBLCr3GoImWV4Fdt2pbXH7ce/QGFK5n1sv/6c32PjDuejSWrhCX7LtM+ftHwR PwY10UiHRATqXdkxSKXgCIPWaD2wCBnGgFu7C4fu9vB8WH8ylwX3oildI3mQ7J78qcyu PWkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425598; x=1695030398; 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=pHpuYVUzN3jckjN0g3IoL6/kLBn9YHZf3O2ocrsGP0s=; b=vqaCGjFeHZEBjk50OvR40tiAnat/WiDhIycvuRCBNQhwzYkkJXWxX2RW4uVcxE30Nl /Bjm2eqWbHysAFBw3FCr6D6vEIRtJydIC6pMvRGR8y8R6wv8h2JWWF1U/Ekfr6fC5Vrv eK8PLW0Z8oApa3hqQ4WyR1cy87Hqy/54+jj5QimtQ9Zfe6SVhByj3e1gsMjcA29unJVn SeaNn+XLX5BXLXRdrW5iM3Q2Qpc4PGPI+QPHD96QRmEmgMVEAi/QdPqAJrRxcR6gnUum xBD1WuFSlro34P6Y/DlYKuCbqAEX0mj3boPqfkT9UJU4lcNegOR8v/7kOFDulW8SgwMP v5yA== X-Gm-Message-State: AOJu0YyBHKCPIw+/SWX9mjKmNlaYY+aqmMaaE3B2GNS1yC9IV1hfl1oD HMatY4Dj3+Dve8B0/IjG6ugdHg== X-Google-Smtp-Source: AGHT+IE4diKAs4V0ZLkbBcPD23s8Bxj5IuLRqCIy3bQ9Nrv1l59K6Ek3oQa6VjaqyWVA5u0uD7+kGg== X-Received: by 2002:a17:903:2843:b0:1c3:a4f2:7cc1 with SMTP id kq3-20020a170903284300b001c3a4f27cc1mr5315057plb.5.1694425598648; Mon, 11 Sep 2023 02:46:38 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:38 -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 , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org Subject: [PATCH v6 10/45] NFSv4.2: dynamically allocate the nfs-xattr shrinkers Date: Mon, 11 Sep 2023 17:44:09 +0800 Message-Id: <20230911094444.68966-11-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: A6214C0019 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 91mi17nh13ae6tkhea6o9g1bhtz7z498 X-HE-Tag: 1694425599-897296 X-HE-Meta: U2FsdGVkX18h65p0ipATTiwcwh9/N+IR7GFvE3Ohk2+/1V1yTUqyNfpARFanPiORR1M0LIsPVCVF8ct4KBMBVmwo4vCixzL+EWLkEfKF0hVo72ypg1trNcho5HttjmsvzBaeTi3V7Jf5BB60kiLj6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k+9fNe7TgrzLjhYWOaL2pyoBiSiwmVqjX7z77ps/9mIhScCORZNtWarUGYai2pvmp6QpV3ZvVUno6VJwSTXWBIptqafqcTi7W4OYX9VQaNicdwEn3Fla+La+QWEX15neMD5Jm7ENox6aNtgdUvUvhI62iJdVuBliqQrDTAUXvsFU7d4mBJl9zYOfp96JxxaM8GMSlxyz9hvvsdo84NtAqYh3EhtjAJjanzjloJnkR6Y3IihG5i1WdQhdaAWb5sBNCBLeRC3dxf+wzu0wppGxAGdMOUC1CjbKYbowMmz4eKXQv2DPgSctp69p1w== 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 nfs-xattr shrinkers. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Trond Myklebust CC: Anna Schumaker CC: linux-nfs@vger.kernel.org --- fs/nfs/nfs42xattr.c | 87 +++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/fs/nfs/nfs42xattr.c b/fs/nfs/nfs42xattr.c index 911f634ba3da..2ad66a8922f4 100644 --- a/fs/nfs/nfs42xattr.c +++ b/fs/nfs/nfs42xattr.c @@ -796,28 +796,9 @@ static unsigned long nfs4_xattr_cache_scan(struct shrinker *shrink, static unsigned long nfs4_xattr_entry_scan(struct shrinker *shrink, struct shrink_control *sc); -static struct shrinker nfs4_xattr_cache_shrinker = { - .count_objects = nfs4_xattr_cache_count, - .scan_objects = nfs4_xattr_cache_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_MEMCG_AWARE, -}; - -static struct shrinker nfs4_xattr_entry_shrinker = { - .count_objects = nfs4_xattr_entry_count, - .scan_objects = nfs4_xattr_entry_scan, - .seeks = DEFAULT_SEEKS, - .batch = 512, - .flags = SHRINKER_MEMCG_AWARE, -}; - -static struct shrinker nfs4_xattr_large_entry_shrinker = { - .count_objects = nfs4_xattr_entry_count, - .scan_objects = nfs4_xattr_entry_scan, - .seeks = 1, - .batch = 512, - .flags = SHRINKER_MEMCG_AWARE, -}; +static struct shrinker *nfs4_xattr_cache_shrinker; +static struct shrinker *nfs4_xattr_entry_shrinker; +static struct shrinker *nfs4_xattr_large_entry_shrinker; static enum lru_status cache_lru_isolate(struct list_head *item, @@ -943,7 +924,7 @@ nfs4_xattr_entry_scan(struct shrinker *shrink, struct shrink_control *sc) struct nfs4_xattr_entry *entry; struct list_lru *lru; - lru = (shrink == &nfs4_xattr_large_entry_shrinker) ? + lru = (shrink == nfs4_xattr_large_entry_shrinker) ? &nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru; freed = list_lru_shrink_walk(lru, sc, entry_lru_isolate, &dispose); @@ -971,7 +952,7 @@ nfs4_xattr_entry_count(struct shrinker *shrink, struct shrink_control *sc) unsigned long count; struct list_lru *lru; - lru = (shrink == &nfs4_xattr_large_entry_shrinker) ? + lru = (shrink == nfs4_xattr_large_entry_shrinker) ? &nfs4_xattr_large_entry_lru : &nfs4_xattr_entry_lru; count = list_lru_shrink_count(lru, sc); @@ -991,18 +972,34 @@ static void nfs4_xattr_cache_init_once(void *p) INIT_LIST_HEAD(&cache->dispose); } -static int nfs4_xattr_shrinker_init(struct shrinker *shrinker, - struct list_lru *lru, const char *name) +typedef unsigned long (*count_objects_cb)(struct shrinker *s, + struct shrink_control *sc); +typedef unsigned long (*scan_objects_cb)(struct shrinker *s, + struct shrink_control *sc); + +static int __init nfs4_xattr_shrinker_init(struct shrinker **shrinker, + struct list_lru *lru, const char *name, + count_objects_cb count, + scan_objects_cb scan, long batch, int seeks) { - int ret = 0; + int ret; - ret = register_shrinker(shrinker, name); - if (ret) + *shrinker = shrinker_alloc(SHRINKER_MEMCG_AWARE, name); + if (!*shrinker) + return -ENOMEM; + + ret = list_lru_init_memcg(lru, *shrinker); + if (ret) { + shrinker_free(*shrinker); return ret; + } - ret = list_lru_init_memcg(lru, shrinker); - if (ret) - unregister_shrinker(shrinker); + (*shrinker)->count_objects = count; + (*shrinker)->scan_objects = scan; + (*shrinker)->batch = batch; + (*shrinker)->seeks = seeks; + + shrinker_register(*shrinker); return ret; } @@ -1010,7 +1007,7 @@ static int nfs4_xattr_shrinker_init(struct shrinker *shrinker, static void nfs4_xattr_shrinker_destroy(struct shrinker *shrinker, struct list_lru *lru) { - unregister_shrinker(shrinker); + shrinker_free(shrinker); list_lru_destroy(lru); } @@ -1026,27 +1023,31 @@ int __init nfs4_xattr_cache_init(void) return -ENOMEM; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_cache_shrinker, - &nfs4_xattr_cache_lru, - "nfs-xattr_cache"); + &nfs4_xattr_cache_lru, "nfs-xattr_cache", + nfs4_xattr_cache_count, + nfs4_xattr_cache_scan, 0, DEFAULT_SEEKS); if (ret) goto out1; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_entry_shrinker, - &nfs4_xattr_entry_lru, - "nfs-xattr_entry"); + &nfs4_xattr_entry_lru, "nfs-xattr_entry", + nfs4_xattr_entry_count, + nfs4_xattr_entry_scan, 512, DEFAULT_SEEKS); if (ret) goto out2; ret = nfs4_xattr_shrinker_init(&nfs4_xattr_large_entry_shrinker, &nfs4_xattr_large_entry_lru, - "nfs-xattr_large_entry"); + "nfs-xattr_large_entry", + nfs4_xattr_entry_count, + nfs4_xattr_entry_scan, 512, 1); if (!ret) return 0; - nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker, &nfs4_xattr_entry_lru); out2: - nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker, &nfs4_xattr_cache_lru); out1: kmem_cache_destroy(nfs4_xattr_cache_cachep); @@ -1056,11 +1057,11 @@ int __init nfs4_xattr_cache_init(void) void nfs4_xattr_cache_exit(void) { - nfs4_xattr_shrinker_destroy(&nfs4_xattr_large_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_large_entry_shrinker, &nfs4_xattr_large_entry_lru); - nfs4_xattr_shrinker_destroy(&nfs4_xattr_entry_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_entry_shrinker, &nfs4_xattr_entry_lru); - nfs4_xattr_shrinker_destroy(&nfs4_xattr_cache_shrinker, + nfs4_xattr_shrinker_destroy(nfs4_xattr_cache_shrinker, &nfs4_xattr_cache_lru); kmem_cache_destroy(nfs4_xattr_cache_cachep); }