From patchwork Mon Sep 11 09:44:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379055 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 2C78FEE57DF for ; Mon, 11 Sep 2023 09:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6AB16B0198; Mon, 11 Sep 2023 05:45:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1AF56B0199; Mon, 11 Sep 2023 05:45:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABBBD6B019A; Mon, 11 Sep 2023 05:45:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 97DA76B0198 for ; Mon, 11 Sep 2023 05:45:17 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6CEEB14091A for ; Mon, 11 Sep 2023 09:45:17 +0000 (UTC) X-FDA: 81223833474.13.1032B4A Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf26.hostedemail.com (Postfix) with ESMTP id 91A4D140019 for ; Mon, 11 Sep 2023 09:45:15 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SvirpOO0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1694425515; 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=ORW0XZa1kdIcIaxWvFs44fwaNLWoHRo/PB9DFB9bcwM=; b=dfoiNir2yGP84Cn97YNpB+re3Php+n4/oiNUa8xKT31mxVgEvLRbsHs9eqIBMX/PeicHVH 2mmjCVsCnhyzskex+DNoBs7+UKI2agUWcQ7ocrolBr6jvDVdaN9u31piy8g5vcgnxA+b0H hFOhaUJE6FMvAwlkHFexJv2VccAAFCg= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SvirpOO0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425515; a=rsa-sha256; cv=none; b=WdaV2UzZ7SlKzcnGDZE3OCIqThtBFeuDaZc0hRN8LcFXTBS5futcGOEDoAoSLNtOs2MsLd wnO9g7vwezSxE8U8NpkOYzn/5o6qxP3BVzn/+98Ustu7Z+yOxi58ONyxIwhetKPW0hwRxX LlRcJCfqIaJwgkMd82gmNBp3waH/ZrQ= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-68cc1b70e05so1080911b3a.1 for ; Mon, 11 Sep 2023 02:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425514; x=1695030314; 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=ORW0XZa1kdIcIaxWvFs44fwaNLWoHRo/PB9DFB9bcwM=; b=SvirpOO0XaTgPOFtnxAGrJPG/klkgx4V9SWV+DbmOwbjn9wnJ4yDA+XbhmHNgxBTky uO3Jx/McMKbzzsTmmO/2I87lbtRCYm4aI7D4Q888p2/gZrWUHMjtggRsQq5H/yVgaws3 SpvegXS1eOfuEYL7cOOJ57tJ0UY0O7kkFvkXF3NUsuo+uOtVqguJ5y+VAwX6xeUtTk05 x34OW0+5SeJKSfnoFaccSBjqRUo4rIZvVhJ3mnHXcljpqRXErg2tKi+xal7kuFfY/8dp ycfBUggTVIRRt8erOp6ncnZTe1lybintF941cvYZLsLkdkI6qu7ecV+1NOyoupELY5NR zevg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425514; x=1695030314; 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=ORW0XZa1kdIcIaxWvFs44fwaNLWoHRo/PB9DFB9bcwM=; b=AnfHt4fcoA0cJec/excOYbCLQrBuDLv70aYhUo5yheB6dsSdhGB3anTfMhEsxHiIF2 NnUPTDq+cH7ey92u7N1M8PAx89fyVyAS9JMd7tiwmLaVcp+eVGIpwoE7EpnUkcow3Zg6 +EHbdBIG/YbSAIIjTGxMXmqKA0O/UU1TUk7pkpGCoQqIIt5Rym0Hr64xDJ6cCOme8HlX n3NKREgEEa9UUkULNX0/S6pimEYYXpY1uk/mb7GRBSFCek01j2z/Qp6EIH3A2i94Snpy 5tKlwW/2qe92fSh/xiEy7SgpDkLkRG+NedQVGlZUSOXQ4GmNsYpx4Tz6pVu9J4+ut7ZQ UHWg== X-Gm-Message-State: AOJu0YzcH5WH1PgYZh4RvOBQSJLM1AJ+rGZEi+kcNpmo2s2mWGFRRYzB gYLBj9enOTLt8UQ1hSXzATYLsQ== X-Google-Smtp-Source: AGHT+IGWvi6MsHJLwd4gCfiQXvrOfPsJ8uQybdIBEiKfHwB8vL0KtWY2tJHiN25CKbq01B6PFU+waw== X-Received: by 2002:a05:6a20:3d24:b0:133:6e3d:68cd with SMTP id y36-20020a056a203d2400b001336e3d68cdmr12844869pzi.3.1694425514413; Mon, 11 Sep 2023 02:45:14 -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.45.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:14 -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 Subject: [PATCH v6 01/45] mm: shrinker: add infrastructure for dynamically allocating shrinker Date: Mon, 11 Sep 2023 17:44:00 +0800 Message-Id: <20230911094444.68966-2-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-Rspam-User: X-Stat-Signature: z885583a5mu5mxzwgmenc67oc9n5pu49 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 91A4D140019 X-HE-Tag: 1694425515-143357 X-HE-Meta: U2FsdGVkX18GZNnh0GzQuoM7rIsDZXJs+Bzs4tQmugVzF2u1m8dFOu9nWswRX533X0EyTBPQMNzYYd09E6mtuS6/M7nuZ/1uNRXHlUakW4tFHDbnK+ChcBSHB5Wr0cQoQ64ZHgjYzqfPUE6V1iqFUA5/RCkOLnJZZ/sBqFiiZ+HLXHJMGFXMN/kQHb538h8SSu0nJbVLb5ELiT5zooXgPzY7G/XHSlqo2TDclrnFDkhLAI7aS8SxeuinRJclSJ7K3CnizHzYFpMjcYwlMqd2bl5tG3osKfnTcw2IExVfuc4ot/9fJZ7EtMDQhXDhDJzOVlhraStHaj+uiwbF/jnexha+CGO7YWsFTvWw9tnASgaYEwWYmRBE6Qw/+YcqMANzjwf0P4DMI5mw0t8GCeeQDt7iA3gC46bp1CnE6u1sYegpGMJEJVLReQeZ/lMZ6B5KXNLoOCEnAtXvRZdIWqWJjdpkilsMJdxKDrrbYCwxyBtSxXQYOHpjw/8k7jNmcKUISIlshmdWtFMmy2g1lsnj2I6CB8xhnlK+NoPlzmcH6yfqC2BCFMn/3IsRtIV6TDbZqmNEyyWHwuOuBOltWdAS+WqCvHL286cqTfWu8SK4VtKYo25inxck4ker7tYHkz/c5M2Sw17hey4n37k9LQehBOLBOGMDZvhU57m+ws6vq4fKtcK9GyIxeSkVcWySzdrafrjz5pgHswN1wv/y4nl5WipcJu3H153eUtxpI6zLK6gJk587GZrZ5fkcI9u+crBO1ljmYs3tF5m3dDp+yI1SwgMGi7pC9QFLm4UMZfhndnWPub+K8+9hqtkaHLEQmCyiS4CSCB7ss1oHuloJWYHFakk/nYR+SCe7InWV0BlvXwwa7haWDStHzb5Xosb78PBLEHzM+exaK5p8qnWqkV6cU5VT2WS46ydh37XoJ1sVjK0BbqfvVmCtb5HvucTKxkCitA9619gJgPvb0BilYeZ ehIMV6iD H/WAYsM42CtpSD+7zDwgr8hg4Cf06oHMb4pwDiiyAdCNKG8+pYaGBFBAqgowtxKF3GRnLvL0i3eJMhNQIQ1Wrvt1o64UEB4EyDyxvoRqJEh5aV6ntAA32PwdXTJ6N0flFFxQN4Q+D7ttn4DyKSoN67itp2eP+whDnxlm59B2jwtKsWc92kaLh3sa5qJZf7K2+T5ejqXcOOUBV5PZjPkMktyXJfQSu3vJA8+P+mBqJBOi3zzP8r1U4YMo17jM6gfkyBIh/vcrO63zYnKOxBIGsBPrdD40J+/swOS0X9ifgskh1h/WwoUcF7SZdF7IRLPvCMFPbM6lLl3q62A7LOB064whXl4TyhM1OvxC61HEpQymWViVntZ9hvUd4cb04fH/xhxPo5Iqx3q41fgbCvshGSgdv/nSFCQ5X5mzo 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: Currently, the shrinker instances can be divided into the following three types: a) global shrinker instance statically defined in the kernel, such as workingset_shadow_shrinker. b) global shrinker instance statically defined in the kernel modules, such as mmu_shrinker in x86. c) shrinker instance embedded in other structures. For case a, the memory of shrinker instance is never freed. For case b, the memory of shrinker instance will be freed after synchronize_rcu() when the module is unloaded. For case c, the memory of shrinker instance will be freed along with the structure it is embedded in. In preparation for implementing lockless slab shrink, we need to dynamically allocate those shrinker instances in case c, then the memory can be dynamically freed alone by calling kfree_rcu(). So this commit adds the following new APIs for dynamically allocating shrinker, and add a private_data field to struct shrinker to record and get the original embedded structure. 1. shrinker_alloc() Used to allocate shrinker instance itself and related memory, it will return a pointer to the shrinker instance on success and NULL on failure. 2. shrinker_register() Used to register the shrinker instance, which is same as the current register_shrinker_prepared(). 3. shrinker_free() Used to unregister (if needed) and free the shrinker instance. In order to simplify shrinker-related APIs and make shrinker more independent of other kernel mechanisms, subsequent submissions will use the above API to convert all shrinkers (including case a and b) to dynamically allocated, and then remove all existing APIs. This will also have another advantage mentioned by Dave Chinner: ``` The other advantage of this is that it will break all the existing out of tree code and third party modules using the old API and will no longer work with a kernel using lockless slab shrinkers. They need to break (both at the source and binary levels) to stop bad things from happening due to using unconverted shrinkers in the new setup. ``` Signed-off-by: Qi Zheng Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/linux/shrinker.h | 7 +++ mm/internal.h | 11 +++++ mm/shrinker.c | 102 +++++++++++++++++++++++++++++++++++++++ mm/shrinker_debug.c | 17 ++++++- 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 6b5843c3b827..3f3fd9974ce5 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -70,6 +70,8 @@ struct shrinker { int seeks; /* seeks to recreate an obj */ unsigned flags; + void *private_data; + /* These are for internal use */ struct list_head list; #ifdef CONFIG_MEMCG @@ -95,6 +97,11 @@ struct shrinker { * non-MEMCG_AWARE shrinker should not have this flag set. */ #define SHRINKER_NONSLAB (1 << 3) +#define SHRINKER_ALLOCATED (1 << 4) + +struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); +void shrinker_register(struct shrinker *shrinker); +void shrinker_free(struct shrinker *shrinker); extern int __printf(2, 3) prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/internal.h b/mm/internal.h index 0471d6326d01..5587cae20ebf 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1161,6 +1161,9 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, #ifdef CONFIG_SHRINKER_DEBUG extern int shrinker_debugfs_add(struct shrinker *shrinker); +extern int shrinker_debugfs_name_alloc(struct shrinker *shrinker, + const char *fmt, va_list ap); +extern void shrinker_debugfs_name_free(struct shrinker *shrinker); extern struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, int *debugfs_id); extern void shrinker_debugfs_remove(struct dentry *debugfs_entry, @@ -1170,6 +1173,14 @@ static inline int shrinker_debugfs_add(struct shrinker *shrinker) { return 0; } +static inline int shrinker_debugfs_name_alloc(struct shrinker *shrinker, + const char *fmt, va_list ap) +{ + return 0; +} +static inline void shrinker_debugfs_name_free(struct shrinker *shrinker) +{ +} static inline struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, int *debugfs_id) { diff --git a/mm/shrinker.c b/mm/shrinker.c index a16cd448b924..201211a67827 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -550,6 +550,108 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, return freed; } +struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) +{ + struct shrinker *shrinker; + unsigned int size; + va_list ap; + int err; + + shrinker = kzalloc(sizeof(struct shrinker), GFP_KERNEL); + if (!shrinker) + return NULL; + + va_start(ap, fmt); + err = shrinker_debugfs_name_alloc(shrinker, fmt, ap); + va_end(ap); + if (err) + goto err_name; + + shrinker->flags = flags | SHRINKER_ALLOCATED; + shrinker->seeks = DEFAULT_SEEKS; + + if (flags & SHRINKER_MEMCG_AWARE) { + err = prealloc_memcg_shrinker(shrinker); + if (err == -ENOSYS) + shrinker->flags &= ~SHRINKER_MEMCG_AWARE; + else if (err == 0) + goto done; + else + goto err_flags; + } + + /* + * The nr_deferred is available on per memcg level for memcg aware + * shrinkers, so only allocate nr_deferred in the following cases: + * - non memcg aware shrinkers + * - !CONFIG_MEMCG + * - memcg is disabled by kernel command line + */ + size = sizeof(*shrinker->nr_deferred); + if (flags & SHRINKER_NUMA_AWARE) + size *= nr_node_ids; + + shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); + if (!shrinker->nr_deferred) + goto err_flags; + +done: + return shrinker; + +err_flags: + shrinker_debugfs_name_free(shrinker); +err_name: + kfree(shrinker); + return NULL; +} +EXPORT_SYMBOL_GPL(shrinker_alloc); + +void shrinker_register(struct shrinker *shrinker) +{ + if (unlikely(!(shrinker->flags & SHRINKER_ALLOCATED))) { + pr_warn("Must use shrinker_alloc() to dynamically allocate the shrinker"); + return; + } + + down_write(&shrinker_rwsem); + list_add_tail(&shrinker->list, &shrinker_list); + shrinker->flags |= SHRINKER_REGISTERED; + shrinker_debugfs_add(shrinker); + up_write(&shrinker_rwsem); +} +EXPORT_SYMBOL_GPL(shrinker_register); + +void shrinker_free(struct shrinker *shrinker) +{ + struct dentry *debugfs_entry = NULL; + int debugfs_id; + + if (!shrinker) + return; + + down_write(&shrinker_rwsem); + if (shrinker->flags & SHRINKER_REGISTERED) { + list_del(&shrinker->list); + debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); + shrinker->flags &= ~SHRINKER_REGISTERED; + } else { + shrinker_debugfs_name_free(shrinker); + } + + if (shrinker->flags & SHRINKER_MEMCG_AWARE) + unregister_memcg_shrinker(shrinker); + up_write(&shrinker_rwsem); + + if (debugfs_entry) + shrinker_debugfs_remove(debugfs_entry, debugfs_id); + + kfree(shrinker->nr_deferred); + shrinker->nr_deferred = NULL; + + kfree(shrinker); +} +EXPORT_SYMBOL_GPL(shrinker_free); + /* * Add a shrinker callback to be called from the vm. */ diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index e4ce509f619e..38452f539f40 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -193,6 +193,20 @@ int shrinker_debugfs_add(struct shrinker *shrinker) return 0; } +int shrinker_debugfs_name_alloc(struct shrinker *shrinker, const char *fmt, + va_list ap) +{ + shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); + + return shrinker->name ? 0 : -ENOMEM; +} + +void shrinker_debugfs_name_free(struct shrinker *shrinker) +{ + kfree_const(shrinker->name); + shrinker->name = NULL; +} + int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) { struct dentry *entry; @@ -241,8 +255,7 @@ struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, lockdep_assert_held(&shrinker_rwsem); - kfree_const(shrinker->name); - shrinker->name = NULL; + shrinker_debugfs_name_free(shrinker); *debugfs_id = entry ? shrinker->debugfs_id : -1; shrinker->debugfs_entry = NULL; From patchwork Mon Sep 11 09:44:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379056 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 0E0EFEE7FF4 for ; Mon, 11 Sep 2023 09:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6F606B019A; Mon, 11 Sep 2023 05:45:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1F4F6B019B; Mon, 11 Sep 2023 05:45:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9108B6B019C; Mon, 11 Sep 2023 05:45:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 805306B019A for ; Mon, 11 Sep 2023 05:45:27 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 534B340908 for ; Mon, 11 Sep 2023 09:45:27 +0000 (UTC) X-FDA: 81223833894.28.AB00839 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf10.hostedemail.com (Postfix) with ESMTP id 7E0DBC0008 for ; Mon, 11 Sep 2023 09:45:25 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LPxQp7qZ; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425525; a=rsa-sha256; cv=none; b=wrIteeUz1wF/YC+B7FynYZy/06mBfdZKYZ9FKKNO5YX1XVKA+CqELYjskwxezruyZ2J79M oPuQMnwjJKgLoPs9GSIFaivkI1sXtEW/kWibYR6d1wXcMry7iZCsPMQJDSdTKzBnVqB1SB pt/P7mSM/cma3oDWyj2Yj+2zqmoA3AQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LPxQp7qZ; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 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=1694425525; 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=igTSDR/vKXgPwxt8Nsf/dMSfVCUUURBFbV4iu+jj8kI=; b=jX6rimxGFqdY4HieC19FSYv+Nwhtm+/znkDWljE/kXgeherKEI/DHZGDI6z9ATqDI5Yg6O Mhp3RarYAa8Ygzn9hdOnRetkfRCSjx1pb4gHzTdtQcAGYUBIOQW/xYOunwKeSlFz7bdmEk oDZW2X73ms82z9IdERySVzXv/yUeV8Y= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1bf1876ef69so11137135ad.1 for ; Mon, 11 Sep 2023 02:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425524; x=1695030324; 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=igTSDR/vKXgPwxt8Nsf/dMSfVCUUURBFbV4iu+jj8kI=; b=LPxQp7qZ35iqC2pFP2+qB4poYnKjIU0iZ6Qez0JPK9IWwZUfQJwc09mrGSUS8vu23g IRJrJhhPlqKA0KxuPkoyTd/TiWbpe6RiXKVY/JtHTNSBCO3wca2CylBjBt4dFaARYj7f oiHjoPxfz0mlUpO2hR3xKZxIbZ7lPjgpFGeB2qpXeIQorFdL+bXs6bUgrsGX0bWorMVF 9USaKHnpffsaEZVUl45CGYftK7XRRREkcv+e8uhKbWrRdbv6hKUBBVHBQjTTZwjQ+bqH HhfA0DLpJLCOgsRsh117sEC5eI4gRQhHRYXD310xFx3fBKPN/XfeYFZMKQC873fKAhSG pL+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425524; x=1695030324; 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=igTSDR/vKXgPwxt8Nsf/dMSfVCUUURBFbV4iu+jj8kI=; b=iJCLBjreYAvqkF+0423ERHdTRTfpfwL+fek54iRAjojrUNtNw5/36kAtnN6vBfd75f uZwdwBLSr2Jfx8zqNssD8K2Rj6Ji8eDSvEZ7fHFetCxCpaav+7ElSVaq8233Jlc3Uy5R Ci312GQk9ytFbIjdW+chTE1+0dBJTTWmHg0Moj+B/AZEij1Ucm1FIlsEQ4vXOp4S01jP JBCOMEfDRQRbMFwfqd8xRQGmjubO1ign4mOAsEg6+oDxdMQsDUOjCKWB2spQZX+qZVry BC2IWUlghIQPIPJnMroiBankApYQaIAooDS6NStBqGpjDYyeSqOog6tVEgalDiPfdtZv t9Kw== X-Gm-Message-State: AOJu0YwKIx0KdCWw9G/2amH7rw3KaWwOo56TCJR9JUcM83AnC2GyJLvd Ozco24AXmiy08tY1OLlGxIQlUA== X-Google-Smtp-Source: AGHT+IGwCbRmnmWBiffPOJTl07r9rRbQgpxezDjUTflYdm1L6Q4G0DETGg6o4mxqN/MXYenR4q9s6g== X-Received: by 2002:a17:902:e5c7:b0:1c1:fc5c:b34a with SMTP id u7-20020a170902e5c700b001c1fc5cb34amr10655164plf.3.1694425524206; Mon, 11 Sep 2023 02:45:24 -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.45.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:23 -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 , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , kvm@vger.kernel.org, x86@kernel.org Subject: [PATCH v6 02/45] kvm: mmu: dynamically allocate the x86-mmu shrinker Date: Mon, 11 Sep 2023 17:44:01 +0800 Message-Id: <20230911094444.68966-3-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-Server: rspam08 X-Rspamd-Queue-Id: 7E0DBC0008 X-Stat-Signature: wm6c3mb9urcuom8a4w6m3hdqymc5xhuw X-Rspam-User: X-HE-Tag: 1694425525-516701 X-HE-Meta: U2FsdGVkX1+4eAhIRB3Gc8OWMYb4yEKTZKuT8ZAx+0B/0kq9KBsnxreqzTNuBMQ+4w6lFjaJGnyWqpkSSCk1RUY3ZtiZ/yI6mO8L4vQDAlKAnlOxJmFLAXtcyo7q1Jfv5oawr52KpQ1kYbloyKabrnom6nd6ZvrkW7gzdx/AxhOe3Ob0fb/yvzBwaZ7/a0LkSOQ1pDgZvEw9gfs6osFsVkU//9FOvsmqV9j8ASDy8mU7T1IchzHhmRIE8KRkTAbsve87AnWcH9PNI8RxganmT2EzsuW69Vdux4cCrhT7OPOyGwqPAkKjCtCJie0/lDiDGVxpnQGCK1I0/n8yGod9f87yPjZB2whS3/2KsbyNHbtcvWD1FDgCMrz/IeSQnFKRIA8WESaRgIiB/jr0XyDHNRi/XLWI5Z295KDzRJdoOW9Tr5UfO+Abh1A2NBxn7T5zMcV4f9zs+wq31uspPEUuh8FSGHXSBRcTEY+7+11uODUSr8myQxAfTPdMCvzEO2ib5aOmY4yIGEbtFwgsEs1vCBYf+SXlP9Pyq6f9ieYWcycqFMvkC1XJU92PZqQaDnjoiAbsP+mQjV2IG18v4Z2yF+t2F77MXSCoTgfzBB8zpuBEEOhVKo+G9LYxVmH6D5eqDYBPX6xVxe8jfBDlfgJIGkhgnSEjoD5aZBdrBVfq3R++x7XWEeylMNc85JDidQrVrp82thoCo+z/oeJnE5JFRszaQ/ZfdPqSWXgQxYI4MPFDSjbh6fHF5EKY1kr1ZjOXHq4+cvKs8W1ycETX5Vr9IgqSptc7iFhHU1lO1OIpKhUeCWqZwALnSb+nFGLwOgqaDPgrFPLc5iA5XFTFJbOEAyVIzPiY0x9Kik7Y/vffWwohdHfnlIHUGEFaIiJ2b4mbGSc9Jd15GHPlVVds6B63gb6numKWnluKCeL/pzEc45iNvznc9q6Ro7kw+6E4xHzX1IA6dv2EM9Ni0XSOmpx uTXg3g88 bDE9WWZAztXXWIZam+qa4gwuQ3OoPNV+YTnCbBoZWnhoQhv07r+45nkQAe4v0uo+xGds1+AMD9kjz69e5jNnI8NtCmLLlJAxBLn1NjnzQGBQNX1d3CAVY8pDKfLcJmQShzws0Ux8QA9qQNIMdA0Vr9Rn7zFqWg+4Ss8HuS2X07xg8aidvBalnxssDUvnt1ZMApZ94W8BwlJTDWUj0cF44s8MznEASNE5EHByJcayXM4vL+ATLzimioBm3BYbYYWVFZrB49+LXbKbGzU4zPoV7LGBSwMODKwHbvdVkgj54Nqu31EvQxhLF3KihFtAFUmfbsuybuXRoMXPqwhbkqIAh/Lr9ooc+IEOQn0mtMJptrxoFW8fuY4ixKDchr7AfwvbLNdRHClSkfbLmCyZUD1QdVzfcaBSRNlVdM6WJjsbCVuU68D40PHZqRjqK6aWBrXRrOCVKmOrbFwyhdGOCrhvTPuDhX8Pplku6FrsrfDiNUsUkOdSVbJlVzru0oI4niolsqqPrLeO8H/TnXv8= 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 x86-mmu shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: kvm@vger.kernel.org CC: x86@kernel.org --- arch/x86/kvm/mmu/mmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index e1d011c67cc6..9252f2e7afbc 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6796,11 +6796,7 @@ static unsigned long mmu_shrink_count(struct shrinker *shrink, return percpu_counter_read_positive(&kvm_total_used_mmu_pages); } -static struct shrinker mmu_shrinker = { - .count_objects = mmu_shrink_count, - .scan_objects = mmu_shrink_scan, - .seeks = DEFAULT_SEEKS * 10, -}; +static struct shrinker *mmu_shrinker; static void mmu_destroy_caches(void) { @@ -6933,10 +6929,16 @@ int kvm_mmu_vendor_module_init(void) if (percpu_counter_init(&kvm_total_used_mmu_pages, 0, GFP_KERNEL)) goto out; - ret = register_shrinker(&mmu_shrinker, "x86-mmu"); - if (ret) + mmu_shrinker = shrinker_alloc(0, "x86-mmu"); + if (!mmu_shrinker) goto out_shrinker; + mmu_shrinker->count_objects = mmu_shrink_count; + mmu_shrinker->scan_objects = mmu_shrink_scan; + mmu_shrinker->seeks = DEFAULT_SEEKS * 10; + + shrinker_register(mmu_shrinker); + return 0; out_shrinker: @@ -6958,7 +6960,7 @@ void kvm_mmu_vendor_module_exit(void) { mmu_destroy_caches(); percpu_counter_destroy(&kvm_total_used_mmu_pages); - unregister_shrinker(&mmu_shrinker); + shrinker_free(mmu_shrinker); } /* From patchwork Mon Sep 11 09:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379057 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 F4119EE7FF4 for ; Mon, 11 Sep 2023 09:45:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AFEA6B019C; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 760B36B019D; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6293B6B019E; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4F0846B019C for ; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 25DEB12097A for ; Mon, 11 Sep 2023 09:45:37 +0000 (UTC) X-FDA: 81223834314.14.5725C4D Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf25.hostedemail.com (Postfix) with ESMTP id 1483CA001C for ; Mon, 11 Sep 2023 09:45:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GXFX1PNx; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 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=1694425535; 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=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=qsgnXq3Qxig2mCCqAfSjL6sL78IbAs2fhdtCYtktAf3rtql/DZilHTFJFqR/xTH4+ljsl8 D+WW+d7phskUizi6AEGtimZuO3hylu/U6mioKpmXGRZqH60WMedt9QP+16ssIxmpEvbm31 mTC1seJla/e0SU0XNAGrBwQOIK6c61k= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GXFX1PNx; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425535; a=rsa-sha256; cv=none; b=GA0M/kix9S2WvQBYXBH0NiQA6u5mGcs5JiDwCuCMTpgVkJOPFhQGboSSPf1BG4mXLyEqTq dB4ATKVZUCLwrZgUM5fNft3BfOPON4GJyn/neRDy7kem1nIVH1mQiQRGmqTXZ3NCp+E9jM 1+Dp9p7rYwojoLIRbUhP0WmC1N52Vpg= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-68cc1b70e05so1080979b3a.1 for ; Mon, 11 Sep 2023 02:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425534; x=1695030334; 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=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=GXFX1PNxTENCQ/IiNsCn3MZe2Y2SOh6ZjQtuH03JQVGgiZRZu8pIhQnD86Q9/o9CoU JyOmHYowFEW3nPVX2ATbHwgUNaRIw4wrhIYTPZVx8/9N8OdxCK+/2eaNbPOFU1RQv9bR 0y0J7Zuim26hSTUpJfQu+HbB7Hc6qkh8zNWdEyBPXng7pu0K9e3fR9UUAQwsAPIuT8Ba EIBj0iia+JYuqa+bo/zscBDFeQgYQHyRHAviWt43KF2XW0sVWM8yFHvwdJ3IpTnKj6+8 K3oujT/rfO8fV+PfVugXyrZ0FBwdVIWjMepN6lQXXpJEZFcWcKnePHY3tTItHqiHsKgV RBPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425534; x=1695030334; 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=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=DKvACvFBgD7CYE0obDYczp9RbdtnFtuU+WPjzDyi3u50JHSAjwPtw523y5aCwMZSxl dfEVmTv82NSM+DBxnSWNuKzBVsMZYUYX1bLV6mvJUke3tPZJqfTCRfDMNqEDmBCqAxlM IkXkTXkRYCHaHtEMiMIwH2fimcuAjDhT5i84vYoUeTig7CzgFn/EdyN+QV58+QJbrl8G ikic9AXFrXAJy7iX0HnwahP+1LqI7+UrXsW2GSCzQMZagIJ5jPTl9w+9FKfWXptkcB4K s0TV8SR3WP7ifbxQ2Cg5kl6fGU7e4/bFiZxjajloV/rtiOTrDblIqp6ExOcm6PnpIxm1 j0UA== X-Gm-Message-State: AOJu0Yzy+c16GfIQRUhHEcFVIyAZ5+H4xhul+1FjtLYDCO9N4M5B6Y1Q ieCBab0jRUUHjBibB3W1JVcBJQ== X-Google-Smtp-Source: AGHT+IFTLTKyDsfu1NylfkAEUjAx8ahS4NnLvg9xanza3vKrJB8S7jYrE7HTHnlVMC2Ur/FZ9D9EPw== X-Received: by 2002:a05:6a20:394c:b0:13d:7aa3:aa6c with SMTP id r12-20020a056a20394c00b0013d7aa3aa6cmr9989617pzg.0.1694425533979; Mon, 11 Sep 2023 02:45:33 -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.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:33 -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 , Carlos Llamas Subject: [PATCH v6 03/45] binder: dynamically allocate the android-binder shrinker Date: Mon, 11 Sep 2023 17:44:02 +0800 Message-Id: <20230911094444.68966-4-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: 1483CA001C X-Rspam-User: X-Stat-Signature: ad9oeypgnqjt887fytbyc9o4bqf4qc56 X-Rspamd-Server: rspam01 X-HE-Tag: 1694425534-292662 X-HE-Meta: U2FsdGVkX18TELv5l3Yxz41sv4P+40aT8BE7wvRVYtwmnVDBYrY6CsGjZkEvOEywBIuxHT08KUW9LvgujRg9fJvTXrbgDnHZvv6DWfFvNPYQEXGsze0xa81dvhB2qRBMNhstWmZJ2cCJRk53/8aAPRmVVoqftvXjlOGk1Kdqk/x4/ODmR4svWiUddYKkv4BIRsV/E4p6fa29hrxrQTSTJQKCfA0pmDF0+VRRd/Na8P1qJTdjhZ5GossAbxGjhlBFLImOjekkzKcDqLNytjdwlm0u6zZKvTNS60lGaeLchGRPDMBlWW8QsQ+fFf4PYl6TuahEK1SxHxSwEXjUBzEhG7X1RGbJOuedUADH62fmc5j+UPOWa1wZoK5DaVqnkyClJNphp63QXXEHuRxbXXmW/gxkLD7fCVDaIdKWR6xZqWrDLQ01soOvHp2LVLxx0Q90JmE5mOyuNEVfWARoGFcaKNUfC4dloNDWRrHTRsdmPLHR0HCEHq0rG0k4dVbIEg0gkVrGUVrwy68n52FS+hm5xcUCST9bpadAsdcV8lUrP/8x+SvDKOCS6xwrujFwhSh6yyflxVzhBoyK/XOW9r5Kta+SvF3ZHZyV1B/Hx2gtFybaE3YdNuelNO477eojikHyndvVmYIbHaa3azPI/c16zyo25oaJoOdle8RNZ5vonoZZ2vJ9NuND5hloHwdKcbbuoNq3EEKLztheq3bfqztRuQPvQM8Sj6OsBaW6n3JIfmFHh0xTD9ng/cT5H/I3MESpSQmIY9TY7777/BShPgV6HCkodJuFvKSGNnP55BlooFJRL0oGcPluji8FGWjrgnX7vJ2MTyhTHdtydphh+aULvwRc9ibLRvIPoBQUWQsww6YIuy8S9p4QOAu0dM/zazXutRKfQAhADOEQxSPaR8l0d07rO8uYRpFq88u9QNpR1vbDqTG0djnmBJYEEPl1VD/OQwlltil9ZS0mPCsH/5W YTCbeVBT TI/5MsQsGCSqvwY8RunRO8wtc+vSdRAJbE2iviXpOJ+NrJOoECkZLjo31z5oNMSenHr4thO6rz3VYF1raL0M5REz82/HAP3och5O6AGn/Bw0ElVh6dSkmtxS6Kom71UcXZgEJTEf7CkYpPAwlFbvva/nzaAJpMVDRp/QMQQXYV2YUtslj9xGjwE8cv1/+jZuPc9ltmOWC4wPOTM+mODhtP/4JQPtV1tHrs8+CLfEriY9ZC20o6LvmRtXZAFyFW6QTjFNvFKV7F1X1xa74hjGzfGgGRGC6k7J20fTNGZBZ5DlylOpj49ZArtVmuVkcAmnOoD+mbNwF6LPEac4j2iZMrAuHjic5CEDdClSVPVB9iX+CpVk4m5SANU/YaqxIPD6FxdUrgxu9dz777JK0XNrQ2TIovIEX6rI9lktxvaXM4st7tbGfecgrzh1TKQftuNhBhPI19QjzFBKJYQa69S0XT3PH3LnUK3lXuTWPvJDR7iWcAfMKHnMj7922GA== 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 android-binder shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Carlos Llamas CC: Greg Kroah-Hartman --- drivers/android/binder_alloc.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e3db8297095a..138f6d43d13b 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1053,11 +1053,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) NULL, sc->nr_to_scan); } -static struct shrinker binder_shrinker = { - .count_objects = binder_shrink_count, - .scan_objects = binder_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *binder_shrinker; /** * binder_alloc_init() - called by binder_open() for per-proc initialization @@ -1077,19 +1073,29 @@ void binder_alloc_init(struct binder_alloc *alloc) int binder_alloc_shrinker_init(void) { - int ret = list_lru_init(&binder_alloc_lru); + int ret; - if (ret == 0) { - ret = register_shrinker(&binder_shrinker, "android-binder"); - if (ret) - list_lru_destroy(&binder_alloc_lru); + ret = list_lru_init(&binder_alloc_lru); + if (ret) + return ret; + + binder_shrinker = shrinker_alloc(0, "android-binder"); + if (!binder_shrinker) { + list_lru_destroy(&binder_alloc_lru); + return -ENOMEM; } - return ret; + + binder_shrinker->count_objects = binder_shrink_count; + binder_shrinker->scan_objects = binder_shrink_scan; + + shrinker_register(binder_shrinker); + + return 0; } void binder_alloc_shrinker_exit(void) { - unregister_shrinker(&binder_shrinker); + shrinker_free(binder_shrinker); list_lru_destroy(&binder_alloc_lru); } From patchwork Mon Sep 11 09:44:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379058 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 D5365EE57DF for ; Mon, 11 Sep 2023 09:45:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B08A6B019E; Mon, 11 Sep 2023 05:45:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 760B26B019F; Mon, 11 Sep 2023 05:45:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 628EB6B01A0; Mon, 11 Sep 2023 05:45:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 506156B019E for ; Mon, 11 Sep 2023 05:45:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 288A9B3A13 for ; Mon, 11 Sep 2023 09:45:46 +0000 (UTC) X-FDA: 81223834692.03.E0AC962 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf05.hostedemail.com (Postfix) with ESMTP id 4578810001A for ; Mon, 11 Sep 2023 09:45:44 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hbFTNtZE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.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=1694425544; 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=hCA0ApwXV5FyQtvOpmWRZ9XMHHHCgvXZoPv/VlrFSS0=; b=ls7eJsbLXqph0I8f8nlWP83PdRG+3Lm+7BzYewwPbva6ThSrh0jPqVAkHxUcjwp0saqydq 4EISQ5pDhjQr8wpk4daWcfLeqBTVU3YwCm50CuC9UrKlrq3EryeGSpKEGO7FpcJXJaOUnI s+uC7KRJI8t6bUc0deFiSmqis+CDufo= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hbFTNtZE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425544; a=rsa-sha256; cv=none; b=JU/MLUtN9/OcTu2CAPz2NPdtqcgtiPOsD64oqpa1lyjAaahnXr4Il2MZ57cuwL6YsHYvU/ CsR8FZdnecxP8vps1DcbbhxnHHUmK/Bn0KM2/Rw4eBLYPJowNcNiLDHC+kmWioISBbhIfx TjpU86N2WJnsArpbLy8jf9ES1BX1ySc= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1befe39630bso9363855ad.0 for ; Mon, 11 Sep 2023 02:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425543; x=1695030343; 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=hCA0ApwXV5FyQtvOpmWRZ9XMHHHCgvXZoPv/VlrFSS0=; b=hbFTNtZEAJ8iCdH7gZG0k8TQujGOLvf0BN+4QlH8Mzfh1NcorCUqt054mqUmP/gosK PwS5/lbRhrNmY4xLYo3+0bEHFdMnv8Ik75/+DHKF5CEZZT974TtTCyhCauV4d9jT5XOC 0DPVZ4JEedvExbT7iSBFAzHc9PZ4W0FSMeU33XkqWdy9lN9Hw5zVTmnbUyAY2u1slDRb W+kkvtpXRSeRgF1hd53O5EtDgjgOVlq30Cp67waPCG1uoLJB9GuY2I2LqFrUHZiJedpx 2vCoQgFvMwwAG2BkqGJvvvW3UOdviuFdn7wnmfjgBnovCYY9OIWsa0C1EtFqo/SLG0kC M5DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425543; x=1695030343; 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=hCA0ApwXV5FyQtvOpmWRZ9XMHHHCgvXZoPv/VlrFSS0=; b=HPgC0agRmDKjDLKLyZe1TcGyPCViZJws09JRU09FcVp3GlSYO/VLsHtSn24Rd2C8aP E5jFw/fc124AFTZ11VGPv/iHD/Lt/2l+VErC4Qmn3myEx/VMswO3viEDI1E+hu1hCfSo +l3uVbquhjlv5aUwIigIPZL4tjHmGyDb3mJVQ+LI8EomWqJ3Oud5GTTyLVaoG4aQLqg9 ML7usmSBy0++K0W17k3M+JVYBm5XjKKbTx91jPuZEHbYYvD64SWpsrsji3mP5YhwDxXt Yp9ulr7P/M+TyHU8PKgjIEBNimqsjPnydnbJvPt+h1GhGVsab7zsRZHhWR/DQER3/qvu nLlA== X-Gm-Message-State: AOJu0YzPBFXOnXiuMbwtS1W1w7tccKybR7PWPjkijiOD5AD1xOrMntqd ZtACrie+KgtdUuIAO7DqQ6cYCw== X-Google-Smtp-Source: AGHT+IHdDCNX66HmyeFeumyllN+fvmvJwteuvjAREsMUnnfysYcrCUJrxwo3wRPJ4iCHNwAnAJyjKg== X-Received: by 2002:a17:902:ecd2:b0:1bb:ac37:384b with SMTP id a18-20020a170902ecd200b001bbac37384bmr11076107plh.6.1694425543157; Mon, 11 Sep 2023 02:45:43 -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.45.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:42 -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 , Daniel Vetter , Christian Koenig , Huang Rui , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v6 04/45] drm/ttm: dynamically allocate the drm-ttm_pool shrinker Date: Mon, 11 Sep 2023 17:44:03 +0800 Message-Id: <20230911094444.68966-5-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4578810001A X-Stat-Signature: mdggm3kkeunyuiqixewazymho6p1c3jt X-HE-Tag: 1694425544-995204 X-HE-Meta: U2FsdGVkX19W1KCS6Rt5zwFGKh5BxFSoLKxDtTGrto5n9AebLNRlJ7r6KaiThHxaSc7Gg50tSnVj7xHUeV9N1s34CFN9ZqGlyomihq3ybfgaZ743ObZz9+79NuPviF6fZG5FPv+/kCvlFuT4skISx3ZGRv/OHBbxGjyTs1lmkYMmjxadJqCnvWDHB5zW3IKCRx6HyIo98yQokRfBor9Iq4RDB45f9oLviZlb+LxKxnuuv8DT3iX13bGKM1b/ZR+qWCKs68cZhdztVne0MZIpVD49PJJY/FhSEV4SiVNUj9+Mm2nxqwC2msIp/0Lo9ITeDtS6KuCsVpKbbRcXPtQfmm8upZgpjkq74jyAllrKCgbBhykLMeZvuHJ9cWqjaDRvJcusjh2BUT4On6wnkmkOK2Q0uoFSXVOOOf+x7zI+ATdGb0wN30O/5EnR50WJEYMCI0IoWHZQx3t9coAJxwhTzQF2tQ1FJduyHCOXlegKNSodfEVKDxj7bB1ZsqxOk8WhbyxC+5NcVTRii/lgUmiYkszQmWKTpgmBieH8tzpVKZkP8mRQj2jRKOKiu8nd41Mo3NGCfWu/j8R4QeUuAUwL8GO0MR/1Iuwz5CogpPvByWTlKAvRyN73RVNYvzT4Hg7AfxsnekPNQB/u4llh+FZLeDxgL0cE5AOrZoz6hfN2SRZCu53GguvvLusdg3leti+h5KV6yd47dim4/R9mEEz/vj6vODa8os2yDsCtrLajkQ5ie9JYsLbeqbNX2Jcb+E+PEYZ1H9hdIdJPUAo8wEnzJ3Bvw8qLp4L3otYWWRfiKXHkn8t795qPYbctLdlHetqzEq7RAS1pFSd50l1XkhryCPufac+IdQU/o+EKoeElikZrohp+pC2Wij5e8hxeYWFFZvn4QuM5vGs5p78WOdH1rXHE7rtP25S6TERqi9q0LCNdOjdmm5aT1sPIWZq3nEoOkHwpztnpgCCRmCBpdFg FJCOK4E5 H0mb9Qi+9YM6a1NfJRMGDQZho6RWKZSMObR9RCRR6JVjdR1caJP6W6oYaDb7dRgjpvUCm/29xUsfbGYVFL4KY/8QdYE5SVXln47j/H86lPKxxFQCs4ceEdGXwY4RnUc3dn7Zl7FmiCXLXcLOkHxGMYtYi1PWQHSmEZJ0UxCvH6zzRIp458Ggr9H+BduspMavfQzq8rO1vgSZKVlMJMe0E9JoBzoZIFEVdUryKSIo/G2iQ9gNH9hh8ROnJFCba8k1xPDnLACGCp+NeK8kb2pj/hjgsdZ4HgVqi2VyKvs5bjOUEWrt8fSyEsqnYNztm69ZNgre/PJk0P4Ul2HZo8OvZtSIT8bZwZWECv0j01lK4d9ztqT+OGJ92v5LsObS68qLf9vULgxrUXyO15/MeJY3uEcW2sFhEW+YtcW/6S7rcAUcQ3ke2tTewdtUvv6J5V/gkaGGAwsB2gxDnbJ/dzHnP3/JiD5sSRN9otxcM6enLo+zqW0m6a7i3Z1TddOw4RmI6rQNXMZx9gwrlgvEj4Zvb4aOjP3AnZj8RPuLhp+IgQGT9b85lJDwIyHRnCf9RR1glodja 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 drm-ttm_pool shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Daniel Vetter CC: Christian Koenig CC: Huang Rui CC: David Airlie CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/ttm/ttm_pool.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 648ca70403a7..fe610a3cace0 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -73,7 +73,7 @@ static struct ttm_pool_type global_dma32_uncached[MAX_ORDER + 1]; static spinlock_t shrinker_lock; static struct list_head shrinker_list; -static struct shrinker mm_shrinker; +static struct shrinker *mm_shrinker; static DECLARE_RWSEM(pool_shrink_rwsem); /* Allocate pages of size 1 << order with the given gfp_flags */ @@ -749,8 +749,8 @@ static int ttm_pool_debugfs_shrink_show(struct seq_file *m, void *data) struct shrink_control sc = { .gfp_mask = GFP_NOFS }; fs_reclaim_acquire(GFP_KERNEL); - seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(&mm_shrinker, &sc), - ttm_pool_shrinker_scan(&mm_shrinker, &sc)); + seq_printf(m, "%lu/%lu\n", ttm_pool_shrinker_count(mm_shrinker, &sc), + ttm_pool_shrinker_scan(mm_shrinker, &sc)); fs_reclaim_release(GFP_KERNEL); return 0; @@ -794,10 +794,17 @@ int ttm_pool_mgr_init(unsigned long num_pages) &ttm_pool_debugfs_shrink_fops); #endif - mm_shrinker.count_objects = ttm_pool_shrinker_count; - mm_shrinker.scan_objects = ttm_pool_shrinker_scan; - mm_shrinker.seeks = 1; - return register_shrinker(&mm_shrinker, "drm-ttm_pool"); + mm_shrinker = shrinker_alloc(0, "drm-ttm_pool"); + if (!mm_shrinker) + return -ENOMEM; + + mm_shrinker->count_objects = ttm_pool_shrinker_count; + mm_shrinker->scan_objects = ttm_pool_shrinker_scan; + mm_shrinker->seeks = 1; + + shrinker_register(mm_shrinker); + + return 0; } /** @@ -817,6 +824,6 @@ void ttm_pool_mgr_fini(void) ttm_pool_type_fini(&global_dma32_uncached[i]); } - unregister_shrinker(&mm_shrinker); + shrinker_free(mm_shrinker); WARN_ON(!list_empty(&shrinker_list)); } From patchwork Mon Sep 11 09:44:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379059 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 A56BFEE7FF4 for ; Mon, 11 Sep 2023 09:45:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47CC56B01A0; Mon, 11 Sep 2023 05:45:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 42DA86B01A1; Mon, 11 Sep 2023 05:45:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2F4346B01A2; Mon, 11 Sep 2023 05:45:56 -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 1DA436B01A0 for ; Mon, 11 Sep 2023 05:45:56 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E56E0140916 for ; Mon, 11 Sep 2023 09:45:55 +0000 (UTC) X-FDA: 81223835070.02.53D4F46 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf08.hostedemail.com (Postfix) with ESMTP id 1BEBE16001B for ; Mon, 11 Sep 2023 09:45:53 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=B5O3j2Gm; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425554; 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=6FwhLiYYaF8GJm0hS886+94gWet3PBBx4VE+fsMZAKg=; b=gLSSDiMtaHJQa3aNUnVTDHgZUw/ZNj0KHKpIlj2at3zqK/+m58kOPEemHG1PE7GRc7BVSG Lcf/+xhoxeM1CZRi40xnpY/MAnvP1L1QErO7AkcMIlnOpO7uc8ghD1r4QEr1Dbp4HZGbXt hSuXCh3qgXEPTrDX4Psuxkv66fBwkoA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=B5O3j2Gm; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425554; a=rsa-sha256; cv=none; b=ZJq6x8Ti4j2Tuaf2jLeYZ2+Akr4Ro68rKFT+iJPRCkFxf1eT47jXW7f7vp75I9ZmBxEAH3 79mswTAiNq6pFlYIO5Zm23kzqjPSCz23kRqB92Su8DyJ7Q37jOZjcH6nSx33T/YLKzPfzz 8+cB/viVMGqzl1LaCc2vdDvGZPyRY/U= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7083365ad.0 for ; Mon, 11 Sep 2023 02:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425553; x=1695030353; 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=6FwhLiYYaF8GJm0hS886+94gWet3PBBx4VE+fsMZAKg=; b=B5O3j2GmMlDtFdZf2vzb12DgF3FNoauCqA2C+RDNhy0yoeRq8fja8jgTfK56fcv0/d /f0uPYujBFFIrITOL4lR48PHxJmWevKdSleD3UKtPVSakY7wUWyvPvtIKXWIBOeulULr f3HNiFC9pvolOfQRzeIN9DTUE0aJ5ol54N9T0Empq3Pu+NzEw9w3CpvVuoIUxFeDJKmP SY6HCvoUdrYDQJjogdf2n0wBmKiYgXfwlC/lNgRXp2jCrGxR95gjfbVYuzDOz4q4yW4b Vbh3fQP6010eVbwczO5im3auFfCYEtpEXCmuFJ/qpxJgiyU23M9p3S+Kcl0GFe9JA+gg vexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425553; x=1695030353; 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=6FwhLiYYaF8GJm0hS886+94gWet3PBBx4VE+fsMZAKg=; b=Et488LV0oT0XJAnYYRiqKxahY0I+73nmXuURMkGFZVpMQXcZzjjoZcOmVT3s+AvBS/ IqgTCjBPidTnaGdDI6MvE4zxsicJsQndO8E9NT3vykjDpyBy3Slzv4CWjRroZdzx49LC 46YldSI24PW2f23YRCLEFyhlcrxzwO4d3KxP69/SOnN6trmqqzXqCPzM3JHk6kVBOcfL BO4o0E5yTkJaUitluslh9cB8TPlWeupMqmIftz0torpRFc7vWkJSg82jhOErRN6CSElP KIzk3J1kMidMZhh88H88GwktsfALzlE4xovO6vj0X5DwFDMR+uw0y62wcYIS7gjmMnXP L2eA== X-Gm-Message-State: AOJu0Yzsp3fvOzKlgzg7YnBmlM1kO6xmlmTrZGdE+pv+ysE8ObA88X3Z XBI9zh/wjqn9/wUvOOYv10egJg== X-Google-Smtp-Source: AGHT+IHJaWa+7S6PEpk0MEo5uFVZCUWjKmc0DPmv6mKvqIMnxGI/EF90IQq3u3ePRTZciiGyrN8JSg== X-Received: by 2002:a17:903:41c8:b0:1c0:bf60:ba4f with SMTP id u8-20020a17090341c800b001c0bf60ba4fmr11505655ple.4.1694425553045; Mon, 11 Sep 2023 02:45:53 -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.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:52 -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 , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH v6 05/45] xenbus/backend: dynamically allocate the xen-backend shrinker Date: Mon, 11 Sep 2023 17:44:04 +0800 Message-Id: <20230911094444.68966-6-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: 1BEBE16001B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: nythmtt6hboj39ei1nwd1o8bxkfq41ay X-HE-Tag: 1694425553-658330 X-HE-Meta: U2FsdGVkX18AYCToE5DK+Z1U6ylSuyzdF9mBc3NKMdazRNA4uquPCKBIoNzXw+dAdUj1iSkovMnKv/F5OULy4GVXMUujp49we3os+9sDsHntpSJtAj4zbre2ZHp0eqJngobMIlxPcpY5VqZshMvulHn9RjDAXT4b/ndgviMBQB4vgBByrfkj1cC+xie+JhzZs1rtU+3WLYbTRjYvFZbaddp57LjIH7Kf07K/osUWdR/ndTu3+UdpxuCWamkaI9MSCSwSp+uD8/kG3WGh5nfOgOMBUZmpeoLG7OUASHuF+rfw7uMYQ88yp5TBgIoHhd23b392fjSDSkNfhx5ZzMJzGKH36DH9zKSa4GDb3soAPHJNEfcYPNKbd/734d/YJRDfko0tWSone+xuzOuKkHEILOYB1bn0lIbBSuzRDamMJF9bkdmeQ4/4GU3ezaNdMOLzy48qlvRiKzMNlxeZRiuAPiC9CPBFte+c6rutPcRERTmhzbozAXmYicDvsOKaVZluMDydHL2+dYElKA+31rZ1Rb1q/SvHwGNhTDQMT7nbaDnP+P2CRzy/jyBdQdYLRz08cWIpxnhSDDKjkjGCbVcZT52aUi9UvqWeeuuS4KNr1jQhj4OToWgGco0/jinpZ0vD1DWAeQGJvO4GKNlnuiwcbY+NTyR3cnrNmgJrfdwxvql140r7mL8OcxbGRpQl8lQBkXR3NcPeCIlHaDE7+0wbbYniSagmVz9tcTsj2GcfJS0yqPHzQ1FGUWGhNsrT/aecqNDx+2ML3GRCng0ZhGcXINh2XtxL6PRfNFdHx5/aZWE1X2+l0Gtqrhqr2hlPqozQEIB+0YWjBY1KZQwxJBsLgw2axyCEntDxA39uMOtsg+V932zAZ2XVps+/xih0PWj3Rjt/YfrhJGGGK87YefY74Yi3gx1dKmXV6DG5xQ35nyY0+kE1enRZIZmwryfQcnrw+4b3b5YlJTiEBlSrlF9 dp0xQqld mHcEmo50YFuJ6ttx01P9+i/BXbYYOOFBAPJHa3IJHfQwHDEyNKrb5pUpcZtnkHVutnAGz5cN7qqGYmdcROFwVEuJiDgM8slLNnEZEPKFnWGcPWvdivIXDiIaRngcTYomQ1p014Mu/6pisHOfkseKQKImgE8meI9jD6pL0JlH1+s6NDeP/e2yeKyO5jiy5saSs3/OdV5md5I6M7apzU5Jhtr6z7n8XQrIWJDBAYh+3pEPav98JcM96/kxyMMEmQHj+kbvZZOgCpchrBWfKbK57jmQ/m8qwv+dwpnHPaNSDawfB+F6nUFNIr2dFUh/4en29MuR4CTej8ZjdFjGLJCjBN3DCGDKkUiPgeIgbk6AkDZ5EearHpw/AUqY8FtPzn0IqGcUmkOgZzaHlFcE7YulPSgpACi339jm5fE12o9ZG2eiR8K99Xw6OhQRVaJidV/G8Pt8Iu57rI5VZ8hta1nRdzDORxZ5e076OSdGSzySuLvXvC8l6kRuwVWKobJSx0lnus6uNfihWiYrKIdFLPmDoUrkLjfN8xhQjHPassJLADa+D5CEpUkIRuvKckwaqDuZ/34nkO7fOKTN2uoqvQA5fur9Q4uOILsVUY/g7pm07Ta/EqUQUhLd0rUayvq2G7YvV71ln1Nbi3Nm1O6VJSIJqXe6IWw== 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 xen-backend shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Juergen Gross CC: Stefano Stabellini CC: Oleksandr Tyshchenko CC: xen-devel@lists.xenproject.org --- drivers/xen/xenbus/xenbus_probe_backend.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c index da96c260e26b..5ebb7233076f 100644 --- a/drivers/xen/xenbus/xenbus_probe_backend.c +++ b/drivers/xen/xenbus/xenbus_probe_backend.c @@ -284,13 +284,9 @@ static unsigned long backend_shrink_memory_count(struct shrinker *shrinker, return 0; } -static struct shrinker backend_memory_shrinker = { - .count_objects = backend_shrink_memory_count, - .seeks = DEFAULT_SEEKS, -}; - static int __init xenbus_probe_backend_init(void) { + struct shrinker *backend_memory_shrinker; static struct notifier_block xenstore_notifier = { .notifier_call = backend_probe_and_watch }; @@ -305,8 +301,15 @@ static int __init xenbus_probe_backend_init(void) register_xenstore_notifier(&xenstore_notifier); - if (register_shrinker(&backend_memory_shrinker, "xen-backend")) - pr_warn("shrinker registration failed\n"); + backend_memory_shrinker = shrinker_alloc(0, "xen-backend"); + if (!backend_memory_shrinker) { + pr_warn("shrinker allocation failed\n"); + return 0; + } + + backend_memory_shrinker->count_objects = backend_shrink_memory_count; + + shrinker_register(backend_memory_shrinker); return 0; } From patchwork Mon Sep 11 09:44:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379060 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 62474EE7FF4 for ; Mon, 11 Sep 2023 09:46:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D7D1C6B01A2; Mon, 11 Sep 2023 05:46:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D2D286B01A3; Mon, 11 Sep 2023 05:46:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF6516B01A4; Mon, 11 Sep 2023 05:46:05 -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 AA0846B01A2 for ; Mon, 11 Sep 2023 05:46:05 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7D830140915 for ; Mon, 11 Sep 2023 09:46:05 +0000 (UTC) X-FDA: 81223835490.01.4D578E6 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf15.hostedemail.com (Postfix) with ESMTP id AE68FA002A for ; Mon, 11 Sep 2023 09:46:03 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=FRT1mdaK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 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=1694425563; 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=vEaLNFUhwmRxiNXJvWOPc9Z79QJgQluJlkgX3lFWQho=; b=WWBKaW05W0O4mpw9NGK604PEOUpUThVsEcR6JYhlpeSCaFwlAuic2nNwP3/Bp/61f73NsK esacxDFGBf/DTya57L1oNJs3I3ahfG4id8eTNr6AtsY0Cm3mfMYLG4k+i0gKbJzo2/v1mH 8/MTWz0TeAg/VHunsLoaykj3EzCaAjA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=FRT1mdaK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425563; a=rsa-sha256; cv=none; b=jc6KxTkKa5WwFkgCUAk6Ak1eY6t1pG0O4mrXR907OpTbkJ7B18u8OhhFw4VcSpt7feudCz DeffpyHhQCXWYlFC8nfcY76io4I7TqSxxrLTynxFkgFm87jVNrWuEabaX2N1Xc0EJVnSW8 3t7GBIxjZqvjOYJ2OVSQm/iBjr29xZk= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1c39500767aso6231415ad.0 for ; Mon, 11 Sep 2023 02:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425562; x=1695030362; 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=vEaLNFUhwmRxiNXJvWOPc9Z79QJgQluJlkgX3lFWQho=; b=FRT1mdaK2MGgfH5WPxE322qQ8W4/DTrbxHzm+FPeHRKwbyxJOKSxxJQ7cM4bvDROs4 M8EM/ffAAWdAYKoTPAxeGHRnK97RYe1h4WzgRguB7tZHP8NPt4tTBdwjOjmNEsajmF78 bv3xr/VeILARpEL+g5qpoPRAwwf63EYxHVqxCwuDfyOJ7UCiNts78qCVV9UXhCUtk/MM oA8aXhjDivkbvBxmIoSbM4jRHTxkJQjxaDxkrf8NqpHPCzDylIDkLG/ROoAbepyEkFVm d6OddgPrM4jQO/w67sYmtBuh1sna95lF3GbeXEgr347PdV9efrnmA+oYvQid8wFAKcQL K13A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425562; x=1695030362; 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=vEaLNFUhwmRxiNXJvWOPc9Z79QJgQluJlkgX3lFWQho=; b=A5yKjDW9NpzeTvMS8BZC2QErkwdlobJzlyjgwwDx/pyA5pVnD5RgwIBvHS+eGFPlGh ME5XXa5k1JaI9rjaw8SvpjfTxQOuB9WNEpraWC1uNEXxFjASfR0hiTNdyogBX3hsmANr r36HS3RYJuhDKf/JaEOyTOQmMZx7EXU6uRG8hU5EYfEh2v9qfh3AYf9Tkv1A6IAsFe/A RuYvy5A6dQHaMOs8U7wQxaXXhr9L7rXeJmov4CBlP8tqhrNmsys//nZBtR4K5dx9gtzg S8bm3qqGa1FUvKLNV17UXg6Sw8aSJZeeEzixATQG8L6hlb85cYii0RosnEf62f7fn8Fg 5/kQ== X-Gm-Message-State: AOJu0Yx+N1det2MRQxyugGYwNE6plP+327BO5a2xd1jbLwlvkOksZivb 4UnBkRx6LRRt+pnSZa08nb2UGg== X-Google-Smtp-Source: AGHT+IEEe7OKLpAjWZ6ZHMp4sopalHLkAI6pc9tZjZALl4cTsdDgpaoyKPO/MAR6mRgsc+S+sQMbZw== X-Received: by 2002:a17:903:3386:b0:1c3:8dbe:aecb with SMTP id kb6-20020a170903338600b001c38dbeaecbmr8865820plb.2.1694425562720; Mon, 11 Sep 2023 02:46:02 -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.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:02 -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 , Chao Yu , Gao Xiang , Yue Hu , Jeffle Xu , linux-erofs@lists.ozlabs.org Subject: [PATCH v6 06/45] erofs: dynamically allocate the erofs-shrinker Date: Mon, 11 Sep 2023 17:44:05 +0800 Message-Id: <20230911094444.68966-7-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-Rspam-User: X-Stat-Signature: kpo8z4fcp4rb563kxymcuamzwq7dds6r X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AE68FA002A X-HE-Tag: 1694425563-516538 X-HE-Meta: U2FsdGVkX196mUXdAKMRkYC32MTtKD/6cEOLUptL/2uhBt/H64BJgl98u2Tk5ldtA5VaOXkLO6G0eYksZvjZXjXSVHRapfzEpiTVfkS/qgZOanZIjg8FmPpVvIIyaVIX/ON+6XnDdOPHOimsuu36cscSp4MfU6mPo0YUDrstskQrLr/D1mz68CqpTejzpXQwrMGYEKbxMvXqiMYtvAPnHS7hD4b1LpTJdJ5tWRZy9KWWm8iLJ1L3DgINNigdMRXKSE8QRg3/QUqKsjq0zbQOPawAYkn23PQ/7VOonOwih4s8l0yGjSkCvbxCDyXkzcOaSJpsVu4gfeIrG9EvKRjnzk3RpWLAir6XwWWrD/vOL/r/woTEcZ8qq6MtNz7xWVQ9vgbpmetZxiAgewzIfJ3+WrNTfUrJlDMlJoRRgc62qErUDPR95vNdzjUwvlU0yFicFuBytf1KZI9qU7iT4UFSVqqOn/LvuKGiPa0FCkWPthNrNpVCkFsmHXnT6OHc3at2agLQJ8ys5b9da5VGO716m3QA9XjumC+MPkIebAQd5ZZwrWVFmbjawX1OkNBxgLGzR3OhJX2jJSDMBtbcOwZ6wlCVdN/FugiMDeFRGIvtqvAGIbqZHoTESz/g7cPfOplk6DsM///ce9nEpmngwVnGwv+KYObUDWAS8k7gpPIjPN2Oq9FHPllLrDe4aE2naqLpUpy7CxGVmO8HGEJWvemSd5qeigEnXyRpvZXMZtX+bxIUU5SH2l81sWWOGYSge2yx3RcJMO1du8EwZVQsRW1GX4uuazAC9PcllsdLbUTvT8IdjLkFXjpUoIvfOR9WXSFjh0ar8/rwWWEPFQN1gTOHntfo2q5MLyHpHolyimCMrBLpZuX0Vcup/zL7Qk6X8G4w0i5YZ/aAhLHRt7q+Twr6JiO1x5+9KjLjisbl1hbN3Ro2NpLCVjofild3bO3EAShXF2mj/Zl9nSQG+V7dOQw vkpJnYaH qUXUQf3JsKxbRij5a04ViAjQEfB9i0MJ53Xqkzl1M1RCySjS+17Nvo2u8+tsP6tv8akSaqNGmsdTcpdi0+iyr+dKOteTitPq4Ta4rj1YNPvpE7SXeZdbqDYk4Keo0N25RxrzdwQaEZvHSjgnU/3hX4kKUCHvQ5hxbDawIZXiaru3RL+sOdoBTCuCYOdOx/hSUQ6LsuhOfxFS7jelGZ/3zl7Q3sht9RdgIJjOPeZNMV3IJNSCnlAtsFE5DxFMoFUlKu0wqsQyS91TRIJYdjUuzTr06g83IDsz35OTAfpMtEwzfX6n9yd2gqc454va/aKvKIFHPrM9S0gKAhFCNa0amgF+cnO6+RWAz2USeNRsn3BKetJ/TEHbGYZ4ULWA1nFp3iejnnZSdw1fKdG5HHO3evTLzNu0zVDKhllcypdEJqsl1JCCHxFA70yiTOJmHfpG7MX6UV/e4+NyvWJxHa7sS74MMYGqzj9Y10b4Pgkq8V97hsBNb/g0CTsHlYdk9BKUykgJh1y3iV8aKnu5Edj1pY2jKyERfvLLZJQ7hR31f6E3x9w4g/vAFB+jwlKa5W3sgvbhPkbp9BcnSPsR/aNAtC2AVH4nLfTpmqEVAtMJ3gjKN4jA= 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 erofs-shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Reviewed-by: Chao Yu Reviewed-by: Gao Xiang CC: Yue Hu CC: Jeffle Xu CC: linux-erofs@lists.ozlabs.org --- fs/erofs/utils.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c index cc6fb9e98899..e9c25cd7b601 100644 --- a/fs/erofs/utils.c +++ b/fs/erofs/utils.c @@ -270,19 +270,24 @@ static unsigned long erofs_shrink_scan(struct shrinker *shrink, return freed; } -static struct shrinker erofs_shrinker_info = { - .scan_objects = erofs_shrink_scan, - .count_objects = erofs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *erofs_shrinker_info; int __init erofs_init_shrinker(void) { - return register_shrinker(&erofs_shrinker_info, "erofs-shrinker"); + erofs_shrinker_info = shrinker_alloc(0, "erofs-shrinker"); + if (!erofs_shrinker_info) + return -ENOMEM; + + erofs_shrinker_info->count_objects = erofs_shrink_count; + erofs_shrinker_info->scan_objects = erofs_shrink_scan; + + shrinker_register(erofs_shrinker_info); + + return 0; } void erofs_exit_shrinker(void) { - unregister_shrinker(&erofs_shrinker_info); + shrinker_free(erofs_shrinker_info); } #endif /* !CONFIG_EROFS_FS_ZIP */ From patchwork Mon Sep 11 09:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379061 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 C28CAEEB57E for ; Mon, 11 Sep 2023 09:46:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 651826B01A4; Mon, 11 Sep 2023 05:46:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6021C6B01A5; Mon, 11 Sep 2023 05:46:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F0966B01A6; Mon, 11 Sep 2023 05:46:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3FECB6B01A4 for ; Mon, 11 Sep 2023 05:46:14 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 179F3C0990 for ; Mon, 11 Sep 2023 09:46:14 +0000 (UTC) X-FDA: 81223835868.19.5943C06 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf05.hostedemail.com (Postfix) with ESMTP id 4A48510001A for ; Mon, 11 Sep 2023 09:46:12 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hKx3SgbS; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.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=1694425572; 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=r2z5ZP0td7rQio33ZrusFB6X25vGZrzEp4fIJ4zc7l4=; b=lQc8TRQsuNRhElfz9a1o3IT4zA3Tfk0FMrfOGgt9zbKgY5+8Haf1Zvzto2rpPAnvXYL9cw C1jfNDw9L2UruSY1ilPtl6xosaVVTJPsjhVd8a0I6OK1guk62tFn0gWS6cJeF1Ms82Pe6q qZfU/9zolyF5B9hNn35lwg1Xer6BeTU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hKx3SgbS; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.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=1694425572; a=rsa-sha256; cv=none; b=4YUSN5cINJJRprkpE7OlRAbP0lV7DMkEn7SIzkx5oHy3vrqslp49n1rYQorLJMWMdWxldY Z7ULCqMA2r9Cw5czh/SMDu+5Friq8T3w50wLyX/FnbLl33Z0n50uzYx6MeiTK8z3vmNUSh TwECBXpFHXdSwLmZ+DpUASKR6VyKs10= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7083805ad.0 for ; Mon, 11 Sep 2023 02:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425571; x=1695030371; 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=r2z5ZP0td7rQio33ZrusFB6X25vGZrzEp4fIJ4zc7l4=; b=hKx3SgbSvfplEurPK6tcgp92qjxOE87V4hdlh0k0eIJnhqAqooz8ev6zNK9UEe2Nvg EVWyyxQNpCcvhJynj+KwO/NsXsVBgLdLm8+xeSOHNQojGvfZwKetSNsVOpP7Cpr+eFw1 bfqgJT2vO+J42H4u3fRxWvG49GRPztyjEe0wKeHbbXOKgcGlyDmQ+bJqvVes6DJ4bg5i /DsDWzdudMGTux0zBfm71JLzyspS2i9zEY88Dj251HIfjX8vuSuG7mNka/XPbJSxawpm TCvwxpzPNRSalEJGQ+0xpYbL5fYqRKYwC+ZukoX9mmMSI4jI3QDyIpPEc9CMDz0lnLL2 3fVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425571; x=1695030371; 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=r2z5ZP0td7rQio33ZrusFB6X25vGZrzEp4fIJ4zc7l4=; b=RkzlSeO3uq8vMbw9q5Pavqpw2LlRMSgBGF52BVw8qF75p9BPAqq0isdaqZBNe9hklg C27xGQkYIz1UT9fFAIlWiMZJg6RdVrB0NbiL+9vudShppk8qKckSIiVTEhH3Yv6z8eRs LI4xIDEB9bZiuY5mAMH9F9AQ/z4S6pQRQ3opOqmKQo2hPD1PGUFi5z7ndJmcmr/ryETW ApeqIokTnu9ahm8Bw/058+hBQLWin+/KHTInrkq5cNJJpvt0JTCc7WRjqk/5SVBj4ufP ZNxed+EvdESL0zZ2CZYoazgM99e0LxalTbUdLliSmL39zjHnlVPDtYQpMZLk0jah+rdT fyxg== X-Gm-Message-State: AOJu0YweIkOFUUYiZnefBNWi/LdUkCHhjLx3mHdUHxV+gTQJTnje8UZx /ZBtUn7mBnZrKSQUB+lompd0AA== X-Google-Smtp-Source: AGHT+IGMazOb/vYj+YAbB56aNimJAjHvQ95oEZj3vNPDNUhDjsPyS/sjYbZ6xZxadrVaoBmmMuhKhg== X-Received: by 2002:a17:902:da92:b0:1b8:2ba0:c9a8 with SMTP id j18-20020a170902da9200b001b82ba0c9a8mr11823440plx.2.1694425571312; Mon, 11 Sep 2023 02:46:11 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:10 -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 , Chao Yu , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v6 07/45] f2fs: dynamically allocate the f2fs-shrinker Date: Mon, 11 Sep 2023 17:44:06 +0800 Message-Id: <20230911094444.68966-8-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-Rspam-User: X-Stat-Signature: 17tscajazbjoxfhbu668668eh5zgtnh3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4A48510001A X-HE-Tag: 1694425572-8013 X-HE-Meta: U2FsdGVkX1+RmAilCJte7EwkGb3WfdVuXRF+hupzxn3/OtnJek6F0fhPItNGRxXjacwYKDrXi5rd3LxJBjLuq4vQcg20ipyXU1MAkrtItzBcjI+fDhOHpNw3L9avEw3h1sgSAR3Fh/H6Pfw+5oj0OAy4AmqTIe1JJSVAEZhpI0it8xQJ3wrZAkQ74+ayJHbPKKhC4Rd1HlEeH/Zj+mDh0R0V9MmqdoD0dWn10U0GGYWDGyNKJce6Q00HkjbvRwBkkr7ow31/xza27TifFPK7l6d9WVGIcgPL5D98976nYaHk9Jvp/gK+SMegdwiNCVihELZWg78vlLeNEcmHN+u2wAwQpkfRw3zcVxxomVT5OFnyFtf1hz3GCPL/sgldR+XCzJ/bxgvPMW+DXUnLaDYWnhr3y3Ddtt7Qa0H38Kq5sSVaH+7ZJDJz1AgsahmYF63xxmE/X3vUiUv5n5jT4o4IOAKY+DopaOPxnkU8gMy3UL3g5r0RZgA96uZbkfbTPwbW5eC5woSFO+cP8uTmG7F7xyQtNSmuRc8CRE/xwnZSC/m1jE/uITWTAOKkUeEc26b8KEOd727e/iHGvn3IeQTkCgMfx9imbaLFi6Lb+VCUoDX/69JzyTJLSD2XLmQZLnAa+GbueiQ5SVKJuTWJYFQltg5k2QTj9b7qhT5mbpmfE871gj5v0zbd/EYRXEmnpraXzYCQ2orBkNccPu21qlVfdonPi4RAcIoflgcGpmnh+1uyFKMKx1/MMs1/FrPHuQJAAER2KmWracXb+0SuXB9au257maWOZqYi1U02yBn6EXvGvpySP+9r9VKRU+P2URkJZbFz8E24Q6l4kmt5EiM/zrikMT1fTVezKdiyyRfX0wu54i9lGf1fhpYNHsYrVg8ZTzIKSiGVFX7aLLKiu78HnRU+LmS4xfkChq3kgcz6Nk4xUmRnQ0v2Adsvk61MWfMbFKVmbuLKkgnYC/yqfUS ay/e6md5 AfxoK/VL6XuML86LbFnMeZWLEx0pebquhRAkpMr7VEemH7okWC+dPMCyiZHjF7x6jZkL9BMS1sifdQgwUCbpWExVQVCNsNreWoZG2Ak0fOvni1ToQBhqDLkvvXThcHT8mKXmhjmIryqlTWvvHPdHshc1QdZaVVDpVHIuy81gwEtDWzJKt4AxaWoYX15tZXBBWfid6fYmesNEwOnYtKJyQIL84VVBn1K9gKThxtcm9Y08TSnnFSOyjBt16H0PoD18mNuwgUQFhOTqnfbf+Sqy8EIpfi+MJcB6N7xcx/FUt6eEIuytncBcb3+SRwipfmw1wqBQLym29nzeTBbbPx0keiU9VqedrobKPp1e0M8drRarWOiRsMuUMokaowrBE8mTIrwBuWa8P+QVQoUL72ZvXQsFu+Ot9MYbfBDrrZYqGMz/YOthANMH9yQTu/Kmta/fROJ9pC1iX6hbXSDc6mO2aLU8tycAlV9BRhvOjOWZtScwGoAyPT1pkzLQumQ== 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 f2fs-shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Reviewed-by: Chao Yu CC: Jaegeuk Kim CC: linux-f2fs-devel@lists.sourceforge.net --- fs/f2fs/super.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a8c8232852bb..fe25ff9cebbe 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -83,11 +83,26 @@ void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate, #endif /* f2fs-wide shrinker description */ -static struct shrinker f2fs_shrinker_info = { - .scan_objects = f2fs_shrink_scan, - .count_objects = f2fs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *f2fs_shrinker_info; + +static int __init f2fs_init_shrinker(void) +{ + f2fs_shrinker_info = shrinker_alloc(0, "f2fs-shrinker"); + if (!f2fs_shrinker_info) + return -ENOMEM; + + f2fs_shrinker_info->count_objects = f2fs_shrink_count; + f2fs_shrinker_info->scan_objects = f2fs_shrink_scan; + + shrinker_register(f2fs_shrinker_info); + + return 0; +} + +static void f2fs_exit_shrinker(void) +{ + shrinker_free(f2fs_shrinker_info); +} enum { Opt_gc_background, @@ -4944,7 +4959,7 @@ static int __init init_f2fs_fs(void) err = f2fs_init_sysfs(); if (err) goto free_garbage_collection_cache; - err = register_shrinker(&f2fs_shrinker_info, "f2fs-shrinker"); + err = f2fs_init_shrinker(); if (err) goto free_sysfs; err = register_filesystem(&f2fs_fs_type); @@ -4989,7 +5004,7 @@ static int __init init_f2fs_fs(void) f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); free_shrinker: - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); free_sysfs: f2fs_exit_sysfs(); free_garbage_collection_cache: @@ -5021,7 +5036,7 @@ static void __exit exit_f2fs_fs(void) f2fs_destroy_post_read_processing(); f2fs_destroy_root_stats(); unregister_filesystem(&f2fs_fs_type); - unregister_shrinker(&f2fs_shrinker_info); + f2fs_exit_shrinker(); f2fs_exit_sysfs(); f2fs_destroy_garbage_collection_cache(); f2fs_destroy_extent_cache(); From patchwork Mon Sep 11 09:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379062 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 21D3CEE7FF4 for ; Mon, 11 Sep 2023 09:46:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5C486B01A6; Mon, 11 Sep 2023 05:46:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B0A5F6B01A7; Mon, 11 Sep 2023 05:46:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 984C16B01A8; Mon, 11 Sep 2023 05:46:23 -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 85B1D6B01A6 for ; Mon, 11 Sep 2023 05:46:23 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 606E94082E for ; Mon, 11 Sep 2023 09:46:23 +0000 (UTC) X-FDA: 81223836246.06.2659C4E Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf22.hostedemail.com (Postfix) with ESMTP id 97ECDC0009 for ; Mon, 11 Sep 2023 09:46:21 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SodeY39R; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1694425581; 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=7LECipjpjMsTeT5UMm7L2TEbO8WqkVi8hOfJfny30YM=; b=vTuvIKQcXhHc+YEvmbpZHXqNybGUt9VgHMwzdRj+Cj/JzE0Lo1Kfj++lZOohMvqIODoW+p Ps4gTD92Vnp/Dzg3uT2JS67lLVY2zZPfvRFpPLAUsGOE/6EVWt6Zaow2oWIqh1TBnmocVY AOeLcW4psfcgueJ902zs/tuv6F86qdo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SodeY39R; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425581; a=rsa-sha256; cv=none; b=h9GS5ofyLG+IzeJpg7qvr3UYoVKtmn+odrpZ1RkwoRx0O/QuUJeOMCps09lU5oOHuONX2b mIl5WBjljZW35B58B8AspDX4eO8ML6PKq1CVbR5W4Pn+O5UaHEW8LgmwB82pXqNcy+Zno5 nf7inxx+Ote5Nw6Mmyqn6Ab36Vua0hY= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68fc94307bfso148133b3a.0 for ; Mon, 11 Sep 2023 02:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425580; x=1695030380; 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=7LECipjpjMsTeT5UMm7L2TEbO8WqkVi8hOfJfny30YM=; b=SodeY39RdgbZ+114xEtwF/Roue3nP/9wFq2z9CDs9t9diBpluzntqp0m1funNw6e5g ssN062Mz4u2m1Q+ul50LVQ2NL5T6/Qx6gea+10fc99+IEZqomM78VWFCShJ0W4PUGjXi r0Dsx7e2w6qfiHrQrbuHeuj+CMpg8I27MvCXQCmv9yrubJbBzXpvlPcTF6dl8NnvYtiF HhusnHmG/QYeYV8tIZ9Xd+Nk34v2pJvozdkgPlIlr972f4RdDEsnZHOA1bjF9T/F+jrD 3t+BtqrPS7tDievAsMvXlgOMGKkaG/Qb0hkVN1Nz9EVayD0TFly+fLMhCig9l9/L3Icb 8iKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425580; x=1695030380; 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=7LECipjpjMsTeT5UMm7L2TEbO8WqkVi8hOfJfny30YM=; b=SqjfRlAqcDkR3fMz0Vz8Lu0c5qtFeFY5SwF584/K7ZdVVLjXHrOByEgxcRrGrQIc1P flqjdegOTMFMuyTRJOX2CYBfQ6pqbIRILICPY3SZJJaZbeCYZ/UHlTS3LDvWiw5vjMUq EuRcOh2wm/lY/5R0AbkaSJwcIi36qlRbEPjUqUWnN6SnSKW2Oq23aQBEXJHZ3b/NSYlG mqk5QiwmockKtQqK9a1hmqg+u58KKKEO7cKJ6b8yG8o3FWdqS2bIfHY3M1TIYxEaubpm zw2rKcgIiPzsf41SunBNVneppRzpQzRC6Twi0MkOx/Tau8P5MYx44FAjJ+N/xjzimf4F eP9g== X-Gm-Message-State: AOJu0Yw4OLyhIyHJc4UlkvUPrvT+MNrm2yFyIgd/MS2n9+mpipMMT4SA rdTUsKSdzakCmO63mvQPZds5zQ== X-Google-Smtp-Source: AGHT+IEIDNe7dp+17p/1jwosBLUpyZnN7S3R/YUG8mMRO57r91hEdK6UAfUP/CCgqA5OUGqlmZWKGg== X-Received: by 2002:a05:6a20:a10c:b0:13f:9233:58d with SMTP id q12-20020a056a20a10c00b0013f9233058dmr11702677pzk.2.1694425580529; Mon, 11 Sep 2023 02:46:20 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:20 -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 , Bob Peterson , Andreas Gruenbacher , cluster-devel@redhat.com Subject: [PATCH v6 08/45] gfs2: dynamically allocate the gfs2-glock shrinker Date: Mon, 11 Sep 2023 17:44:07 +0800 Message-Id: <20230911094444.68966-9-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: 97ECDC0009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tjh51cc391b36iaibwg7yrdy9d1kjwzr X-HE-Tag: 1694425581-325126 X-HE-Meta: U2FsdGVkX183hNSA1bOlLCz3cAvY4eqDBM2hSAJrdoo2yw2UupgIg9Da///OYXfF2onRrmoRgFE0i7MeDpkVrLy/6k0rUpNyY8hKoaeDPOU2ok+1zNivAF2XRmXK8373psdam1V+cV9enH9KkX0h+/3Vq1XtiWxQ6zI+jXUJJsNp9Cbf33DkUmqpbguJIT/DHKoJMWwdVe1FEaPTccKuX5Ko99+7YuTkRFo/ao/2EP9WVN6EN3g1JAqe7R5zGWlGd8ryl3UAw+/mBlTaMrYiFOQXqyeyXWGmasfEIszQGSOOleZUnoaxUeIEX3Q2yK64CKzBuo0ynwLE58cYCe9ucWthedrQ84kpQvtbMGbDlGISwyn3+jmVY0DKbWJGuebrDSMDjX4nZ3CMi8byoonWqdBVXPvxqOS1ciFDXFGuji3tNyjXUZLHxQGwQppzn26EzMHarZJqI97W1C5hioJ13M03KnztSV673LiT1PVPUFTh/gtRms3BRPkXKsJPtJmm0RjhRiewIKE3FNUUfRYn6zYT0n3uHFYW2OICpupW0VS7P9EjO5IhTPVfLbXC0UdltwyeBqXV/6fVLd981v+Rj08RQjbmmn12sA3bN0ONqC+90TlqllGXb02+JZwU5XundcuvKhlTzAHcUmG6YEO3OqV47KpKQLK2Udy3M3+DB0RgFFikCRjc9KfaxLPRFetmPn5lC3abt+gDnzlv5osOw7YNQpZr+5F0+8UT3+XWFckcGICpxSv78ETomB9VXGunvh8KaiMPyQCC6UsSFRMV+WmxnpB1AtFTcimCyL6IwmRy7ythYZnUTNfvnrhx/4XHaaTUFEr36PWMOwVL7rFEy6imkburdN1CmmTJiiYw8ltRP8AsexiTKf60I94quc3j0Yvof1TY6WRLHkzjgTQXuOvf8Iseh/ZGEM6mvSW9btKaR45iIcCXgfAQUD+32ErOgafNP8Kk8ThXQY/IFUk ybHCmbWE NIqCj5RiW6uku89eOiBBKuq0Q99jQJPLjhWIWzpNS2AsXsYfWH86a51YynWJWlwUWR9gpWKM4BudoiWwy98fjMNP18gQ6nzM9EuKs3SJypeZHWwObH5L1ACLvMXPb05TlwemHJftNv6o9NgtbLHSyWcjMvkGufJd49OMHtn+gbKTfNwhSxi4EPx7YB5gGtmcsv8b33v8e753y0r5XDui1H4EUoKQqKFN53mPFwCj9pwWrr70BfmcbsMnTQIgP22y6gXD4ln6ujjeos9yjX3XBAqV1NodWpcnjfVPh9poKbCk/gQ+Qbq2L+3Ul04J7p+93bnWUdcZBOA0bGGLoI1FLOR/dFwOZCNEmgVe3ZEDvx75VJd8AD5+vIEBSVlef6Z5kqPCpZO7WZXFNAt2qN25q33cEXmiKVa8zxgHgpqaxCsbBhMQawv0X9ysT+Q== 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 gfs2-glock shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Bob Peterson CC: Andreas Gruenbacher CC: cluster-devel@redhat.com --- fs/gfs2/glock.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 9cbf8d98489a..35967f8e3038 100644 --- a/fs/gfs2/glock.c +++ b/fs/gfs2/glock.c @@ -2039,11 +2039,7 @@ static unsigned long gfs2_glock_shrink_count(struct shrinker *shrink, return vfs_pressure_ratio(atomic_read(&lru_count)); } -static struct shrinker glock_shrinker = { - .seeks = DEFAULT_SEEKS, - .count_objects = gfs2_glock_shrink_count, - .scan_objects = gfs2_glock_shrink_scan, -}; +static struct shrinker *glock_shrinker; /** * glock_hash_walk - Call a function for glock in a hash bucket @@ -2463,13 +2459,18 @@ int __init gfs2_glock_init(void) return -ENOMEM; } - ret = register_shrinker(&glock_shrinker, "gfs2-glock"); - if (ret) { + glock_shrinker = shrinker_alloc(0, "gfs2-glock"); + if (!glock_shrinker) { destroy_workqueue(glock_workqueue); rhashtable_destroy(&gl_hash_table); - return ret; + return -ENOMEM; } + glock_shrinker->count_objects = gfs2_glock_shrink_count; + glock_shrinker->scan_objects = gfs2_glock_shrink_scan; + + shrinker_register(glock_shrinker); + for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++) init_waitqueue_head(glock_wait_table + i); @@ -2478,7 +2479,7 @@ int __init gfs2_glock_init(void) void gfs2_glock_exit(void) { - unregister_shrinker(&glock_shrinker); + shrinker_free(glock_shrinker); rhashtable_destroy(&gl_hash_table); destroy_workqueue(glock_workqueue); } From patchwork Mon Sep 11 09:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379063 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 C0098EE7FF4 for ; Mon, 11 Sep 2023 09:46:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F32A6B01A8; Mon, 11 Sep 2023 05:46:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A1D86B01A9; Mon, 11 Sep 2023 05:46:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36A046B01AA; Mon, 11 Sep 2023 05:46:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 258C26B01A8 for ; Mon, 11 Sep 2023 05:46:32 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F0AF780930 for ; Mon, 11 Sep 2023 09:46:31 +0000 (UTC) X-FDA: 81223836582.06.53B9DA9 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf29.hostedemail.com (Postfix) with ESMTP id 2936D120002 for ; Mon, 11 Sep 2023 09:46:29 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SSqElHnJ; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.171 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=1694425590; 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=eZxqpi7coMh8ftID9yaYhwXiGQ4pT4wdMxIpYIgs7HE=; b=X5KHKUqny6pTxg6YzeXe1NcaTpq6bgX/f58ryXZO4kCxME9WXFTQdrAlfItLgk674KbVwg TKroyQAYemZL6OmeRCBs82Bky0OqJMLobg0ghpO95MoLBZjxar3GaYX2PvjWUPkN32Iy0N HkaDnVWDQ8pDdlcyR3DYPfxV+rB3ak0= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=SSqElHnJ; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425590; a=rsa-sha256; cv=none; b=J+53F3x//yocruzwA7Jaz2LQdL9ft7lnHqClyb51oBcpGVbdPbuFTVaQe7RmoxJGnKXMYd SPUwGvc6FOShxHOadAwF0jeLH9q6ocsZUKTUHsx4jp1b9Z/BBJIAOmiFM+ivTzxsRAy+ER 13dWDq9DB8Nqy9tfOJrF5Xv2/pzJDKo= Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1befe39630bso9364625ad.0 for ; Mon, 11 Sep 2023 02:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425589; x=1695030389; 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=eZxqpi7coMh8ftID9yaYhwXiGQ4pT4wdMxIpYIgs7HE=; b=SSqElHnJng/0giGSiL2cUGSpvmCVaC7CjsotqWi2UUH0E6mCVcgZ9ppRNyZ0QuunFc MPsKVasi5kTxJ3fFjZHfa9wZ/OUfoSG1k7f9S8PR5sVKp5/7kt4ifRmxSN/QC0u+9qIp yuZ1vmi08J7pmYI4CR9RLPYEbnKml2XMtoHRGP/BAEhXyVT5AnEtABd7S2glzmBsZBgg rJjPkAOL9KVYFZ0uJgLffT+nlpErrhYeu5CESAlAa6kKL7Lq+hEfR5ZCi5Q7iJMrR2l7 3mqsO90puIM1NSx3vZxHlyHZkN9yUAmNk5wln9Ia9xPUQOJVw8uFpcGniG3jY4+FBURF Tn2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425589; x=1695030389; 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=eZxqpi7coMh8ftID9yaYhwXiGQ4pT4wdMxIpYIgs7HE=; b=dUUIGHfPnPeGYMiaKWoKDXh9YVQReLM112iB5mZaKJWKXBBa81BrQ2WMtcWBAW7rV1 F6Y1XDretChIi668NH58trsX8hXCbw6bIJ4WsTRbH50vjE6Bq7Xdc3aikNqaEtlbq5Xu oQOhTt3FJMN7P0XMhw9wXqaFK5b8SOoIUTL7ZfNJ6g3zf2TkF35A5LdN35wzSrAru7mV RTgHNLL9no43fXoSGWhfejPYObeB1FsUr3/NfRfV+wxRrQXjmpB+qv42pIUrDn5o1EWD RIUT8UNjJSxajCCf8widVkG6VUCCVmT4AnKPxd7GWvICyZtCjCYl0a601q3GbBpwr3qN 5+zQ== X-Gm-Message-State: AOJu0YzebCFUvKGb7A9TRL/xKQLdPI64U9Ubryb+euxQGrl/kjS2aRMa XiuBUkJc+PIJVF+pw1Q8sbRiLg== X-Google-Smtp-Source: AGHT+IErSLcCsEqsbL+707FM3SjghmcKvBuY/KdVR6v7hA7UKBMg35jal9WCdltKnJHFJ2qaL3tLGg== X-Received: by 2002:a17:902:d645:b0:1c3:c687:478a with SMTP id y5-20020a170902d64500b001c3c687478amr326782plh.2.1694425589143; Mon, 11 Sep 2023 02:46:29 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:28 -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 , Bob Peterson , Andreas Gruenbacher , cluster-devel@redhat.com Subject: [PATCH v6 09/45] gfs2: dynamically allocate the gfs2-qd shrinker Date: Mon, 11 Sep 2023 17:44:08 +0800 Message-Id: <20230911094444.68966-10-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: 2936D120002 X-Rspam-User: X-Stat-Signature: dit3py7ysxgs3n3mzqcq8btzokyxdr65 X-Rspamd-Server: rspam01 X-HE-Tag: 1694425589-52548 X-HE-Meta: U2FsdGVkX1+Je9x57CZUvx99avANPhCic8FCfv1XWSr9kYh5RN8rceeN12qJVOWWba8Q1vj8b8V4bMI49CbmKscULld7WNWS1ZVGkfgtqvzG/gm2QXmqlqajTfV+P7CEBzmFeL/KxbpBG39P6/ua1vsh4L/RxhevHY+PvxK1wiUq4Ib82TJnac+xrplgugDL833vvWdbEkqIU6i/V4vMV6lFiZ5wnVppYxoB1wcYkT64Nfi8NU1oKnx23yIdbGUFUvyuz0L4imkf/8+eqUxTnw5Fx6TdCqNPQyYaU3DA1mZfJj9/TAhfCYG9CN3K4eKXDApfe4aq3a7spELNPtDytZ53KzTqyh4d4ra0jvKJ71C/CArjTj4SX649jGeRmax+0Z96+0uGYN1NC9kJLf3FHrYJ7xJFOrXKF4w8tHI71uBRvkNQv6YtDgos0sascaGIerHHrXz9WBOryiMaBXJ8FkxJz/hkDtHFFvoGHHS14ju3H4Y6pqOijIVK9X9i4KOnZoYD0Ie6CrpxHrtm5AF0YBWJMPPkS6ytsD3v7b+R8AbyERBP7VOekNEuP7dbWV+0CG9sJwm7iKHChzYaoaGRVwJfmgHO5glFdVxDegckYyzDs+1USWGk+xfa68U8WkrgniR+x5Qxy3bMFqDct8StWRW0s9GyES517sNEW0jpoEjtGmB3iprJZNsPr2+HNL8TNobV24Jx8WyvgN4ew/r7Dmz20QFGFqJPgQDTl+fuGhYm7PhTtg+aVe8jTa4VUDTEmCmNuypQSCUWs/ntpG69WBjLQlXGiHhwpBKVbupDcKL8Syz8JryQvb5fvWxOqiaji5SEw5RqUYykkbd8JFXwmDTvyw8hDAlYj79DzJOxDwAUGN9O/nxoYkv5gZrigUIyN+uKsNps6Pa9vCZwpcCv9+QiAGHkFNVT957bSLGHVGU/5LiW3mUWyz6PB40cpgz934j6RrdLEjcul+CV3JU ywN96/Pw MuEZR1Rh1rUUpzJlkYsiLa9dSoMi0fUgKaxdMtwSGniVlBriE1SXI6LvVrcc6k5Bm7TLNTM56lc98Y71sZbRsgkElQVG4o3i5Dlg+ysG8nnlKBt3iFKfb7KTa2oip+H+XYVw7rtxJFcCSEzgnuf38cDo9AnT4NkFicwoatBvcjDEwTdvIoNNX7RPVMyJdmrQ2ZRoL76xFDYKsPWCwilk6bnfzcxtDLw5MZLJtM3CXBQS2JwlErKWxQ7Q8JKmWVWmNr2m7qBNntuCs5phBwFFTKtdL8nGMf386pduCqarrhIrGh8owCbIirZEdSc31Q7AS/NqMxE3qCiTL4yfm+6uxybCybiLsDGJ2pHuXI4bs3iTRPOiAdUtPQM3XDCb+GNVsKA0JyDxgbae38/0DRI2e0Of1ioSDwJZB6/KXAooAI3CKFXUXmRnDdqKNwy9LtThr9Xol1nIcMWkEzh3YgqEApJE7ylvMhhU9EQZ7NUZp89E780A= 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 gfs2-qd shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Bob Peterson CC: Andreas Gruenbacher CC: cluster-devel@redhat.com --- fs/gfs2/main.c | 6 +++--- fs/gfs2/quota.c | 25 +++++++++++++++++++------ fs/gfs2/quota.h | 3 ++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 66eb98b690a2..79be0cdc730c 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -147,7 +147,7 @@ static int __init init_gfs2_fs(void) if (!gfs2_trans_cachep) goto fail_cachep8; - error = register_shrinker(&gfs2_qd_shrinker, "gfs2-qd"); + error = gfs2_qd_shrinker_init(); if (error) goto fail_shrinker; @@ -196,7 +196,7 @@ static int __init init_gfs2_fs(void) fail_wq2: destroy_workqueue(gfs2_recovery_wq); fail_wq1: - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); fail_shrinker: kmem_cache_destroy(gfs2_trans_cachep); fail_cachep8: @@ -229,7 +229,7 @@ static int __init init_gfs2_fs(void) static void __exit exit_gfs2_fs(void) { - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); gfs2_glock_exit(); gfs2_unregister_debugfs(); unregister_filesystem(&gfs2_fs_type); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 171b2713d2e5..d3d013d1d5ac 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -196,13 +196,26 @@ static unsigned long gfs2_qd_shrink_count(struct shrinker *shrink, return vfs_pressure_ratio(list_lru_shrink_count(&gfs2_qd_lru, sc)); } -struct shrinker gfs2_qd_shrinker = { - .count_objects = gfs2_qd_shrink_count, - .scan_objects = gfs2_qd_shrink_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE, -}; +static struct shrinker *gfs2_qd_shrinker; + +int __init gfs2_qd_shrinker_init(void) +{ + gfs2_qd_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "gfs2-qd"); + if (!gfs2_qd_shrinker) + return -ENOMEM; + + gfs2_qd_shrinker->count_objects = gfs2_qd_shrink_count; + gfs2_qd_shrinker->scan_objects = gfs2_qd_shrink_scan; + + shrinker_register(gfs2_qd_shrinker); + return 0; +} + +void gfs2_qd_shrinker_exit(void) +{ + shrinker_free(gfs2_qd_shrinker); +} static u64 qd2index(struct gfs2_quota_data *qd) { diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 21ada332d555..f0d54dcbbc75 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -59,7 +59,8 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, } extern const struct quotactl_ops gfs2_quotactl_ops; -extern struct shrinker gfs2_qd_shrinker; +int __init gfs2_qd_shrinker_init(void); +void gfs2_qd_shrinker_exit(void); extern struct list_lru gfs2_qd_lru; extern void __init gfs2_quota_hash_init(void); 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+EWLkEfKF0hVo72ypg1trNcho5HttjmsvzBaeTi3V7Jf5BB60kiLj6Y0RQBGHZC/7w0CxJ6JmSvfaoybIAy8m1P4Is81CZdVkzbDJUmpx5AovYzELKKUtJmrqQOESIsDX7o9DDY5Mu3VCmfYgkRuEsmeMwCCt/WTUYJGZxyCpWLzdbzdQOAm6THpl/fofRS3quwdMcCaBD6pAHAbR21fqEFYS4uFg54Bp43X5EQcqBgWrKOWpSKyhQGUw5B/mYCVdJx52nH+wT4vCzEUY7i7nmG85fw3+p0nXoTBF2RSoyTHCa5Gd3GeaVFQIA1kXcUrUdEEd1xn6Kl+ErB/pR7z4HtPyaZ6krr5QJq+SpyOpxuuOdUHSRJYyfHa8G+W7cSsrcmReJh2+fu2x+j4YZ97NbMP7LDahvOwlW70eFyI6hCBe6X9OpnTuX2QqUtqQwr/Bs9EihjZvGn+JRo3il40gSm3wKSQAmxLafZzc9Oiyyb27KRRZc0Oe5QDO68s8eZDk44NeiLwuKffO0yNt3+7le1lbpX0mihopQDiopjwCdzlYgaBvhAy1pkNcLhEF2jcZn9KkwwoYHmWgZy9JNg7QHGk4IodCUIIEG4Wm+XDkzyyN4C1yzps5PMk3pOmSGQ2CBAeJEiY9n0t1C8jDmP7iboF1PKwBfo4vTjMBK4vjV96rICJI97zw8x4TeTpWjtrkD6FfSO/aFpVPXE7tzCefq2W7M9mxbEdBUHAmFOKTKFIa/2d3gqOPllHm1d5CxnQOCez1LFQgZ7D8NHJlIItN4NC3CP+Pp98ffex4z7GtLIY7QmbRsbsJxK4WZKHWa4j/XaNhoemplYmz7LQZcjO5Sx67Y2g+X3DD3Ivj4vZ65pFwDxS9tBR Js6oLA6F iGMg0LkmYGZVPE6oiTs33kwxrhYRb0lzlm01HAhmHm5eKURuEWjUr58HvJIVQv04pNz2pl8yECYsQMn+aTNN9GUB6oy2PvVkjqd+OgMvVj6zLNkX8ZuSIPjZ3zJgE86ayotby1mbd6zA3v6ORdbPNbYRzJ5z9kTBCyD0CPWDI22V6BOeHVedk/tpysrHDiAzFlyEiY9UyNo3064YpbWg8dDMHQBAGtkxzk+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); } From patchwork Mon Sep 11 09:44:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379065 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 AA06AEE57DF for ; Mon, 11 Sep 2023 09:46:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 344AF6B01AE; Mon, 11 Sep 2023 05:46:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F4C36B01B1; Mon, 11 Sep 2023 05:46:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BCD46B01B3; Mon, 11 Sep 2023 05:46:50 -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 0ADA76B01AE for ; Mon, 11 Sep 2023 05:46:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E43121CA3EC for ; Mon, 11 Sep 2023 09:46:49 +0000 (UTC) X-FDA: 81223837338.19.5031861 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf02.hostedemail.com (Postfix) with ESMTP id 2ECC280003 for ; Mon, 11 Sep 2023 09:46:47 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DrQplDef; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.177 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=1694425608; 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=XGYwucYG7HTVpzK5CooX1KDKxtCfW/GyjCRxwUVGc8U=; b=sj6spv1xGqIER3NhmSGacX9jfMb4bI+pFzB1EHS3R6NPiCAYFrdZOiXk4TKeMDBCvhvvkj vR805lqHz1COa2i/Om/r5BWDgZ5kz/yt5kmp8kTJJeEPofQntFlZqRG+Zwhqtn1wbF5yFT R7P9Fm0F5pHiq5Izks/gXgnVGN+0cr0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DrQplDef; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425608; a=rsa-sha256; cv=none; b=CGzwqbXHO/Bzhv25zE87vW1+RUEzZfWdbp+orOxlfRxZIr9y5OXdqVb0OVTFAKgvapX/zu kiLrQ8hzsLVI7S9li62kSUQy7H2J7Tj35yS4u5in2vgOA0ZYv7GsRxDU8kfF2Yrr3GAT8Q LbatcT/MqegmThZZpxMKuQajKoXDEGM= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5657ca46a56so444949a12.0 for ; Mon, 11 Sep 2023 02:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425607; x=1695030407; 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=XGYwucYG7HTVpzK5CooX1KDKxtCfW/GyjCRxwUVGc8U=; b=DrQplDefwdg84Y/aa7RbWuRJKeHtoGiGMTmYxjuAEDhWZOxmnKg1KBynwlON7GHpCN mHrajSeoBrwONoUU9/V8ycTMVJ9+0TCrB28B2xgAUKiidrK//jLGsWS1dIMoaY/vdeiC XPli9/PB2uxDeMCe6IxFBPxOUmsqmMRcDmFhP+GgcMalkVysgEDzUhRqL7lZxGgzHcLH yQ4GFQI/IlsPXTrUTkjViqRjAyJeehQQfy2oZJ3888hpr4Wnicspw3sPUJSnVn1QyihL GrNc17XbxCqjInCwThnsWfKtAoxM//gsvRgn58tSrW3+VSEMxu2jLrD2eHXSwyp9kF3o jCPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425607; x=1695030407; 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=XGYwucYG7HTVpzK5CooX1KDKxtCfW/GyjCRxwUVGc8U=; b=u+oiDl1V67UsEeiHw1ACCF/YCSTVLDCEeLzljACQC3QIGTINBqC1OU+m5Bv7UhJpsZ fqeMChtn03A0SfgaQC+5oIKSDmHKRc8xV7xPaH9nGUw5/GaBt4w2KUbvXYyT0TxqfhPG xxKVpRLTz/rE7jzuKDwEOkOKhsAb90UkBfEEYhD1MvAKBq99xcrB361BBamH+EdCFftu 1M5Gm2lRm1ASu65WgHZlbt515kYBCGD+iA0tPRSmZHRukaBpJjTA9ubgDlp1g5sRJL0h FF3s9YxukyTeNv4E1p+LjZ+jxvwwWFxaI0dnffcFDXpVWePWfUC+RKjf//l2ZZN3lhRJ EDLQ== X-Gm-Message-State: AOJu0YzJ70ZVzktQc2HfEVrCBTbYl4kcsLAcQGCliZ0cHzioTB8FjNRQ WH52nAkyy6EXm1fcFL3cm3P2WQ== X-Google-Smtp-Source: AGHT+IEATGFeLgyETjwn0MpUPq3DvWwKAg9V030xDC3jjIEkUp9pVkRI070K/5NVvqZMyXiud/buJg== X-Received: by 2002:a05:6a20:5483:b0:140:cb66:73aa with SMTP id i3-20020a056a20548300b00140cb6673aamr12967762pzk.3.1694425607113; Mon, 11 Sep 2023 02:46:47 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:46 -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 11/45] nfs: dynamically allocate the nfs-acl shrinker Date: Mon, 11 Sep 2023 17:44:10 +0800 Message-Id: <20230911094444.68966-12-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-Rspam-User: X-Stat-Signature: t5by5dtpy7h1314h48y93b5u4ni5f7xp X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2ECC280003 X-HE-Tag: 1694425607-109806 X-HE-Meta: U2FsdGVkX1+dOYxmVsp0hKtKulKEGVYjBlBkttG5frcIl0kGaUFozsR1w3GBD0X7HlhMhc6AuMrM/Tb+n0GrSe6AjXN8OZnMskQhmkdvUOgvYa4Pq37B4dZDt14RdqHgl/75/a2Y8OyBGX7+EKSTkrzblp1BlIgWs0L9bD0uhVFWOu7CDLAycSeKegP4+TSC1DWmuXSMRy1r6xmQfu3J0tSvz4klc9jOjNCdub7JNT/OJuDT+GhnbmSa9jIS+wuLaKSiUIKJhf9pvtnix1i7tl3HHCqiHsSYBuuWJtstclUgFHjRS/tqhypgD2jWAn0R8o6UURl5Axwnh6CAuoWiVReO7KFx0t668U5ZB1GqkaWHz4qmUpyBjR25C7HBIhWOQyNZ2tzOtzYErLzGrGeMT5zYUUCABrWz4y4u2oZoxQATaaNYg9YClLkVAAXMXt+JCa2YiGjPBhLJ8qG4IBjR1FEYHGHR2tC9BXoG+ROKa91mvCdm/k1ZJMRPTgVbuUGsf2FH9ZDkOPO0Xugx1HGu7cN21wLizoGtFlHNua7BZ9yfx0KYvNvrXLRrkQaZrl4wfGcytg4HGxS5Yb2BD0Ugog/APULO8RA5KwJ3qh5eQwYaf9JapNoY2qUuQxtY80nFX0FO5XZWGDEw1CKEd0ykjSTTRRyiQ+BArXxylugBOVNgf/gnT+BI0JysftTtcfRD5kgQ8S7Uh8zj1b+jHUTziiXalE3CJLEZ05Brp/Z5be2TRufA251gnU6NSbCqscwBshwleUjCPUVBgj5j1DtgL8u/pKmT1PX0JewMWj4mb/P6ch1tdOc15Q8w5Vf+yTSnXRbmElZOviBD+jp+I+l31FyJ5fF018ZVX0cVFhc36ceVAKLnCUltd8ujPKVGaL22L5tMzPLwpxiA8j1J1rWiMMmahTdWbH1Qo4aTQg7VnyGMEQ81IDIv7sJX+N9Ij3cZMY+7shE/G1/mc2/ezsz eUhYawcc gc+8DL+cljaZWbYuu8x709hhtA2l2lDNax2oapCCjLoHWq0srjD9y2O1IwJngTpFNWNGkAhP8SgRl8IlUK8TTcjfzq9rHEiOHy0lShsRt2rMCAMPOC/EYencKJIDtNh/hGKD4GFvVkWzxFAeJukUAJsHpNbK/BrSK2jHRfWFhTeQV9ZG3E4lDQxbonDka13sXVtIeKzOobiaLhELTog/ji4oNVqjj5i5X8pB5X4V8CiSR5puomn/mXDQOMH4QbCuNczNGVvbnlHLwTDsuDIfXL7XAFOgIpsWctsX0+i6frgu64WeStUsJP/JQ55cSEx8y7gKyWYZMvn/FODLOZO2nDLDJ78r+aoZ6nfEu8c7OOO4pO6cp23ijsDf2hpMZKUcScvQJGnYYlwfjLtxzvN628FRHLG1H4+pVIjooCYSY7rTMOH5StoOnxOC6ox+hNkPH1qJxsnzhbH/lbjlwPR3IB4Q1/6Aa34ecKTnADM3F+HDiywMTagLRq9TXdqeoqKXZv1hnpyudZlppUBDZjI9/c7mSYw== 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-acl shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Trond Myklebust CC: Anna Schumaker CC: linux-nfs@vger.kernel.org --- fs/nfs/super.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 0d6473cb00cb..09ded7f63acf 100644 --- a/fs/nfs/super.c +++ b/fs/nfs/super.c @@ -129,11 +129,7 @@ static void nfs_ssc_unregister_ops(void) } #endif /* CONFIG_NFS_V4_2 */ -static struct shrinker acl_shrinker = { - .count_objects = nfs_access_cache_count, - .scan_objects = nfs_access_cache_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *acl_shrinker; /* * Register the NFS filesystems @@ -153,9 +149,18 @@ int __init register_nfs_fs(void) ret = nfs_register_sysctl(); if (ret < 0) goto error_2; - ret = register_shrinker(&acl_shrinker, "nfs-acl"); - if (ret < 0) + + acl_shrinker = shrinker_alloc(0, "nfs-acl"); + if (!acl_shrinker) { + ret = -ENOMEM; goto error_3; + } + + acl_shrinker->count_objects = nfs_access_cache_count; + acl_shrinker->scan_objects = nfs_access_cache_scan; + + shrinker_register(acl_shrinker); + #ifdef CONFIG_NFS_V4_2 nfs_ssc_register_ops(); #endif @@ -175,7 +180,7 @@ int __init register_nfs_fs(void) */ void __exit unregister_nfs_fs(void) { - unregister_shrinker(&acl_shrinker); + shrinker_free(acl_shrinker); nfs_unregister_sysctl(); unregister_nfs4_fs(); #ifdef CONFIG_NFS_V4_2 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/cUT0KIgLFEZlKONskRckFj3d6BgHzMgfKuJCimqVUtg9ZS8d3YNkE4bfBFrFP6kQajWHDZQ3bbd7XIbSsIg7fiUVcEoleKpuXXSQ2b7y1q0AqTuDuhp3xC4z+haZqD9q6QJh+OIKV+3GE7IoKlsm8+cBsSW2NhFECV3VL7MBSd/zdURETMhCJMzTpKYkyYzQyMlctlcZP9k/FnEsmViA/+GAQ2dFTU2qW6mWgy+1+KQgWvghrTvMhp/qG5AHSSXwdK99+mQtAWGc0YdLrbjhhBN5ksIwkhQnnEAkDoEnDIYv1BCeL4MuxsiO35F4iBskFTEoXFrCNc7z5D9Eueio5nAORRKHiXA/2VUW3lYFEyKQQDVrnNqtfqiogJzYVaNAkH6JcSuB8sMJ0CfFNxOCAT3reV1PQ0F5mbOUxNTCbXJZH6AN10q2x2ZCtbAfGlVnJQbTqyxVEymu9eM3Di0rKa/w7POBUoaIHqT3v+dPinNnVh/CPN4xh7jca9/jojK+l2XNWgXabsR5KM73Udc1wQidkkLaPQiv5Hc4ttX+4/OaePPM7AYBGOri2U+e0bm5uwk1AfT85w65jCEL7GHkdQtRUTbWt1rF1p0nyxzn8GA11A/JiDTu43GCP0lSwWnSRYruILjwbjKh9oKdfuwCE2576/2ZxCdi8AJGRiY11Quetz4rmcYOoro50XF8cSVw36k7TbJWAX9ZZ/jkbBdngm4dR5ix6xz14FhrxrDBbYC+K/6/PHRiBYjyWvBS0pUmbEJG0RDOPQbmfwPFb7jPViQa1RcyaPo4M9scef3eIkQ2Ppp5Quivf5UFWuMYz/77Gk5i6+eFFZvfIbVTRV k5M8l3fQ V+gO2RtqljeVOCCDbgiDBiAiNP/BlA8Mbe6MiXClBegYtvyXCOXxZAI0a2N+Hkzg5AFDc3LOTHAPwn694W17QU6V4Ia2CDvml6aQ7DV3qwyj2HmvUHG13OPIhfxFzo5ppJQJHE2MKpudT25GfNW6nlNEW1K0nYGN3ERfWWd0GtyAAw5lqLFqfdwYZnd8fueQxPGsGGbdMEtxQ0ID7cElb/ldis+Y3elSqePXkx8kkkGeTF8X9D8aEOVOL+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 From patchwork Mon Sep 11 09:44:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379067 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 F1B1BEEB57E for ; Mon, 11 Sep 2023 09:47:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 938B66B01F1; Mon, 11 Sep 2023 05:47:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E8576B01F2; Mon, 11 Sep 2023 05:47:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B0A86B01F3; Mon, 11 Sep 2023 05:47:08 -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 6BF246B01F1 for ; Mon, 11 Sep 2023 05:47:08 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2D20A40908 for ; Mon, 11 Sep 2023 09:47:08 +0000 (UTC) X-FDA: 81223838136.30.DE333AF Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf14.hostedemail.com (Postfix) with ESMTP id 5462F100018 for ; Mon, 11 Sep 2023 09:47:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W+mw1LUM; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.174 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=1694425626; 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=X/NLyvMhlfztd4qbZrL/omLXYwwIYQMNFU1MSKt3KHU=; b=LgeSOjP12JazEyEvv20w4rdhEnfMt5Fiz0JklYA+Yu9IpCYFXOpI1iv8bm4qKyWr6CIWN6 KORmuEkGyKFG71/wBLiUJVFSgF9u/lsjwyxEWD8Wblxysy/+HktxAWQljeh8Tha6n4XL/q VfSQjtufumyMIekwM4XNjDOAptWDeG4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W+mw1LUM; spf=pass (imf14.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425626; a=rsa-sha256; cv=none; b=r6D8wthJ7N9frhYJFdLG229Zp7yfanwdb7IeR0EsENd8uDBmEUvBaNbKvopx21tFMnZOfO tDnJ4lyVWBZs9T4FRGrO3zPEOVbVQs+Yl4R+y2EocRt7nEDSPu1Sq+xNzkQ4nNHSIo2Zox H8rK0/tcQHNGdgG3Uc5qckHBavD+XEw= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5657ca46a56so444985a12.0 for ; Mon, 11 Sep 2023 02:47:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425625; x=1695030425; 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=X/NLyvMhlfztd4qbZrL/omLXYwwIYQMNFU1MSKt3KHU=; b=W+mw1LUMgDy1qWf2QfRA10of6d1C+9RgSnkVlEfhUDvHKgLc72hZD2jW3oSnXNnWIR AV39WPCdjRQwZMDfJYf0cGQzNSiL8t5CEJANZUt8nPjlJ7Q+cwiH03CJWnJ0k8KL3egY OK/+RAkuyG4WCQBzTql7vBtG+LDDQAsLQIWgWsYNDICtBbTe2S9cbwbm4kQzl5KhIamw XjFi96u/FRnDcKQSSsThl92r58xp7URoNvMNd9eTYbUuRDSxCv3Y8EfffielBQ27KAWG AbKVCzMlGrUUChHXGVxTExEGmjDd2gTVfvznjB/J7+UK1iYxGXBCNn1qypTYIHHxgxo9 599Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425625; x=1695030425; 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=X/NLyvMhlfztd4qbZrL/omLXYwwIYQMNFU1MSKt3KHU=; b=FxnTxbB37YqEElinaKNOu1TxYOYZkU5RH6V953Neuh6ZZz+NnUq9X79A0zbGd3bR7h 7GuH8CbY4SeD01YTftfT0cgm1VCT+9FXizeM7sY+o/rPcK4ynTy/tOH9YYddZqtj0cW5 QE5Z0ki96a8AtIfcio2gLZw9GrvAcstyZgtpc8coPQFrt8pMQr27g8FgJOnfpaRmVIjb t+6TNQEIoi7tafQi5wcBKzvdml0LdgkJnZX6Bc8Ay3fvzuIvlnUTcthNF7dGw9Xe4d4X zqKqmUf8jaHSNjR47pnJIDTlNroG9QTF+3JCzLQ2mkQySczRNx1+KxdG3pvwKy+yAcHN JOYg== X-Gm-Message-State: AOJu0YzeIdGcqYfq/zgM4sJCxprmS+Uwq9BTLSGPXuY2oNyzO+SAPf6f qOEosDKr8s+2oi2hgQgIGIPB2A== X-Google-Smtp-Source: AGHT+IGDEIcfsclwcXdbuDvH8sZ7NfMus7y6m3aPNdiNFM1+TgiFCKX9tglqgiD/ZZx6tB1zl6Vfxw== X-Received: by 2002:a05:6a21:a587:b0:123:3ec2:360d with SMTP id gd7-20020a056a21a58700b001233ec2360dmr13693947pzc.5.1694425625285; Mon, 11 Sep 2023 02:47:05 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47: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, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Jan Kara Subject: [PATCH v6 13/45] quota: dynamically allocate the dquota-cache shrinker Date: Mon, 11 Sep 2023 17:44:12 +0800 Message-Id: <20230911094444.68966-14-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: 5462F100018 X-Rspam-User: X-Stat-Signature: 9pppb1qxf193q9rc4ptbsdn35pke3pf6 X-Rspamd-Server: rspam01 X-HE-Tag: 1694425626-415521 X-HE-Meta: U2FsdGVkX182FgkSFhZcF5vCp91RHp8n9kWGM0bbTlgD1xxDt14zHddr8obGIA0p6ZN+BjiBFZ5uSH5U16LeOYNiMIxqNkmwausfXlFfQb2xFrnVr8MPnoeEmJzhnx7RAGjxRmSeQIYKl0NBIacWmyKWJq2y0iFfXrty8EmuDGYHU+QMQ5J/piOR8y3V4Q9EKkXsf8uh6qQA477raXrbS2Bn7rktyDk0is2YsS3s04LKtMlOB+omuEUPpwtfZZeS1Xo3sWOTRuwv8aMFVjllwB2V6tRUc/k6xfPs5L0yVG2K5cu3LlYKbKTZxoRlK8J9n5tIWwv2U3hsFRG4IDK4/GCb8xR1KYTabQR1L/TqAi9L4bKFvFHV8GJysvS7TDqlpfa6rzR38Oo93KBttVe9e1S8nYsjoZbAQRfuO5TLW1UKYhpIocjRMtD39oVQryzfdpTznCbTdn7ZyGu+JiBaDDVfoM+jOadcOUFzTS+OL1rRX8nrn/9Z5FNU8RwfGutZbE4MN8jzUdbiGkxK+XLn5j1sAsaoVTVvsLJ3fUbwW6zosPxQdA36llVSKMTc88FqzsJhW3u+mebuz/YSO3Y/oE490wWIHsRdC/P1xzdHMI4xejg4XbWG9oTwkvBPf2nuO8WvBe0hxfwkNJtfMaC19hF6st2/blPscJ+vUOiM9GcDygF7HSnwV7dlFWXtKBJl9VCOoKw5FbEdKJ0Gn0VGjzX1dE2DnS81+fWqYWLRRnv/tjokl4xALEW+Kh4nH7yEylvCdK10uRSnKc3nbvFViyqcevz0SbTy/FhisP/wpjnAqvmMl4qZjj66x8TS6tM1q1fYsY5fYKaQhCQxjShYKtaYPj2AdWBEfMEqWsekQjozUa9Avj/qBybN9LoZig4ojdpduzEh8a0mbkzaOIQ8Ni3/O9yUcIhxyP2idr+6yfB/glAmHVxqMjbe5E0rNsgLkuyQZPAoq6fg5MKzfSy R72vwaqP /KoTviBdwhdfJpJM/SN4bKXMUj4O/jyruueBqrVVnd7EwPlw2JCG279oc3j1sTkEKNnp5RLs35/NKyNP3bIXxXqKa+ffOW1h6xNfgC1zuC2jh+uO07573mUdtqTizQgyB1LrH/G66QFjTMNk1W61XJI63NylTMY0bALp3UlZmfQn4qb4OSd1qpKE+9yIFLFVoC0WFYScjGSpYVRUUoHWOwthpC7/EHhIlB+heBJQgl9JhVwmbz/fq33loR4QAWLD03xJCoYK1dzlUNknz25H790ZK9bbNbTgZ36tJp37sFv02RhT5XG2w6CEH4B71E8dARZl7huNlgnpqMK3yTGquYloHE5w3oFBhfvwf2Rd01G565+gimHmCEA1vVjEFrSPDVVfT47tEyMOt6+f/erBAVwTIxGdvbhoSMTkJ 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 dquota-cache shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Jan Kara --- fs/quota/dquot.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 9e72bfe8bbad..15030b0cd1c8 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -791,12 +791,6 @@ dqcache_shrink_count(struct shrinker *shrink, struct shrink_control *sc) percpu_counter_read_positive(&dqstats.counter[DQST_FREE_DQUOTS])); } -static struct shrinker dqcache_shrinker = { - .count_objects = dqcache_shrink_count, - .scan_objects = dqcache_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; - /* * Safely release dquot and put reference to dquot. */ @@ -2956,6 +2950,7 @@ static int __init dquot_init(void) { int i, ret; unsigned long nr_hash, order; + struct shrinker *dqcache_shrinker; printk(KERN_NOTICE "VFS: Disk quotas %s\n", __DQUOT_VERSION__); @@ -2990,8 +2985,14 @@ static int __init dquot_init(void) pr_info("VFS: Dquot-cache hash table entries: %ld (order %ld," " %ld bytes)\n", nr_hash, order, (PAGE_SIZE << order)); - if (register_shrinker(&dqcache_shrinker, "dquota-cache")) - panic("Cannot register dquot shrinker"); + dqcache_shrinker = shrinker_alloc(0, "dquota-cache"); + if (!dqcache_shrinker) + panic("Cannot allocate dquot shrinker"); + + dqcache_shrinker->count_objects = dqcache_shrink_count; + dqcache_shrinker->scan_objects = dqcache_shrink_scan; + + shrinker_register(dqcache_shrinker); return 0; } From patchwork Mon Sep 11 09:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379068 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 B72DAEE57DF for ; Mon, 11 Sep 2023 09:47:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B7156B01F3; Mon, 11 Sep 2023 05:47:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 565F36B01F4; Mon, 11 Sep 2023 05:47:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4605D6B01F5; Mon, 11 Sep 2023 05:47:18 -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 319A26B01F3 for ; Mon, 11 Sep 2023 05:47:18 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0E78E1CA407 for ; Mon, 11 Sep 2023 09:47:18 +0000 (UTC) X-FDA: 81223838556.12.26A62C2 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf08.hostedemail.com (Postfix) with ESMTP id 47097160023 for ; Mon, 11 Sep 2023 09:47:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PgBekoGx; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.41 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=1694425635; 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=4NJRoYJvtB3JAQ6HjBpWzHn90j4fvohvXnELHULg3ZY=; b=XbNhZbdlAkr63R4w2wVUq6DKHFys7RfIWHOWIUnaSlBOsBL3eiF9z22bH58OFheI0FMI2E koWQFUtSQEd7JrLZntoT7SWPcEHrNFzpkDxMQcq1UlkuCCjrUjMp08jnGxMnYoXY1K+za/ oCJ1FH1+CJ9RlBckQTdBfeHxmQy2I9E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425635; a=rsa-sha256; cv=none; b=2nJTXc7WDBFYw/a8abIZOBf6nh8olYDb3iZV7jMXB9s/lEmj3g1/jWtg5c/Tcpt9aGan5D QivbHnKMCp+otmMzyxQ3zTEwuwzfSz/K38K56wfIz9g/Ll+5z+/3BSRXybhhLPE/OBuNJR PYi511SPRSUcKL/Jd9IKscnOnnFyuec= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PgBekoGx; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2684e225a6cso580089a91.1 for ; Mon, 11 Sep 2023 02:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425634; x=1695030434; 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=4NJRoYJvtB3JAQ6HjBpWzHn90j4fvohvXnELHULg3ZY=; b=PgBekoGxO6AziXcRWNgpDPQXEwwttTpz2Fp807uz0wU1lb06yEWcfqg6uWHiD6KL+m 70bD4zElnhxUcSRfxX5lMCBqSwPHS7nJzaaydTRfPV5Drx8rfZCr8n6bue+dkBayyzJp 9RcR6RkiV6EvqJpuf2R6EHX1TVcUsSRnWG28icXvmaSjovZ3Wiq7PARmHmJEisnZPIPH T/5tqkfjrYawm5o2U0t0Ewb8Y/26LL4xF9vOSOalwCB1RTbHRMv4YYyQ7SnY8lfHLvLH ZTdb//YnjZfR6Sz4JFLoo7jAfFSs9k+h/k829OMakNlCXIF5XBJOX+ZrmVlsHOlWnUxn +QBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425634; x=1695030434; 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=4NJRoYJvtB3JAQ6HjBpWzHn90j4fvohvXnELHULg3ZY=; b=XfAqDtwty7/E2+XEjyNtVCVQ0ytI9WIAvDrmJtGLH1uQ+xK03zDwTrc4JMSNSJRTwX yzIdP6sDgf2bA+LJgmbzbzg5+vo4ZMYaWWXW3yFel2WSWRiXjbjsdDc62N4XMpk3tXjR mTK1Hsvr10GIpd+uSEWNKD8gs5qcG0digT7i4rJaBIM7aTjj8k5UOGsD78v1eq3PnPRt LlOlVjc6nqAZEFGH2ju5cT4zTGOujesMmoQogq+SShFBzhm3iHabcZosIqSgFot11IEV 01ScrPi0lalqO3AOAgBCReLPWNHRyi+0J1LiqcsceY7zqY5l7rQxHSWOpuAHDhogUiVg dSkg== X-Gm-Message-State: AOJu0YwBFvWFulDlAGZGoBRJg4ICjDp74RRqrq/wCdJhpRZn5W6jnnmf n6V2a9i+KoooiEq3eV1w2vDULQ== X-Google-Smtp-Source: AGHT+IHGrhLYQcHrSOL/A0AfShLW1GL1aOG0gH1s0a/WptYINVPGtQZkcxOK/Zv27+cAk2ggUFIjmg== X-Received: by 2002:a17:90a:9bc4:b0:273:e4a7:ce72 with SMTP id b4-20020a17090a9bc400b00273e4a7ce72mr6446431pjw.3.1694425634193; Mon, 11 Sep 2023 02:47:14 -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.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:13 -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 , Richard Weinberger , linux-mtd@lists.infradead.org Subject: [PATCH v6 14/45] ubifs: dynamically allocate the ubifs-slab shrinker Date: Mon, 11 Sep 2023 17:44:13 +0800 Message-Id: <20230911094444.68966-15-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: 47097160023 X-Rspam-User: X-Stat-Signature: 7kkepsd48f9h8dtkz7bmpc3kaw9hrhus X-Rspamd-Server: rspam03 X-HE-Tag: 1694425635-660495 X-HE-Meta: U2FsdGVkX18TEwm8yoLMZPuM3epZ/Tc8MksyD1t03mh3rqkPsk1YoBo2J/R5i5Lq8TSYSaQ+9slQiaxlEtnI9dHy2Gt3IoQOb1zcYQ/f/KavCx0Kr2eI5lTemYA1EvjtqoQRZhBeyYK/vc68ZSEHU8uxrrDEntR6LxF72G7baBIOCCMqPb7BIH9WJlvEjbhu6hLJCHIGN+YYY3eSPbBmnNCpz6r5X/dyv6nL/omogqtbyc7hC2YBMyisP/ywo3bN7RjI+3nKNfYE+9wZXcX2uc4ouejQZ52l5VzKBeDtl/h2k+UWRsKY+c8oXuoiVII0CsxS7eq/ubGQVBQSVhiKdfPWb/NIDCfSKiGqQFXxtKBUSSA9JtztNXFJ6F+rxzFB7ar0ccByXZ0PiiX+3VGlmEaW5+3PQzabtjVQ9HkDceHZwszqr6kPbEGLMQyMXqxN4FWtd+eCdpIlmPrEQIKHkFnmkzI84uMzPvIb9HQmWhqDaOPJYWfc3+KuA2sEFuGBMi5ssWy9vWnqpsqfCcrgWoIOn+zAR0hEXnNw/3uCEhGJ0iOAYVUCsBvNob0aWSHVxg9HEn1BN0J5zg4Gg8R0k1ZFdjz+uUC9paVYlxJNgcNM6VQRC/tjwRxHCgreZIZRMOGcEYLh2m/VLWlIShnCXnyIQ2OQRKUJqK1CCzCmZ6f8OsNftPwJXZgiAMG++7d6PA8Hj6bxb3c+kr3P/frQ+ynyii6/sH3PvhuHGPgHMKs/O8Ta3B0C5RO978BNp9cdcP/fD2CibDDRQ3xXHDkB5zVANPtT030n0gQwfrIoPqHo6R0bfo7IOiBc03EAsjH3HrEOlFn4si/OLTkVIdysiUQLCYo+NdB3Fa2m1h3gSj1B53/oK8BmlL7Egx1MRS2KjaQJVYpGb5Qya72O6Rj31gjf1yhNUO7IQJR9EOQjgrvn5AHBydR56ovNSo0Uwhsqgh082hdrzQ8eAlVjHS1 /woyjx2E cEOymARS8jP24+9OvE2nxRnrocZLncpmxOouVJDeVSLE05szoXlpHIBU+vsShrRNf2O6DZZxvZ+qrj3IPUcddyBIkKGUHGboD1P/95jFy2EpvBYUDSvbfPlKA1kh9hm7/0/KAKVeSi+a2ahLbgJk9X95tPKqC2wEZuk7UoNLrmrUfpueli1zKdYubqmhnO9IOFJZokC8rEPcA93MpyqSRDNmwBFb6C5KU8/tuxDYA+7hxpYIA7v3hWObemVSj4kkNIaJjp57uZ5fDhrodDFs3jMBXEQXjm7ElmlD96U+n8cCmC4xcHfPH6qW+AjturOdLJBPxbGUmGS8IGxSPmYanU1Uh+fjm3bmUDrYoSHBMdDFZf2uMLx5YC/+DCpLX8nVVW7XjxnnUal051xeDwMzkwHKc2YMWeQBeG6FEoWoZbF4UZ297iIMOzQnPStBGvLDyZPcpSAylrjzIFScVTe3S9o2en4hWeO/b3Q8k 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 ubifs-slab shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Richard Weinberger CC: linux-mtd@lists.infradead.org --- fs/ubifs/super.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index b08fb28d16b5..96f6a9118207 100644 --- a/fs/ubifs/super.c +++ b/fs/ubifs/super.c @@ -54,11 +54,7 @@ module_param_cb(default_version, &ubifs_default_version_ops, &ubifs_default_vers static struct kmem_cache *ubifs_inode_slab; /* UBIFS TNC shrinker description */ -static struct shrinker ubifs_shrinker_info = { - .scan_objects = ubifs_shrink_scan, - .count_objects = ubifs_shrink_count, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *ubifs_shrinker_info; /** * validate_inode - validate inode. @@ -2373,7 +2369,7 @@ static void inode_slab_ctor(void *obj) static int __init ubifs_init(void) { - int err; + int err = -ENOMEM; BUILD_BUG_ON(sizeof(struct ubifs_ch) != 24); @@ -2439,10 +2435,15 @@ static int __init ubifs_init(void) if (!ubifs_inode_slab) return -ENOMEM; - err = register_shrinker(&ubifs_shrinker_info, "ubifs-slab"); - if (err) + ubifs_shrinker_info = shrinker_alloc(0, "ubifs-slab"); + if (!ubifs_shrinker_info) goto out_slab; + ubifs_shrinker_info->count_objects = ubifs_shrink_count; + ubifs_shrinker_info->scan_objects = ubifs_shrink_scan; + + shrinker_register(ubifs_shrinker_info); + err = ubifs_compressors_init(); if (err) goto out_shrinker; @@ -2467,7 +2468,7 @@ static int __init ubifs_init(void) dbg_debugfs_exit(); ubifs_compressors_exit(); out_shrinker: - unregister_shrinker(&ubifs_shrinker_info); + shrinker_free(ubifs_shrinker_info); out_slab: kmem_cache_destroy(ubifs_inode_slab); return err; @@ -2483,7 +2484,7 @@ static void __exit ubifs_exit(void) dbg_debugfs_exit(); ubifs_sysfs_exit(); ubifs_compressors_exit(); - unregister_shrinker(&ubifs_shrinker_info); + shrinker_free(ubifs_shrinker_info); /* * Make sure all delayed rcu free inodes are flushed before we From patchwork Mon Sep 11 09:44:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379069 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 4EE5CEE7FF4 for ; Mon, 11 Sep 2023 09:47:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCD816B01F5; Mon, 11 Sep 2023 05:47:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7C9E6B01F6; Mon, 11 Sep 2023 05:47:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C1D806B01F7; Mon, 11 Sep 2023 05:47:25 -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 AE79B6B01F5 for ; Mon, 11 Sep 2023 05:47:25 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 90D451408ED for ; Mon, 11 Sep 2023 09:47:25 +0000 (UTC) X-FDA: 81223838850.21.FCD72D7 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf20.hostedemail.com (Postfix) with ESMTP id A3DC31C000F for ; Mon, 11 Sep 2023 09:47:23 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lq2wkk5+; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 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=1694425643; 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=nO5XG1oNP6pUjS3WN2+RrRDElLAKlnsgenuSaZhp694=; b=UBoBncW2XmxXN545OHzrLo9SpKLBhhJ5SC4JetMj0n2D+L51707J/Ps/TpgT0V9gg5p0bF u1EEEqsJ0nwZ1NYoohUPt+dSZtCbKGuQQvtApIgbRXB7zEnMhTnxf0BlFDKTBqIkmeTgM3 15+PoSocJjB0exj2MhBE68a6l65XVAs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425643; a=rsa-sha256; cv=none; b=ZXv6gPTs7mIAKqG1MEj3vCdSyRKHUSWAmRuTh7oN/c7keuPWLHqQftRN9xoIFdXgD4fOnD MUZIfLa0yeLtMGa6jFcfdRhTxQZ6TIfZSUD8JhuSV11edfE+gRkXL4/7AcMeYNC49lmGf/ EZwWGGi7IKcQnFGVgGMifhaKblBjBZQ= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lq2wkk5+; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7086865ad.0 for ; Mon, 11 Sep 2023 02:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425642; x=1695030442; 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=nO5XG1oNP6pUjS3WN2+RrRDElLAKlnsgenuSaZhp694=; b=lq2wkk5+NY/scTOQcOxfdalCVh2v5nkRJ8qfMWOUEP/DTLN5DMLn/5URKbWxqmlrEt 6zEmnG4ToDNn8vA6PSb+Nmyb2oqspl6n7C7Vq8XBBLIDgiAV8/8HyLD6ks9TGcSUVg2+ ZTUb6T/oWN3+fhjYh5f7UoRtf3cXrUxBFCF1AyOZWAMxHu3/dmEMwkrNdqoFADOfwi87 FCvVCa/LHbqg9IJ3jmTtOqjSOc7C76QF6QOtRR0W4QJM86sdHCiCf+xb2DxnhVvvwLjr MCve6ZSwj/kZcqKHNejY2/FDyEfeAjCxe/PA8p1MrBFqtD0TFpGdqt9uXlbHGwEgKH5y xRog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425642; x=1695030442; 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=nO5XG1oNP6pUjS3WN2+RrRDElLAKlnsgenuSaZhp694=; b=MlR3R+0WmQ/iHiXmzLlsRQCJ7unwTzsknY4Ir4S6EDmV7Zt/3s7IHn7VPpoYRk7oWr qObCSZ3SD8uUEJ3nFRrbJhobeIWSuPV8tJfeHI5cNi/r/mXkWVemma4YBXaTAGUeNTtW VZ8czO23Qyvgxu2ROZP9++i2WUHR5/pBdq527aYyhbxxRGmgxuT2GJRB5cbyOQz+MNMQ TnCPrbK/sssBBwDTKFNfJBNTcdhUJTTUQj+dyDACZYs/n1WboU2hXCaU/cVdxfKHXLXR FGe9HxBeNVZzzvupb65os21GEXSID9e+kQPpJ5spL3oEp/T6gGpXe8c2bVPB0k8v+ich b1dw== X-Gm-Message-State: AOJu0YxspQaQoWLEZTedVFIrebfry+52uOk68ciwr6+Ee2hxigLSBUaA vMi6Y+RV0XtmkZDR03JTWNfXUw== X-Google-Smtp-Source: AGHT+IGU0jWm5aUKgo65aoc1FmWqzP1rWPbNbFl1TEnUeGhWf2rII1K9xqSMkpAW8Vpnx3sOpXBIKg== X-Received: by 2002:a05:6a21:a594:b0:13e:1d49:7249 with SMTP id gd20-20020a056a21a59400b0013e1d497249mr13273426pzc.2.1694425642605; Mon, 11 Sep 2023 02:47:22 -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.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:22 -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 , Joel Fernandes , rcu@vger.kernel.org Subject: [PATCH v6 15/45] rcu: dynamically allocate the rcu-lazy shrinker Date: Mon, 11 Sep 2023 17:44:14 +0800 Message-Id: <20230911094444.68966-16-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: A3DC31C000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: iw1pergszpdxzntf8hoyg6osefap1dm3 X-HE-Tag: 1694425643-984884 X-HE-Meta: U2FsdGVkX1/JLXlEwDoLjiBhViDmkYaAlNTQY3Xw7KmzJScDUNslAKVSLEnHqxFOXtgBoLeNEtclyX01+1rgdMECOgeuqAtYDPvS42ejoSYcJspJQ/aMVnVYweMqausv2XExHqmblH3tKZ0uMMuRb/iNCz1foKrYCPwwjNf695GtyGJCl1dotI1HeSVaeUIc1jpzyZSLwlwRb83MsiIyYDO0c3S1mxTzzJ5Ef5ilUsc/dfT9iofU6jWwbE8cVNOitFuMPpATTVtAj5+4waJd8vBaalviLN+hv5mrYmWcrdAyPrHFYJ5hMqQrdV40BINEwGcaUdF38/U8IFMACBXt3MFDLhRkXUDs8mCaLM68DFGNOhk/flPtWFMjXEMMbkl5mJa8v1W3BMd//p8EdwzGDugrhXfUExC31/BBAp+pmHhfUHSox6fer73HQSbw9ZAqeuJi0apRkCHNnfhFjJFdwYbwqcv7dJmuxo9KZkW6E9U3lxaCjzZopwmgJhKAoGnTWA9f26hLl5Yb0zH+2s2a4n2ilxIxjyNJyeBoQ5X8LYuIzOBk5rb3d/IUm3Z3Muk/HfcNNdezMy3kKseRM1Vvplw/ErNiGIOifZbtZNvWv0M7+KqbQ4JA38Y2w/MyJtBR/kLScgsH4h0E8n9A8fAz5dSW4ViNrHwl4vNl4QSlpV3tKeCnsvtHU+NyhAVKJv3iMFz/dwwF1JsoTpt/7JQT2z6Ch9+eBR4wWfnwuq6tQWz5ZW+ZR8K0ZRG0ZJKwv67E5DogH1F4fc4LuVf8XZey55+YHocjs2sWaQDVphkWl9M5gFdphcGuXl8ic9rnuZ5I3Bz3WqGGm5YCU7UOBqkRTLK7Xp3HDK9bkb6lT7kqKxtAZvnX/+/Bnr0ZKR8FO9SxcRVCS954aCcnjkVvxNmNiJXIoOHnsefmgefmXB+5eSwTNTMDwYr1PkSaw7nfPeYzeI3APazP6qN4Lvt63Bw mtbnjtG+ bY+mubZmsuYWvmTsk0uu5rdUA/DzXvJYQe0zhh3whDBRtRrN/POxhi/VxjS/bNjX+jEuDmXq+v6I2us+WqqN5Uqu2EvXBeDR85G74xE+eeK6+hda2V6PNqUgvO2bUMNu8vTXp64tftcRbjZVsg66pam22mh9FkzsyRmGbKsziX7dqKg6P9PnwtspOoxiNzdn8gPRDNZ8yibl4wiYIE8g6vMCEv/jK1n3M9URCuyPxR8hhPZlm04bLIKIPyvCo63592VoLVjl5g8wR2H86EGmHQg88+IT5QBCDLZTXA9DOuFOaeUzpyYv/VmPModkThanD8AXC4aBdtLNGS1pNb0ssegO6HrJrvnKhguo/qNcjSZ1HkoZ10sCLewvDKyHzx12rD8+gIndQVVEAIRzj2Z2V9UhBkzmCY/UdFcr7A7Kg6ovOkZiWi9Z+zcEeznQMu6B8xeEuBVbPx717bHzqfRpvQBT5icaLGRWfMTACax01Lmyqgr7VW9kOvXyKdQr+NGUyycCXL3F0xQgr4ySnoEXaB2K5xA== 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 rcu-lazy shrinker. Signed-off-by: Qi Zheng Reviewed-by: Joel Fernandes (Google) CC: rcu@vger.kernel.org Acked-by: Muchun Song --- kernel/rcu/tree_nocb.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 5598212d1f27..4efbf7333d4e 100644 --- a/kernel/rcu/tree_nocb.h +++ b/kernel/rcu/tree_nocb.h @@ -1396,13 +1396,6 @@ lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return count ? count : SHRINK_STOP; } - -static struct shrinker lazy_rcu_shrinker = { - .count_objects = lazy_rcu_shrink_count, - .scan_objects = lazy_rcu_shrink_scan, - .batch = 0, - .seeks = DEFAULT_SEEKS, -}; #endif // #ifdef CONFIG_RCU_LAZY void __init rcu_init_nohz(void) @@ -1410,6 +1403,7 @@ void __init rcu_init_nohz(void) int cpu; struct rcu_data *rdp; const struct cpumask *cpumask = NULL; + struct shrinker * __maybe_unused lazy_rcu_shrinker; #if defined(CONFIG_NO_HZ_FULL) if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) @@ -1436,8 +1430,15 @@ void __init rcu_init_nohz(void) return; #ifdef CONFIG_RCU_LAZY - if (register_shrinker(&lazy_rcu_shrinker, "rcu-lazy")) - pr_err("Failed to register lazy_rcu shrinker!\n"); + lazy_rcu_shrinker = shrinker_alloc(0, "rcu-lazy"); + if (!lazy_rcu_shrinker) { + pr_err("Failed to allocate lazy_rcu shrinker!\n"); + } else { + lazy_rcu_shrinker->count_objects = lazy_rcu_shrink_count; + lazy_rcu_shrinker->scan_objects = lazy_rcu_shrink_scan; + + shrinker_register(lazy_rcu_shrinker); + } #endif // #ifdef CONFIG_RCU_LAZY if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) { From patchwork Mon Sep 11 09:44:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379070 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 8BDFCEE7FF4 for ; Mon, 11 Sep 2023 09:47:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25AD36B01F7; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20B676B01F8; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC836B01F9; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EAFF46B01F7 for ; Mon, 11 Sep 2023 05:47:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BD71DB3A3C for ; Mon, 11 Sep 2023 09:47:33 +0000 (UTC) X-FDA: 81223839186.24.67D266A Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf26.hostedemail.com (Postfix) with ESMTP id DD2D4140006 for ; Mon, 11 Sep 2023 09:47:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MVCFztXg; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425651; 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=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=LxImgOy9+C6GgSr5jyZhkoxaWnx6+xiPSNyOKxxbd51JN689chYd3H4JIQZqgGL2/v+sPA e4G9Vyc2HkcPxm2q7Q0L+rIUwIbGvfgo8Fz9xspDUZOzW4pKMHrmxAP08NPSKHlffE4x/e O+bd997DfmW9DPwA9pO84Sdl3UsiO/4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425651; a=rsa-sha256; cv=none; b=oCbF9jBl1m7PG9qrK7FwyJERIr3ljmI2tL0lEq62Uj6+D11wrHSTgpQoRxavU+eX8p2J9m ikq69vgh/14QmWnzho5Y2pZ5b1SKYyyGTLwHFAMqrF7oRe3Dirg78ZPWUpDK77NfY7PpUq zUJhNRvWUsAS55w6L9YaxcPzXEVhrl4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MVCFztXg; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c3c4eafe95so466035ad.1 for ; Mon, 11 Sep 2023 02:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425651; x=1695030451; 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=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=MVCFztXgZ+GmO4r/HgtM/ZI8Cp+atdpWVwHMM3FtgVCYCgCfXcV2p+6kwvcpupZXkW 7vj38FaG3OODbQU8yT3ZTs4O2YT72gpUOiDO6K1JS7UpRc/akAT/EumNgxn39ZXlwSoh zW7VO14cSzLWWx629+YEVpnofRIz4coGibg6lvMOZ8/DBfs5+TKWQmqRaepVzYoitRAS A7EcARreGe71Df5AqqYECMkwy0UV6zROkRY9yWrHcYSSuItsZ+Hztx7iupSHDSFrQhKE z7Ms1KHGlqdUxa9JtVrzvXDSOsPuOiTGuCxycolK4MMbwyaUgqpjdh2nJciPstJ90B0T Q1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425651; x=1695030451; 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=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=awug1UEwPrxruafUA0goVAnFkxHQ38CCWrAKw5tsQ50/6X4RxyiGNTGEBMbdvkFtDK S7Unyq7xT0GfAfbUDdI9t3u2+0qu/0ML6vpiqDWE4aDYmvTN+FymT/tqak32HzNmfxkg Pxk9spi5J1ZOUY7go3sUy4gQzpABMphCVbIQqsHq9UzL7mgXoOCCTS0VcdkHc8RdzQlV 2KYYTCQPrL7Ho5AJk1cbtIL2YLUVuyzyLsZQv3LjmT8Bqi51YZWP+A6AZWbPcCBo34g4 SjsflX7z6xNISczleDAPRvuXmB7NntZqRLisolmTuB7sEd8MKi+BSVdzoXmR9f3bybpo ozzw== X-Gm-Message-State: AOJu0Yz/SI8dtuMughlOf0VVu6Z2i4XiKNzvnUf+sb7jgNz5JtfvwvIL zh9VVWwvogfvjHQWFfYkm1kQaw== X-Google-Smtp-Source: AGHT+IEl2mpYTODnECMCuBDNAite2AZ131Yxo4SMEA3+9uaLlCuqsjdY37DnC78Awa2ltcDCzu5lqA== X-Received: by 2002:a17:902:d4c3:b0:1c3:411c:9b98 with SMTP id o3-20020a170902d4c300b001c3411c9b98mr11085339plg.3.1694425650814; Mon, 11 Sep 2023 02:47:30 -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.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:30 -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 , Joel Fernandes , Muchun Song , rcu@vger.kernel.org Subject: [PATCH v6 16/45] rcu: dynamically allocate the rcu-kfree shrinker Date: Mon, 11 Sep 2023 17:44:15 +0800 Message-Id: <20230911094444.68966-17-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: DD2D4140006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6niqb3ynxe6ccnwzi81m64ipuzmf44r7 X-HE-Tag: 1694425651-968507 X-HE-Meta: U2FsdGVkX18D5sSe5gJaX8khjTyOb510rrTo2hU07e6/ZFjbEpWM1erfLkNLR4zGzI2rnFt5DGzNdXfsTswN54NTH3gRdCvekAx268KpOtBnWEM5mrAVTKmuI/zwuBx85NCFH4BxfV9W6G4VZpscyrEtsESWIMZiwfakBuIugVylinWVK/M1TdqoRCzywjdO3LbaYDdqzdxAKY6+u715/RZCUIBUXJLlu/wN5Opn9webYqo+9ka+JX7kO3WvzvuLq3D8kimQZsSK35dUlrLCsJuADkLD3RnxYhqKJ0F+vKdeiSDqmGY6uzJRhq8aR7NtqszqXPzXP/DRcop0WDtiP+nmS0/APxb8OdWzggZnZF+Ye2UTkp1O/qxoKoIPzeF4Mj6k/qFBlvcO6GFSSwp65mInwGmPchJAzK44T3fbSOFDXctIrhyqCEg1/mEvDnpasBWKnTZunOX0IVlBg0Owp8ihQOcsw/SBm5gMOrhlLGm8enmAriJlNBLA4zLi397YCneavJdcXQ+BLiy145/rdGoZqAlpFYz1A/7Igt7vvW97Pe57jUoWcrg9U53uwMU6kFE3i3I6WMuAL5+b1whoOzDhO5880ftTe3ExOS6H2mIBiR4GQZcXt6FFoS/FWebEACb4ECGVZel7udxveZWD3UacK+uXmiBFKfPMnhP5qci0tjOJiNb+ToVnv81vd1721JJChW9UTIQfTSkxNEFU9Mk25/sBMe4i1yW8d8g6n1Mxfwpok25rovKhFuRJnGUcyoqTlUDwu3Vvvqw3vgp1CIB+vdwRntx+0inZKdccB5B5iGsi+nbj6AnI7Z1AWK35xqnOk1hYaA+0v2n7ibWCH9b/p7f3YAfmB7hBNEsUUoIMon8NMfOO6luZv9Tbul1SitQwjXwpp3QzNOPkE5nfk2jMwUkDaxd+tyEE7tOxpK5xMluuCw5DuHJ9sMq7TbmP6V/w9HuVQPVzyZat0kV Y1Iys89f TWZV21fkKc0wOji385DxwfdoVkNQE/EjtzVURWRHo8+DnW4j8cZ/jclnFYnIVH+tGR3Hcz0wP7+TKPSiY7/pg6duisJ/jrCED2KDAEwvZKymcUdq9xCylQsRptVqlEMTopfsj3TQEGXiX7ybaZOPks60K1ExX7dOT/DuDiEBd4CbD4/cTbYOzz0lYK+Lrns8PC5kdkoh4aZ70HhIOJKwP5mh/IQqiwMue/7Ra5axLt7yMAujVI9JUxdhtVBqow27ThKls9dW+8Go3EB7sauXlsOCbY9CfDdWiUe5OGZolfghskK9hOQ7+dcLWf6oqDWriiAYYzG4JmOHv/Caxrv7J9MspLzKC+pDgIdmSrUdjU0wxIJ9QoyIoJAipko+VclWSHGLpqzgpfyLWbtfaCmynH7/wlikdvKsek4LXwKRrJCKc3bSfNUxY3fqW6eeshp6TaDcE1mxlslHJKkNbMdCbN99ljBQ+cXh110GxmE3GvEoZxgCXEDlk5arg0waZJhMVW8plLmQHtFFznIAOC+r3bwF+jw== 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 rcu-kfree shrinker. Signed-off-by: Qi Zheng Reviewed-by: Joel Fernandes (Google) Reviewed-by: Muchun Song CC: rcu@vger.kernel.org Reviewed-by: Uladzislau Rezki (Sony) --- kernel/rcu/tree.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..06e2ed495c02 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3449,13 +3449,6 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return freed == 0 ? SHRINK_STOP : freed; } -static struct shrinker kfree_rcu_shrinker = { - .count_objects = kfree_rcu_shrink_count, - .scan_objects = kfree_rcu_shrink_scan, - .batch = 0, - .seeks = DEFAULT_SEEKS, -}; - void __init kfree_rcu_scheduler_running(void) { int cpu; @@ -4931,6 +4924,7 @@ static void __init kfree_rcu_batch_init(void) { int cpu; int i, j; + struct shrinker *kfree_rcu_shrinker; /* Clamp it to [0:100] seconds interval. */ if (rcu_delay_page_cache_fill_msec < 0 || @@ -4962,8 +4956,17 @@ static void __init kfree_rcu_batch_init(void) INIT_DELAYED_WORK(&krcp->page_cache_work, fill_page_cache_func); krcp->initialized = true; } - if (register_shrinker(&kfree_rcu_shrinker, "rcu-kfree")) - pr_err("Failed to register kfree_rcu() shrinker!\n"); + + kfree_rcu_shrinker = shrinker_alloc(0, "rcu-kfree"); + if (!kfree_rcu_shrinker) { + pr_err("Failed to allocate kfree_rcu() shrinker!\n"); + return; + } + + kfree_rcu_shrinker->count_objects = kfree_rcu_shrink_count; + kfree_rcu_shrinker->scan_objects = kfree_rcu_shrink_scan; + + shrinker_register(kfree_rcu_shrinker); } void __init rcu_init(void) From patchwork Mon Sep 11 09:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379071 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 B6EFFEE57DF for ; Mon, 11 Sep 2023 09:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 567EF6B01F9; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53F4F6B01FA; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 407446B01FB; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2DDA36B01F9 for ; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0B52C1A08EB for ; Mon, 11 Sep 2023 09:47:42 +0000 (UTC) X-FDA: 81223839564.06.FE27F4B Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf03.hostedemail.com (Postfix) with ESMTP id 33D7F2001E for ; Mon, 11 Sep 2023 09:47:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pn0C7JJG; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 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=1694425660; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=QtJ1AcS3j82DOqP/F1Ak9xXvWKHtaaI4U1R/a+K6EWelx9mBdjSlbm5cYu+d/lPmYcQXlc YnH26VJzhPWTJrAHa+yR29zugu87+4fteloCSyQzjhdG6JM6WT2pD2Kq7atZMTpCOHabUb j9hNsKeS+I9ZgDzfYaseO4UfCVZeYr8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425660; a=rsa-sha256; cv=none; b=LigOl9D1IVRzYu53o4qm+MgiV8DIiLV0mMDmY0PDzmnZLFU2omBlTfOdmVhF+KFXTRcw94 m3t4NIbMwL40yMxP5Y/S7SkpaUqA4dt4KN/+d/yJtjG2yFCz84kpysGWWW6q/Ty9tTBeuS Jd1gajCcw2bAMBHrwtiQwU91QmqpKjA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pn0C7JJG; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso7700315ad.1 for ; Mon, 11 Sep 2023 02:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425659; x=1695030459; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=Pn0C7JJGAgcSf2JKcMgWYvpodi/YwA8vh/l++qxLDqKSv6V3lAz+WWm/5p/vQEDIRi BORvopGa0d/f6z/xvuChlJydN5ddjTr7/EV26ZpHZkM9bxi0S73teFUnRu3SY6c4VZh6 qVpbZ/zwwU6jFuY/vFo9Ng3C9EzkSgffAW5H9kNgnk+2+kMwd9woy/1qvMXQZj014E0N jMwYCzRZQN6aVopRL5N4fZE0u+UA6EAZDVQTiIzeoReg2pLDPW53tFGEyT8KJcux7TMr wwoTxuaEdUPtc91yKIUgeyBOqoqVNOM7hVM05FaHLqVrT2CBDUsq7XR7uDwnKRyTcwmA kvog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425659; x=1695030459; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=a9iElZMqk2h2aJ1YJrENA2B98qm7968hePxhCr0hqDWNLookA8xhKFhUXmVy6SdHOV YRM0sNg8ciynZ4PfdscpimHVX7d9Tc73vZVA5UnrKa11eq6PkKj0W0EqEI4fiAt/bRJF +PKMJduLBbiS3NrmR465BUUFvde+Lpiget7gl7NIHWowRYh7wjtiFlZvtzFA+Gs6/ZCN f/JnkGDB6HoGktFOb0/w6HuB9iZKY884qFLqIrVj7Lv/mkJhiPCo8m1FaB+mLh0hSOy5 h7ObLSfDKGT/OQaXQjn+pJBiyxF4XhYDYj8gukl8S+xlw9BK8f9ZXsxHeE4JDPrSdVgs GgiA== X-Gm-Message-State: AOJu0YyaENwtlevPGUOsoZMF1rFjJbrHV2dAKzGqaCdxVNIR35Rer3ZQ 5IoBU5XidT7odWq9ZYDAtIkTeA== X-Google-Smtp-Source: AGHT+IH2KVNM9Hi/PmmKcKS4mr3sE9GLoL02lCaa5Z7/hioPtgcvnrY94ZAiH3SYey8unqQ3Icvz8g== X-Received: by 2002:a05:6a20:4401:b0:140:ca4c:740d with SMTP id ce1-20020a056a20440100b00140ca4c740dmr14470391pzb.4.1694425659098; Mon, 11 Sep 2023 02:47:39 -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.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47: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 Subject: [PATCH v6 17/45] mm: thp: dynamically allocate the thp-related shrinkers Date: Mon, 11 Sep 2023 17:44:16 +0800 Message-Id: <20230911094444.68966-18-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-Stat-Signature: tsumiux5mj1inai5d88pcuuds7bx1rxh X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 33D7F2001E X-Rspam-User: X-HE-Tag: 1694425659-622439 X-HE-Meta: U2FsdGVkX18OloMShyYu0/j06px+/+c0CVVBxGDcOAXww73sVjMoUr0OyLNZm7rsEeZsnb0m3lrYlAOWQjG3Ultuy9iCew6HsLr5RxxseWhYHAARWA7GJkyvyIK/R/PLnCOnyDmuF+afRmR122Pyz1l4GK0f6zW5lceiuLx8+cbKqPDdDJs5NaowJBD535VdkQVRg+QEW6JHYQ2ebddjsHI7SZUWRFVNpCi+macba/C371yfvF6thPuTAxkMYRRTyiWX2wtFV1o2l6dmcCVQdvC1DGcZYzX6COHO9NR2taXJIbAwTasFOMgcSJ1I1xx77+31Rw8qXA2L9WD27FDzOr/15omZqrzMGH8tuhC1eDsRwg/N8p0t4Wb3KHDi8sT81Feyb9gIH8XCR3ESNIegbzbHKN2Tq5Py2yK8Y4M2M+Kc2TTNZYjUW/I6Yigpv8lU8PY/oDMDf+cOyRdZvB+qwNSMDvT19t+JfbZJ4lY644VfmTjE6WyNvJORkCiivSwwDE6cqqA/NClA+D3q7xaRT/g3xpD2/l8aWNDgS1wpkqA/X8rCGmwm+HtjVGOU+NdA5hrx+Q5CrTSFNkpqOWCw4H/QmgKO/9Me+i4KSS0ITbb6Hy61tZ+5NSnWDuk6YYSyupQfJkl7TvIe9p54G2V/3qG6wyllQ3kHlS36/1CWPHj32Op76ClLxloxAjDSra5Lkf4CCi+gnAl3oRb9UaGUy9lEXOgDa3P99anClcSeANpR0AY+nfeZuhuZIpAqF8Yy3mwQ7hZ6VRfN9EDhi8lJRfx8hpHU6Dc4+fqt4cjD8hB0QupTxmGInKyBjAXFKLJag/X7x8o2MWdNOYiUc62AL0mNW4W/x/5soiiGTOURQpa0Ca397i7zCwxaSjBVNnp1LFhC18dgG02MLa7zdhfyW5O250fm1Eyf0rYz+va6rBu1QXOC5pIj2j13kuxMEdjXO76PIzvpY5VqMGcG/er qsqjThYs Up5SyNU4lOtJv1Bkq+/1tqTWZwOw2da+2eHFWilPjG9wZ1lXY7WhSnv1L0NMEqlygPpJZ55W6yvLFA63RBEi1oxEG2Dme7hZ1oQk0gJBO1coJaBLTm+HyqCOcMs1wcVIcZPONuNOkNuwC8JdcPRhVXEx9bzlSOWNJUtaF1kpyzaBg3+SwWjk4ZOqFptKtJGLocbirl6gQN6qhHgRLrQbozYyKBi+4oMIh92CqnjdpMl//OHjJrSMz0wGA75dyFm4aIjahcAwoXMJ1yk9erC5g9+OWh/xCZUA5yxQzMWJZ92X7reVubLxNDFNlHofTwFjasoBOLaQEWsuUl91IzTIRe6BnEhackKi9+ISP9hRcF35p2udJi3Mw7fTr0ZnHvLPMI83JPGPRxgw4kMeelxtH40LvlP2oSHFJLdTc 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 thp-zero and thp-deferred_split shrinkers. Signed-off-by: Qi Zheng --- mm/huge_memory.c | 67 +++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 064fbd90822b..1cfd83e91748 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -65,7 +65,11 @@ unsigned long transparent_hugepage_flags __read_mostly = (1<count_objects = shrink_huge_zero_page_count; + huge_zero_page_shrinker->scan_objects = shrink_huge_zero_page_scan; + shrinker_register(huge_zero_page_shrinker); + + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + shrinker_register(deferred_split_shrinker); + + return 0; +} + +static void __init thp_shrinker_exit(void) +{ + shrinker_free(huge_zero_page_shrinker); + shrinker_free(deferred_split_shrinker); +} + static int __init hugepage_init(void) { int err; @@ -482,12 +514,9 @@ static int __init hugepage_init(void) if (err) goto err_slab; - err = register_shrinker(&huge_zero_page_shrinker, "thp-zero"); - if (err) - goto err_hzp_shrinker; - err = register_shrinker(&deferred_split_shrinker, "thp-deferred_split"); + err = thp_shrinker_init(); if (err) - goto err_split_shrinker; + goto err_shrinker; /* * By default disable transparent hugepages on smaller systems, @@ -505,10 +534,8 @@ static int __init hugepage_init(void) return 0; err_khugepaged: - unregister_shrinker(&deferred_split_shrinker); -err_split_shrinker: - unregister_shrinker(&huge_zero_page_shrinker); -err_hzp_shrinker: + thp_shrinker_exit(); +err_shrinker: khugepaged_destroy(); err_slab: hugepage_exit_sysfs(hugepage_kobj); @@ -2828,7 +2855,7 @@ void deferred_split_folio(struct folio *folio) #ifdef CONFIG_MEMCG if (memcg) set_shrinker_bit(memcg, folio_nid(folio), - deferred_split_shrinker.id); + deferred_split_shrinker->id); #endif } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); @@ -2902,14 +2929,6 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, return split; } -static struct shrinker deferred_split_shrinker = { - .count_objects = deferred_split_count, - .scan_objects = deferred_split_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE | - SHRINKER_NONSLAB, -}; - #ifdef CONFIG_DEBUG_FS static void split_huge_pages_all(void) { From patchwork Mon Sep 11 09:44:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379072 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 3E206EE57DF for ; Mon, 11 Sep 2023 09:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0C096B01FB; Mon, 11 Sep 2023 05:47:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE1896B01FC; Mon, 11 Sep 2023 05:47:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAA016B01FE; Mon, 11 Sep 2023 05:47:53 -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 AA7B06B01FB for ; Mon, 11 Sep 2023 05:47:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8A1591CA3CC for ; Mon, 11 Sep 2023 09:47:53 +0000 (UTC) X-FDA: 81223840026.05.A94786B Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf20.hostedemail.com (Postfix) with ESMTP id A5D6E1C0030 for ; Mon, 11 Sep 2023 09:47:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Vq30w72H; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 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=1694425671; 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=4+dyOdEpvdrL2eUxAXXyGxIB/NcoZnEV+TKBfmBMmgQ=; b=XeLUjVX5tz3VFO/oloXcQ4wTiAwt51bpU9hg6Y0wky1I3HnpOBxPyZtqV+8zMTXNCpCl5F 8+H5gQG88m6myr0fR56esI8wxiES1pC1/GcnnccXXrlby0JiYiuxGMjr+hjHRXQad9dQZi NJlIFqmjWNufpJ4l0XQ6dzKgUqWestk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425671; a=rsa-sha256; cv=none; b=H+2bcEcgS9ZiHBm0zpcDM9cmJ2jdvqUlcLR0XBkkp5U5LZl+T7yzpsHOxxlVLMPyDIaSNu 7kKHUXN9uAPOrmk9YfPLiU4W+kyKacVvHEHb+5O3cSpPXRofZLlPDayG2ZT2IWeHSNCtXs fTa1aAwdunKmDIjAlzi1aB0gOGLYW94= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Vq30w72H; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7087595ad.0 for ; Mon, 11 Sep 2023 02:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425670; x=1695030470; 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=4+dyOdEpvdrL2eUxAXXyGxIB/NcoZnEV+TKBfmBMmgQ=; b=Vq30w72HKf9qiMUVMQ5KkTwn1pyfxXQYKWvT1OvyHIXu11zJc7ZFkuD2CT0r0K0sva OvuVWkJJhsKDJNC1XofiGaGspyG2BW+FMCfGlj5tLfPxoYIuMdbpahT8kHWYptj/rcll z5Psny/NcYTikFZlsadoE3MjaT2k56VJ5rM7ZCmiFNDnNCovefuYkTY+WHh71DXsYkbQ 8nNLJvCjfNQ/8MGQCpLMHgBaJJ13VK3YDJOnA1SyctzEZiD0T+DXMZvTS4WMLUNZp3lt uAH3I2CKaPIEMNcDInQ7RQc3KfDMKB9FenhWD5Lxt8tRXiwRvSE3FXcElP0TjPPZTvci b4bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425670; x=1695030470; 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=4+dyOdEpvdrL2eUxAXXyGxIB/NcoZnEV+TKBfmBMmgQ=; b=aIOEy2mHzqR5+pp/HLzA0lh4lmm4EPg+8wTdSb34dPpJwNUi8UFUTFehUguTJYadri B3OQY9Q7Cgqv1Zwqz36PpSONwns+5C1OqeAMh4mQYJyG/jGTa8aSV3jApEMzGsQozT1u JVD1Gzafcj2mPKYDvzUO8XlpANVywnK5IdKavMUx4+12F2RoAxlLLuTNHHmfJid4PSBO PkO93iJziSpa7gLB8tNLf5aLKZwAtXKGK4L0dfeB2Z/NppNq1UHjvzeFTgTNCxleh3SZ wY2R1rvq61uFAmU7yLsewFUQWMiM5RAJAw9eMVUwpQMFJ0thi2MPBXTCWZr9HHbL2mj1 LeQw== X-Gm-Message-State: AOJu0Yw4SkYDCfWwY/uWOzPpOF/hoDwTEUPnnEXmZvYezWJysZ+iUTgW SRP2j7THlUdrDjCgqoF9jcLNqQ== X-Google-Smtp-Source: AGHT+IFJHaBKDBa9FsHXtzux2UkvFgC3UTp4BhhdsEjv8fCLAr/6/KNue5g8DvDfgdf99+Ek70M0DA== X-Received: by 2002:a17:902:ec8b:b0:1c0:cbaf:6939 with SMTP id x11-20020a170902ec8b00b001c0cbaf6939mr11608160plg.3.1694425670620; Mon, 11 Sep 2023 02:47:50 -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.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:50 -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 , Trond Myklebust , Anna Schumaker , linux-nfs@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v6 18/45] sunrpc: dynamically allocate the sunrpc_cred shrinker Date: Mon, 11 Sep 2023 17:44:17 +0800 Message-Id: <20230911094444.68966-19-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-Stat-Signature: sxei8na36cdtyfwmqy5eco3tfb4i4sb8 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A5D6E1C0030 X-Rspam-User: X-HE-Tag: 1694425671-606469 X-HE-Meta: U2FsdGVkX1/zsj7b7k2br9WYsyuOcOIHidfj5BsNC5AmC80J+v/pMrSGjC+oA1rdQoVvG5UDr2KZMZvDnJ/yqVS2X8VlDKOWEqoop8F/I7OjdRdo3Ufjy7gPwxIpwZ6Hyov/zD8ddjztFn6McOH+egXFvanvqo+wtSwYIBOGvONDoU18aWEsFM3vHKJ4WUUdbE4B+6i4Wt8QiKSe54BMiysZFh7/P1SJfMrxK2oy7cz4dK5wcG9UEKNs8CiVILoFbpBHRl1Pykvocm5HlbZwfv8ZKcI4iMW11It5yZTccY1wYDK6/y/TtCgYgvxdAZfRMHOk/XFxcI4gwPW8YbDCYZUJI7TkWXg7yysY0JPngmnIdGy2Zhx0MsRBCmWGMallDuuO6hWbTC4guuI1t47p+Lurq6RO9o1IxH86lAt5hl4NqzlYh19DQY/0aQ05VuKWoHobAXNAycuWxMD6FIkuTMZhS66UbPzWg5NSVMtsiFJZ9XbNSP7unl+s0bVqXHCAz975vcanOuVerlNIK1bSsm3RH58PTS6V2tMKS/pl5u7Wcz9vdxBgF2NLzTU+8Wtg+y3NQdCO0MnLcIYllzlEAhfuzb6OP6qm3vUaeAdLJeQGq6wOgqtF44tVRpx9JlgHBugsDE62IigffNTcI38ebXdYxU6DirtfZSZKD88tf5VA9scO/MGSI9saUo2aALkO2DdDBsQ6m6ZsX0t93vbV5vd6qFd63XEAYvUnmTbCGIlEH+Zgos9kP6tJBNT2eIyv1T6WiYI91SA8Cj4nFW//K8ArDsYj2Zit54lUD8m9fHfd6ssqOGZtg9KmckKRbRY3EgYZnXFBJDb/lWo8qciKh/LkkXYi2ZbsYygwH3ZhyCYJRfcvr0JUTcWg9J3EBv5OkogZNJaOfv1z7HsDHGYAFOvwRE6Qn8gZxrSfJFT1xiZwBLU6WyIGRxqmHfAjApmYP06FsEz7HbZyX9dpJ1U /GSUBMUu U6ykEqrPiq5bFt1tEIZUqutdQwNG5JX6UruhqnTsXDxV8DKjLbBKIRKp6J25/GPUKmaQnwSMsdANHILsVg4cwUyE/RgweI46fdVEAMsx6R0JIBjlfErJQJNOYWsHMkAmd8XYpVdocPK3Z/u7JPIPreYT3SU+L8rW5zKre4PNtiHgA3VJHQcUMZR2PtBQa2PfxFmACnwrkCtN68kFgTF8+961Qc81L0lH9eiOtt70+HNqx2Hsei0bBRG9VSqzM98+IOFQs2mbzdAKX0ay8NttXVV5RSiMOs75wv/XVMa8u9nhk7ABB5F461Hz0mtlz29JVO01cbX3cnS9nfr+1H0RPF0Yh5bp1hE+ActXPJgTTx0TLWqhdFMDCupeK81QAwHD8aCQHD4qk8XGE+ZGZLZRgNbVF8p3pth9dMg5lW6e+lixX3CK2HC0uvq1ndaI68F2IJhNk49k/4Q/CAqelY+yKBUEBRMoDspe0UqWjPehKJws76AqDvIscJzm4oDVp1lqhGicqxOUhJ3GMwB0HHh8AJSbq2qoQCSFNOITkpjl/6iMtRl0NpCYWAtuAnKvJN3YBAleKBNTafeyK7dx3ljxEUP0BL1KcZkaHU7KOSqcpyOfN/OE6JO8M9D1UjskSEHAmacHzPwzglBhZREfG2WnSQ+LQL7lcTj34obB93j+d40UXxhkvd9dRUC8EGxGBZpT5dA3ECK9zIqAf+o0leHETeizxjQ== 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 sunrpc_cred 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: Trond Myklebust CC: Anna Schumaker CC: linux-nfs@vger.kernel.org CC: netdev@vger.kernel.org --- net/sunrpc/auth.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 2f16f9d17966..c9c270eececc 100644 --- a/net/sunrpc/auth.c +++ b/net/sunrpc/auth.c @@ -861,11 +861,7 @@ rpcauth_uptodatecred(struct rpc_task *task) test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0; } -static struct shrinker rpc_cred_shrinker = { - .count_objects = rpcauth_cache_shrink_count, - .scan_objects = rpcauth_cache_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *rpc_cred_shrinker; int __init rpcauth_init_module(void) { @@ -874,9 +870,17 @@ int __init rpcauth_init_module(void) err = rpc_init_authunix(); if (err < 0) goto out1; - err = register_shrinker(&rpc_cred_shrinker, "sunrpc_cred"); - if (err < 0) + rpc_cred_shrinker = shrinker_alloc(0, "sunrpc_cred"); + if (!rpc_cred_shrinker) { + err = -ENOMEM; goto out2; + } + + rpc_cred_shrinker->count_objects = rpcauth_cache_shrink_count; + rpc_cred_shrinker->scan_objects = rpcauth_cache_shrink_scan; + + shrinker_register(rpc_cred_shrinker); + return 0; out2: rpc_destroy_authunix(); @@ -887,5 +891,5 @@ int __init rpcauth_init_module(void) void rpcauth_remove_module(void) { rpc_destroy_authunix(); - unregister_shrinker(&rpc_cred_shrinker); + shrinker_free(rpc_cred_shrinker); } From patchwork Mon Sep 11 09:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379073 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 7925CEE57DF for ; Mon, 11 Sep 2023 09:48:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14A2C6B01FE; Mon, 11 Sep 2023 05:48:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FA206B01FF; Mon, 11 Sep 2023 05:48:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDD226B0200; Mon, 11 Sep 2023 05:48:01 -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 D8BC46B01FE for ; Mon, 11 Sep 2023 05:48:01 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B57B4B3A3C for ; Mon, 11 Sep 2023 09:48:01 +0000 (UTC) X-FDA: 81223840362.12.2DED7C5 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf04.hostedemail.com (Postfix) with ESMTP id DEFCF4001E for ; Mon, 11 Sep 2023 09:47:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VqbaKfB0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 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=1694425679; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=5/3kXUNtUSdYNKsbAZZe3ps88FmJNaWIFu37hefjPyumYRuPkUS1mOQAvPxDkGbIQEyQk3 tWX0FsuheyyXsL6+Om0UsbkpxpsGTv8Bv4xJNKITEgqTQ/N+v5WqgMClTlzBz0BE7o87Qd X++4Lnk7AtrsUgw02I6aW7We2zVxs/w= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VqbaKfB0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425679; a=rsa-sha256; cv=none; b=FBYUNXgavxzDQRxjTOgyWzj57vQWxJaCNRkhBSRh1q7JBlqfj0p3msFifOcP773/ETrbGN SrGFzhqWWib6XV7alniOlgJW9KHugEeS2yN9yTJpC8v/7JljogQOCqln0l8BtJg67JNLMx J1UUfkDOFdlvmWdP/Y4iV7XLdDcNazg= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1befe39630bso9366215ad.0 for ; Mon, 11 Sep 2023 02:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425679; x=1695030479; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=VqbaKfB0TjKGUBTjzT7m4gGqpq440TvWueN7RM87KgFRP5VxUjiWWFFiCHXSem+TY3 J63nZyQArugBeF+4u7Q+rlfklJXHTggeAJnA8oNw+ZyZDd7IU+atN4NBTSuAtitZxdGr eyUN5CJDQHFPFp4qYo/+ArlSwpzPjUYD7GcU+BjX0AtSh0PZCk6mjkZZKr+2k9uiHMBv /Zq9Kukei5YLXc9AjWMuowPM8Yug4B+MR5IoJiivAL5q0KMmb+NyGfV9BSJMbexVSID6 tdY0vqRdKzCBth+gyyrWhkLVPTcFbVwu+mm1/q7/m/IVAUKppt0p6igwDsShvCnYo8Nu ZWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425679; x=1695030479; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=tH5utb7YaIc8lRSw401MXytwOCeinXiX+XhNyMG6JmG7opyDU5Z4jbbADksNbM+EMl 8XvwTZHJ/irDa2t+WxPAJ+jbgVKzIr4gZE6e/3GdZpcXrfGgWCs4z3nOFuOa9yso6Nod VfCo35DfVxZPNkLvzCFN2fCtxFymgI3lUdxd6BEYoa2o+NAT/JMzgoS5o31TJBnPDswx sfFibYsM5gOJnS6lcCSF+m3GdPgO5hC1+WrUM1e8JzgbyTmFsP3XrV7ZNDtz4LpInIzz VgUpycuckIjrs+KJNwiDtP7iUGpUDWISAMiUyKK8V1kZ8h9/EsABIregReekHdrCwkEb GtTg== X-Gm-Message-State: AOJu0Yyl7Kfl9mUoiGDbPBjoGSiloyPFYpPYRqx+uN8d7brThOTCksTC xAtLeQDEzjrPYCCo638ArXFy+Q== X-Google-Smtp-Source: AGHT+IGdro6LiLO9vRH4IIg6fznBAneFLTeHoPfwnGVLVhVa7r8b9KXvi4A+Mo8zyY74vr4cIKuVLg== X-Received: by 2002:a17:902:e546:b0:1bb:9e6e:a9f3 with SMTP id n6-20020a170902e54600b001bb9e6ea9f3mr10988406plf.4.1694425678844; Mon, 11 Sep 2023 02:47:58 -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.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:58 -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 Subject: [PATCH v6 19/45] mm: workingset: dynamically allocate the mm-shadow shrinker Date: Mon, 11 Sep 2023 17:44:18 +0800 Message-Id: <20230911094444.68966-20-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: DEFCF4001E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pgp1ne5ghkifza48tjxjwwze48634nuw X-HE-Tag: 1694425679-15258 X-HE-Meta: U2FsdGVkX19SaMj53LnhhLtY4Kl+1+4asmBN7IvjZ8bj7yhL6EshOuMNnNias1oaldy/0HIMjPoJzEt7nRG1urnRPN9/4ciXdCkT1gGegtwmG5mE0252ixnAODgnwdmL62rUnDd7CEerOyQjMN6lwsvZ2MIa/s2doh7jeVX+MDFQ7yau2XAO+2SG1RNsIy+vguRTWKni7B/xU4O1x+ntkckF/Wfl9fagVc+EShK0q5gVLmu319d1hktDF9vm7AdTaU8x8poa+8ytcqDpTO58uozTrfkverOnZ/+QVIA+8oWqFBJePjiRK0pZG3w/OH9cG+OGRi1dCuv0x+C0opXKDmZOXo8Ohq9vamjIQ5u81g19qIMEnGTRw7L0m0DFNPvn1HNRWF3pR8FsyW6HEgeXXsP3O+zmJ0Y8647boiU2aDLUCG32Lp1Mxn1LUIDk2lE2443HZKVIfAvXxsiXoyxtuhe+PwLsf5awdG/MgTRpabdBQ9F+2HaHTU0fDafPlwfzfK4Ra8g4I0s5ElJcUtydizwmiRxQ9QOuhS/sPe+s2tsH61GkdKzaa+HK9i1NWMqvISQHuo3HH2ILCZToea7TKL6Obp7So2X9QpzUNfY8Hbs028FoCS/xJIbiwQf2z5vP3ih0W8h954SgOqjbbnWGLA61hiwpn260+QGpPOpS9ui/AaHQgqoZW5PJM1FH56vqw6RoODhkq4mTbxRzIGhGGiBr04P7IKEkRqHB20IFXV4hvxdKidfk+rKTAXSlBysdaMSHyten7ByJ71m5VgPLisZhJHjHPrQdXgbTlR/mWmDUP53Iu9YAXaoH7OJji8mhkXmqETy0b/1elTdsUGpkUXXLGMVhpKG6bwsSAwXWqAT7evWXxG5P89+nGdKPBjwXp3yzeM3uhfR0o1EcuqcIGQ1TF7aTxt0ncFq96+dEJgpE2LdwjXWRJJgwQ1gobMdOY3zgHceG4VqM1rB4x8t YRT4cP8E zaIhuVesGB8zx5uvU6WKBYbq8ImF/o4RahltQBfQKmJjbCXI9t01a51qdEHF3eIuN6UUdR8CVpRa3EzuMQgAjcWoU1xhepqjfYOuFf8H5ehT/43HS03MpKC6naeiByBMZ1bt8WWmLLVke96ia4XkC1bNoicWSPuLtDyZCDovOLocZrLXaj5/6sKhkVTrA5j596OLbnEFzwCK+r5loeOrzADHMUSxGio4t11orMc+/7pfSBClxFxjnVHAa9Kx1C5zlPe5ZUbUM0wzZGxX8JAIbu1O+PUjdNWEJ+CKf0xf3BDaqGz5xawWDsz89iCKlq6rx0WWTHnW6oReq40QFQMBEX7UN+ZXmLh7uY/4heYO0W3fjy31j9gJ/E0ave5LjbpL3Nmj3vkYLcwt887NyE994otWsznM7gbOUdLek 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 mm-shadow shrinker. Signed-off-by: Qi Zheng Acked-by: Muchun Song --- mm/workingset.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index da58a26d0d4d..b192e44a0e7c 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -763,13 +763,6 @@ static unsigned long scan_shadow_nodes(struct shrinker *shrinker, NULL); } -static struct shrinker workingset_shadow_shrinker = { - .count_objects = count_shadow_nodes, - .scan_objects = scan_shadow_nodes, - .seeks = 0, /* ->count reports only fully expendable nodes */ - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, -}; - /* * Our list_lru->lock is IRQ-safe as it nests inside the IRQ-safe * i_pages lock. @@ -778,9 +771,10 @@ static struct lock_class_key shadow_nodes_key; static int __init workingset_init(void) { + struct shrinker *workingset_shadow_shrinker; unsigned int timestamp_bits; unsigned int max_order; - int ret; + int ret = -ENOMEM; BUILD_BUG_ON(BITS_PER_LONG < EVICTION_SHIFT); /* @@ -797,17 +791,26 @@ static int __init workingset_init(void) pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n", timestamp_bits, max_order, bucket_order); - ret = prealloc_shrinker(&workingset_shadow_shrinker, "mm-shadow"); - if (ret) + workingset_shadow_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE | + SHRINKER_MEMCG_AWARE, + "mm-shadow"); + if (!workingset_shadow_shrinker) goto err; + ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key, - &workingset_shadow_shrinker); + workingset_shadow_shrinker); if (ret) goto err_list_lru; - register_shrinker_prepared(&workingset_shadow_shrinker); + + workingset_shadow_shrinker->count_objects = count_shadow_nodes; + workingset_shadow_shrinker->scan_objects = scan_shadow_nodes; + /* ->count reports only fully expendable nodes */ + workingset_shadow_shrinker->seeks = 0; + + shrinker_register(workingset_shadow_shrinker); return 0; err_list_lru: - free_prealloced_shrinker(&workingset_shadow_shrinker); + shrinker_free(workingset_shadow_shrinker); err: return ret; } From patchwork Mon Sep 11 09:44:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379074 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 67D0EEE57DF for ; Mon, 11 Sep 2023 09:48:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05F516B0200; Mon, 11 Sep 2023 05:48:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 00F6F6B0201; Mon, 11 Sep 2023 05:48:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF42E6B0202; Mon, 11 Sep 2023 05:48:11 -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 CC6BE6B0200 for ; Mon, 11 Sep 2023 05:48:11 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A211312098A for ; Mon, 11 Sep 2023 09:48:11 +0000 (UTC) X-FDA: 81223840782.15.795F331 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf28.hostedemail.com (Postfix) with ESMTP id CE096C0019 for ; Mon, 11 Sep 2023 09:48:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VaNeMDFr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf28.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=1694425689; 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=TH2SdUyTcD6fjHvcYPnGAz08JEgs2WamZypN/j9OP1o=; b=OhPeXAkIGtHI8ko+Lexsb4ahNc9J7J+kgbJCMaRC+bJ3gPALvM7FLr0uyxHGmqIoSCDARC yqaPwxHK2ElIFqew6liw5yt1uRhBOy1o2eG79IgvHKFZLmaLo3NSMzmxwz3epsg3/VLP/0 0g96XasDjJDVThECXWYl0w77k+3JsXY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VaNeMDFr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf28.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=1694425689; a=rsa-sha256; cv=none; b=of2MbdVJXzdzGZwpwA+TXEC5bY4povlftaUwXelKajgHGnroMowTZBLAoBsm6Sbw+8R8Uh Qw9J97kluq7eBIOpdP7kI7/EEtyLhh3hUpZwZH8uAFbgaG0IUG/DbC9BLFntoHnYHhh4Gd hSZLlHnZzp73SW4pR3cazBtXKuYtn2o= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7087875ad.0 for ; Mon, 11 Sep 2023 02:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425689; x=1695030489; 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=TH2SdUyTcD6fjHvcYPnGAz08JEgs2WamZypN/j9OP1o=; b=VaNeMDFr0UmJ/keK/9JWOEjLSQYcG6mKIISDTps3XzeXV6gHaHe8nX91aHX22NQwbM /+qWr2NxyixrymUSsHsb22heq9Fnq1F1/85fnCHR9TyaAMi/G0uVVHrk/QNZpd/EtWRd 96R9Zx8m5CNO12ZS7gJtbbOgwnAsr0hwH5ACO0ELlb5wQM2HXlE+iwyMR7hYzGT6cJsH Xb8vAEYsVRUQG6TUF0fR0lvKuEWaFmnDlwYbEzvO3o3H3Xs2lJcFIHT2pw++reDejxbW MWjgkDYHxv+WE8rMtZgfOr3FnVmvdmsjopSAUBntSl5fSHoGmazhF7S06QpI6jvL71Sy S5zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425689; x=1695030489; 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=TH2SdUyTcD6fjHvcYPnGAz08JEgs2WamZypN/j9OP1o=; b=TLSpkI0doFYdC5Of4wQs0vgnOlUfCmDH5g/P0ODQe560Xy6iXs2W+CiShaAGX9pa7B 1ozXBD9V2EMmPCJeK6/GKHzPNcY3QQm9a+RkQ6yyUGe46CB8Yotjq4RvfkiOz9B/2lYv IwTWlT/uuc4gPK+3iLjAB01rcG5OHh8LkDDW0Ibw+WCZQI0MgdbWaYcPz2FjNoxBoR8k Kb0jSL6SW0CxlzliEh5hK8howlZAMzHf9Fe2zVvy1E2fTdvuYY0EaIpfscEvC6VYtb6F L48BmbUD7tDWNF9K2xwS1cBar0QYC6kFA/zPMe67vBZJs2bohVBFIZ6YAGyf7nucUeWV h8Nw== X-Gm-Message-State: AOJu0YxBaAKrAYehvr04zx1mCNCF8uJBSAMdink5DfoNYtbFd2mevH0Q TOQlxO5OV8HN+QYPUsy1TCdHFA== X-Google-Smtp-Source: AGHT+IFXsoJn9CE40v3H4M+g/tTzTAY/D+R7L1IYVyxz9f8XJyNRX7PJqlNVDB6THijf5N8OiFzBVQ== X-Received: by 2002:a17:902:e750:b0:1c1:fbec:bc3f with SMTP id p16-20020a170902e75000b001c1fbecbc3fmr11507909plf.5.1694425688824; Mon, 11 Sep 2023 02:48:08 -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.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:08 -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 , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v6 20/45] drm/i915: dynamically allocate the i915_gem_mm shrinker Date: Mon, 11 Sep 2023 17:44:19 +0800 Message-Id: <20230911094444.68966-21-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: CE096C0019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: kphbqip9kizezfui78panjmxhubiaiis X-HE-Tag: 1694425689-365933 X-HE-Meta: U2FsdGVkX188BufjV4zvC30rqg2GCkYYw1rZr5Fut4c/5hGOWO116TsqtRaxUqidSz3Mh+4Qpm2VGc5LAIpywC4/NJ6B+gJQwAy9kxek5HbQBb5ehmSIUEcsONOAiWa0z8a/MGKQCNgOJOlSBG1qJASZUWmi2EmA0Ipi3rNyXhRKdMfApBT0sPKA2DkmdgcdQ5kLoDYLIY27JPLdCfPAn6VvLsKRIf3GS337+NfSV6b0Te/Ad9mgO7TagU1qObuuN4Y0UyelkeeEVk6i+PFAhvfsFdvRYQy9xeWv2i9ZTnwBfjLauXjP6sSv94Ledd2ew9CkB8lzGSnRUJC0c0W3SBEEXHapllVEiVeE3zHZKT1JtGSiou1pE7wC7qxyKUI/0YoQvPusfQKGSlRu2p2b4pIoczO6d/WgnXWFXFnGBRNIkHn2JIv5rXjBLmZ/sljgf28SdFowxYtVYrfm2mfV3PLCa5NSammHTIaXSPPuQryL6C+jmfvWBq0N/dSOn3qPyYQxKoa2QYwt36/7XtyZNpl70qLZwagXu/8UHaN5lXlzwNZ1RRH4cYBNLG08efRpa5FqXM4yvIc6s5GtK9EVO+t+YChI0knV4zKzgXiUz2cD0RVzqeO72m2EODvC3vmkjLlFB3wtKSy+lzBvjwLYLj0B9t4felTLYK6qvnrMmD6myCh7xhEgLpssFqTrgMEk4CdpuZ9qhP5zd93leP8CKuHzkIpFC9WaH2uh/2YzbfiMwRcbfiyGwZGKCjAELXiqCrGNjSrxbOsRU/iJ7D4q2uNckdxLeg41PBz3er5xq3BFrkv+Oz5XBbwNS8W5DqNODAhnEArGehXrat+bm7kfgmp826twYoL85Ik4ZF2J9IQfw8cMhat8qviWdxUNL0piU1hf/itry4VqGYg2nTMP/FpGR/Fl2DV4bqnUDlJKtFEEYRAemYu/6niI/ZeSN5SVvei5YkIjW6F5LEjERed CypNehtJ dg4NomzCy9nw7Tw+tPWs8K7LXcRxmWYYPYBypXE/hVnhj31VyP+O0XEdtPBhCr7Q+miuIELxIdKpqrpCY5ITbTouv2B9RSlEGsnc59L/hiuRh7yzPvQPjYlBDgUpU0oFpQTeh0M9LhpGe9zgMa9ZNTndnHsmRwJ30pXtL/utN4csl4wUk/593k8y+3/VdeiKZ4yYCK0I6bhP1Yh5uXGfGLJmPWcLR0jpaRnR5i0y1x3dL/zyVkGvHdf/EFUAajj/f6oNoZcScN0MMPQOGvqBqyEyR2+FoOSNLCPkrHAnZb6LH02+iWuJSyhmCFOLHuIvPi8ES5eAJCNAmyDTmhIoeSFguFCXXYkqZCNzq9D4ikaexJfQk+MDH0wMCTrxls55Y2pHf3c2CIXhjpPxJAsZa/41C+nWfK2HNVgRi5MRVj/CPvBxUFrMGURSyW27zEOwiKlXYqznLpFK9KxOVCtxVTw0VGdQCewvvPFpeRSrlsMSDxCIkeYSXmpitdoRWkBCpRIQXQFYWnTJRGsrL/91OPmx66mVGBHlJlzfgWnDEimcstNH3AEcbqTVfHhsK9ml5QAuA 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 i915_gem_mm 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 drm_i915_private. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Daniel Vetter CC: Jani Nikula CC: Joonas Lahtinen CC: Rodrigo Vivi CC: Tvrtko Ursulin CC: David Airlie CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/i915/gem/i915_gem_shrinker.c | 29 +++++++++++--------- drivers/gpu/drm/i915/i915_drv.h | 2 +- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c index 214763942aa2..e07ffbd9eab3 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shrinker.c @@ -284,8 +284,7 @@ unsigned long i915_gem_shrink_all(struct drm_i915_private *i915) static unsigned long i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct drm_i915_private *i915 = - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 = shrinker->private_data; unsigned long num_objects; unsigned long count; @@ -302,8 +301,8 @@ i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) if (num_objects) { unsigned long avg = 2 * count / num_objects; - i915->mm.shrinker.batch = - max((i915->mm.shrinker.batch + avg) >> 1, + i915->mm.shrinker->batch = + max((i915->mm.shrinker->batch + avg) >> 1, 128ul /* default SHRINK_BATCH */); } @@ -313,8 +312,7 @@ i915_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) static unsigned long i915_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct drm_i915_private *i915 = - container_of(shrinker, struct drm_i915_private, mm.shrinker); + struct drm_i915_private *i915 = shrinker->private_data; unsigned long freed; sc->nr_scanned = 0; @@ -422,12 +420,17 @@ i915_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr void i915_gem_driver_register__shrinker(struct drm_i915_private *i915) { - i915->mm.shrinker.scan_objects = i915_gem_shrinker_scan; - i915->mm.shrinker.count_objects = i915_gem_shrinker_count; - i915->mm.shrinker.seeks = DEFAULT_SEEKS; - i915->mm.shrinker.batch = 4096; - drm_WARN_ON(&i915->drm, register_shrinker(&i915->mm.shrinker, - "drm-i915_gem")); + i915->mm.shrinker = shrinker_alloc(0, "drm-i915_gem"); + if (!i915->mm.shrinker) { + drm_WARN_ON(&i915->drm, 1); + } else { + i915->mm.shrinker->scan_objects = i915_gem_shrinker_scan; + i915->mm.shrinker->count_objects = i915_gem_shrinker_count; + i915->mm.shrinker->batch = 4096; + i915->mm.shrinker->private_data = i915; + + shrinker_register(i915->mm.shrinker); + } i915->mm.oom_notifier.notifier_call = i915_gem_shrinker_oom; drm_WARN_ON(&i915->drm, register_oom_notifier(&i915->mm.oom_notifier)); @@ -443,7 +446,7 @@ void i915_gem_driver_unregister__shrinker(struct drm_i915_private *i915) unregister_vmap_purge_notifier(&i915->mm.vmap_notifier)); drm_WARN_ON(&i915->drm, unregister_oom_notifier(&i915->mm.oom_notifier)); - unregister_shrinker(&i915->mm.shrinker); + shrinker_free(i915->mm.shrinker); } void i915_gem_shrinker_taints_mutex(struct drm_i915_private *i915, diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 7a8ce7239bc9..f2f21da4d7f9 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -163,7 +163,7 @@ struct i915_gem_mm { struct notifier_block oom_notifier; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; #ifdef CONFIG_MMU_NOTIFIER /** From patchwork Mon Sep 11 09:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379075 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 6C2F3EE57DF for ; Mon, 11 Sep 2023 09:48:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0866A6B0202; Mon, 11 Sep 2023 05:48:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0366B6B0203; Mon, 11 Sep 2023 05:48:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E41326B0204; Mon, 11 Sep 2023 05:48:24 -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 D57086B0202 for ; Mon, 11 Sep 2023 05:48:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8C5BA12098D for ; Mon, 11 Sep 2023 09:48:24 +0000 (UTC) X-FDA: 81223841328.12.9534F19 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf27.hostedemail.com (Postfix) with ESMTP id B38CD40012 for ; Mon, 11 Sep 2023 09:48:21 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jbOlX3/p"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 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=1694425701; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=I4XIHDBKS4O0r5TFVnMLcGxiVO+XCXBod9+n8VxGNQuMj+sxui9+3whMY1QW5PxqOXNfyo rbJEuQQ+w98wf+Wdjn9M1faJ7vMp1OmA/imezIkzWX/0Tuoo0ZVUKhKg7idylQckAxaeMZ unJ38vuqpGUFE2jezyZzyDpYMRT0KXY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="jbOlX3/p"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425701; a=rsa-sha256; cv=none; b=pSEargIqHUb3YNg1NMWtLQOazWn5yg6WStWPnZHyRJI/gFEGFWTvDOdBst2oDpDdlDvwor idFIOVTgCuOBhf2H5736WekS1gD4WGJa14+t8hKA1rvtscR4DosrdInnt7j8/5QL4F8fYp NkiXDemb/7IvFY830g2zqsoA1mjgsJY= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7088155ad.0 for ; Mon, 11 Sep 2023 02:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425700; x=1695030500; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=jbOlX3/pdoQkIM33VQ+oZKuOwERXJ4Fg77K2ba2f7/zAza/UC0xLLCydX4itoflZR3 u2lCf98p0cemc+SzuPjuth1r8qcjoYI/nHY9nCVAlFeUw+iojNjkOPh1fKTsLtzfQj4U /V0LxwrdYZ0xRHh5LhZXSSWKeQAv5MRj+6fEbFGFyKoHcdJ+6xThCM7+xd7ylQiayRkV a+P3hlIykXjC6BZXGaNLUe8BOMftVDNN3Ni/qE0s4vBjW+58rVxQAGI4SL1I2nKUisO9 HU1THsM5it3RQMgtwqBImbUKtLCvQEFzyR0vw7OkFPIVl4+op/7v0ycFOk2uoFPwJE44 fknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425700; x=1695030500; 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=J+AOjYo5MSUvfxmHTrKdHJPfXG1dzZtS744QdXjNFdA=; b=T0w0K36V7AHSXdTFvIbZWbG5NGQSjjgIBCPPijxEf72c82zPTlWPvaULe/zzncERPY 3svMAdNIbgwEqUKPR9G6aqzTPeQFWIWqzOfBaOVe29QDa/uGE1XREvk8OdPYOPTGNU4Y jCMp0pwVEV/qtiJvQJZ+mhIANBXEzj/bUCYpN+n6fImFaAwKKzBuIpgovkdCCvhXIkxP rlg8iXH/TiKEyKX54Vn93hkEjx83hVMW40CE4G7MIuFqDiDM+x41Eqs7XFPrAwD8ojOR WY5tGMpgnwdrpwDG7jUFTc++1loP+mVaeWYnDeau1wMYvLTrmAu1aNzglOe6N87xoAcb 32DA== X-Gm-Message-State: AOJu0YyB7aB2SEf+a9e2ToI+TEuicxPPZbksLs3OsXxVIfFMYM1GqZK3 +/+NOSzDVfOA/y36kylcKVr6iw== X-Google-Smtp-Source: AGHT+IE27vGs/uaz34ojq8+Ua2kGxMGmW1BLKwB00ljr5B+4yLh4dyEjB9Qga47N3yLXlwPZmv4ysw== X-Received: by 2002:a17:902:e750:b0:1c1:fbec:bc3f with SMTP id p16-20020a170902e75000b001c1fbecbc3fmr11508200plf.5.1694425700587; Mon, 11 Sep 2023 02:48:20 -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.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:20 -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 , Daniel Vetter , Rob Clark , Abhinav Kumar , Dmitry Baryshkov , Sean Paul , Marijn Suijten , David Airlie , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH v6 21/45] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Mon, 11 Sep 2023 17:44:20 +0800 Message-Id: <20230911094444.68966-22-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-Rspam-User: X-Stat-Signature: 3sorfhhj51bno66w3w8pazeb8jg8mcww X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B38CD40012 X-HE-Tag: 1694425701-255311 X-HE-Meta: U2FsdGVkX1+ifdrojViHxPv43GdPNXqJQxE3wdTGGR5nwH18QJdKLLgwgqkxvGLEZJdghtqioBBWscy2RnlH3QVYiRDv2N0vwqVmskeOmR/3shIOYHHW3ufiZkyNFQ7Yx8AC58J2gTeSlpG9qAMG2cJoCApB2JXTeo8puX6TSfkwAohP4/tUBEBirgogXx3LfVrJV39g2nmAZgFb99NSofF+j1wzCgPPzuvUaLWBHhPeKzw8ulEALVY83QMp+tVfzHj2DO3/OwzGb6NrH5MofwnVTJKalRoN5ci0e72em3ovMG2T3K2PKEAAVaR04VsA1j2wIh9haBn8WyRiI1Q0BMHvqnFsRCxI2dWT+vCZdk7b2gEgAlmQ1Agg6aUg/kGHXYOusdvVt3pMRoRVnXWSuDgKj+rvy++AgLNNznbXI4hDaMS5SAF+/Wynel9ANelwOhbBRHIUZXu89y/aDk7rTEc91PZ52t0qAafh7LKWiF994vpdEC/AyOZd/cxaF6tpcNApiPKDKATKrLUq7OPjXxPXXzJSW6HGkp+WZ988qmIRbdg4IPpLyGDeVN1vz6nmJm447XM4ma4QM1Lcfy8Li+IhYcQ9b/2ywbhS1APIXANSOgRZpcGwgATUxO7NbH2bJwDF0KFDCU7cvjDj1ezDQkS62LG8AGhQLTmu7rB6FJYcFY+gb+jFwD1Wb0J12BAeNnss5wet8TGHVST5itu6E4SEaORtwhsb+xIPptYecfz2xXCb/skH7tJf6zOyigzP0Ao5LnFpyTyLac4uDHx428twMtf4UInU7CBymjbqzo0TnWuTLoP8bV6AqSWepAc/dOJub87x3Z9bx4He4kPYKU6kwdDSzZDI/XUlUNJtZIbn6oVo7ED1hmkjUm1p6f9TV5Wzk3rs5rhx3ncN8Hlrl0K4I8qR3nknL9Dm5RkMU5PPShIdGDMH8bzogfqN/hVhrB+pFtpjkdwpPe5Q2Cy hNq+PSz0 4XexELphWU47iVboJqrtKG5NS1eyM9tD4sxeYmUf7cfA5bhV6VE6EPQQ83cRYG2Ou1XpegmSwJSLhHir+Zi9W2E6PG+leSGe7V9UA6Bt3ik5/RCMA+BkPgPc7u56l0LMp97yZMAG5/6hb6AxtDaidmiDBnLMwEpszx+yDlwbvT5G2xW2DrpKAJqUaraUEcmnwF5iGol2uBGWv4zxYCbt5Aqi+YCc9ijdTlX3rb4AKdwlXedUnCael89uHOfSqi6vgsSSadYltvaqD2rpwGODlm/ldnXiKJrHzrG5+51LyPHgRK7tVxF413ib2MymPrEQfFk4js+RzYtRsaTUdzW1DxBw1/J4JUlZB6ZJeanSVJQiAEa8jVyhJ20iX+pSL6th6TJJ6wgNu8i4zAHdS8jSCXoBwb/ywekXIx9GJlkpYfFfMw06TpyyzXBqDDDW09xUDyy7ls8xITbudONTOJm3vtBYVSkX7JXo30em4vGtABu0V4f6rFJ7v+89OWsVaqxFuQerqA+roVPp700WgHrVkdxJ5Agzk0ZrYVyUYbVwAJ/bcLDXVxmHdoSjIBPUUteaJxJr8pFdt6eJdD1gy36OZsR3b0HFnaTPUQ1WRBmaKizK+RMgweODO8BI3A4M1LGFl8JXTdXx7ICrni76N1wJGFzeC05KtKrtIRmOxSVmfhmYMLkhIHExCbC+8Xn7OCu1TXBytZhnuEVxQYGs9f4cdEkSbJ5vny397JpWYs4CF2GoI7J8WWaRcSqDldJvIKAwc/MI3QpvR2KrSFk5Xs69EU4aMIg== 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 drm-msm_gem 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 msm_drm_private. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Daniel Vetter CC: Rob Clark CC: Abhinav Kumar CC: Dmitry Baryshkov CC: Sean Paul CC: Marijn Suijten CC: David Airlie CC: linux-arm-msm@vger.kernel.org CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/msm/msm_drv.c | 4 +++- drivers/gpu/drm/msm/msm_drv.h | 4 ++-- drivers/gpu/drm/msm/msm_gem_shrinker.c | 33 ++++++++++++++++---------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 4bd028fa7500..7f20249d6071 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -462,7 +462,9 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) if (ret) goto err_msm_uninit; - msm_gem_shrinker_init(ddev); + ret = msm_gem_shrinker_init(ddev); + if (ret) + goto err_msm_uninit; if (priv->kms_init) { ret = priv->kms_init(ddev); diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 02fd6c7d0bb7..e2fc56f161b5 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -221,7 +221,7 @@ struct msm_drm_private { } vram; struct notifier_block vmap_notifier; - struct shrinker shrinker; + struct shrinker *shrinker; struct drm_atomic_state *pm_state; @@ -283,7 +283,7 @@ int msm_ioctl_gem_submit(struct drm_device *dev, void *data, unsigned long msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_to_scan); #endif -void msm_gem_shrinker_init(struct drm_device *dev); +int msm_gem_shrinker_init(struct drm_device *dev); void msm_gem_shrinker_cleanup(struct drm_device *dev); struct sg_table *msm_gem_prime_get_sg_table(struct drm_gem_object *obj); diff --git a/drivers/gpu/drm/msm/msm_gem_shrinker.c b/drivers/gpu/drm/msm/msm_gem_shrinker.c index f38296ad8743..5a7d48c02c4b 100644 --- a/drivers/gpu/drm/msm/msm_gem_shrinker.c +++ b/drivers/gpu/drm/msm/msm_gem_shrinker.c @@ -34,8 +34,7 @@ static bool can_block(struct shrink_control *sc) static unsigned long msm_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct msm_drm_private *priv = - container_of(shrinker, struct msm_drm_private, shrinker); + struct msm_drm_private *priv = shrinker->private_data; unsigned count = priv->lru.dontneed.count; if (can_swap()) @@ -100,8 +99,7 @@ active_evict(struct drm_gem_object *obj) static unsigned long msm_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct msm_drm_private *priv = - container_of(shrinker, struct msm_drm_private, shrinker); + struct msm_drm_private *priv = shrinker->private_data; struct { struct drm_gem_lru *lru; bool (*shrink)(struct drm_gem_object *obj); @@ -148,10 +146,11 @@ msm_gem_shrinker_shrink(struct drm_device *dev, unsigned long nr_to_scan) struct shrink_control sc = { .nr_to_scan = nr_to_scan, }; - int ret; + unsigned long ret = SHRINK_STOP; fs_reclaim_acquire(GFP_KERNEL); - ret = msm_gem_shrinker_scan(&priv->shrinker, &sc); + if (priv->shrinker) + ret = msm_gem_shrinker_scan(priv->shrinker, &sc); fs_reclaim_release(GFP_KERNEL); return ret; @@ -210,16 +209,24 @@ msm_gem_shrinker_vmap(struct notifier_block *nb, unsigned long event, void *ptr) * * This function registers and sets up the msm shrinker. */ -void msm_gem_shrinker_init(struct drm_device *dev) +int msm_gem_shrinker_init(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; - priv->shrinker.count_objects = msm_gem_shrinker_count; - priv->shrinker.scan_objects = msm_gem_shrinker_scan; - priv->shrinker.seeks = DEFAULT_SEEKS; - WARN_ON(register_shrinker(&priv->shrinker, "drm-msm_gem")); + + priv->shrinker = shrinker_alloc(0, "drm-msm_gem"); + if (!priv->shrinker) + return -ENOMEM; + + priv->shrinker->count_objects = msm_gem_shrinker_count; + priv->shrinker->scan_objects = msm_gem_shrinker_scan; + priv->shrinker->private_data = priv; + + shrinker_register(priv->shrinker); priv->vmap_notifier.notifier_call = msm_gem_shrinker_vmap; WARN_ON(register_vmap_purge_notifier(&priv->vmap_notifier)); + + return 0; } /** @@ -232,8 +239,8 @@ void msm_gem_shrinker_cleanup(struct drm_device *dev) { struct msm_drm_private *priv = dev->dev_private; - if (priv->shrinker.nr_deferred) { + if (priv->shrinker) { WARN_ON(unregister_vmap_purge_notifier(&priv->vmap_notifier)); - unregister_shrinker(&priv->shrinker); + shrinker_free(priv->shrinker); } } From patchwork Mon Sep 11 09:44:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379076 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 3B87CEE57DF for ; Mon, 11 Sep 2023 09:48:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBC986B0204; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C6BC06B0205; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0CE16B0206; Mon, 11 Sep 2023 05:48:32 -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 9F9206B0204 for ; Mon, 11 Sep 2023 05:48:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 798B480943 for ; Mon, 11 Sep 2023 09:48:32 +0000 (UTC) X-FDA: 81223841664.15.8085B51 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf07.hostedemail.com (Postfix) with ESMTP id A4B8440009 for ; Mon, 11 Sep 2023 09:48:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ru3T2Mk9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 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=1694425710; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=wnhGwlVZn5o6Ts9l0idmDnFcHgDPeWYzaUkqiq1x/Q+gnNE5u3CXqtpjZPZgx2mdJPMQRO K/daBRMu5eNvpyOOG7QG3vPwQ+j4mUFpU77DVNSHkrBFcjetiK+5vaeVHYLLVjJ/Kpnsdv l0Mo78NMBiaEZenhxyBxxGdr/i3Qa4U= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Ru3T2Mk9; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425710; a=rsa-sha256; cv=none; b=T1ZGdxEBwW0Se4LOP/xaGiDe3YlSWvQPtl/UPwpbHfyxGsl0HSXp0uM5V1YimEnSwMsUVL H5vst5Pw4fZUxtRtvppWrDgjVtAXn0MNkMQZIT8HYuC7vBUhvICZbzW+7gyJ1CrtixtdEc IVVqCwcN0nyiLkA4IwzHxJ4YDqsDWuA= Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-68fc49ccbf2so179261b3a.0 for ; Mon, 11 Sep 2023 02:48:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425709; x=1695030509; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=Ru3T2Mk9LANvaqzuJvebACPhy2qMwM/MxVTZxa9cJS/5zfa1v6BbRjbB7Glnlt1Rpj VzA6kIM5SDGP5dQaKlyrI0fR7GpxKQjEItCc4SQfvTXvssmw1Lae8a07MnfKi8hBjt/b QdEbSaTr/q8PwG9aEc2OMl0U1gNNNo0N1EsqZDIlmHu3hoz6g+bhpW+WP0+P0oqfeZgf /aLYHYFIJFXf/FUpd4cArUgdMxxhE5HXYGI0j43Lc6TbjeBbpg1S6adb0meb7TAGXaek AFbyMqX7/QkwYH4erH6aesE+ftXsVe1l7990Qsi+TMV7mjTvOt/XUEfFq10q5CvDpTcb ztuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425709; x=1695030509; 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=G2LKbZzetr9O4IdN7KGu2giI4bSrZ07Zf0F2IXqxpI8=; b=cv/2M0biVp2Jx3vcuD6PcisfbVLFnZ1XS3yteGmala/7vTXvhLY+MiWai38B1xvaVd bVdBXt2+GYgOt9e4fadHgxH4uQ0gwjOaZwedOj9lUdx8BlM8QdlKAVn8CFu3et+b8sfT y7ovDLeN8iLzNZDelUJHmT4NxCX/ccfSyj4g6mcFdIfKfUoDNCEivvfVcc4Kg7gi3lES Gbi6TfHvp8QHQyPTmhDml5hzutjkSMM/cpUImXnWP7uD4NaXKgrkNLr9h0cqOoxUkwmN RP3DUkLP/2+TJtxu9eNZiT14ycoUvoZFzk0daB3G15alKCexfZ7sJEreOZTfIbxM0nxL JtOQ== X-Gm-Message-State: AOJu0Yzt9rBucPfLafc4+iCeHRDT7FSC48zayGgYEPTcKqTl6GKbZXBW r+2uOzaHpU9fbDITbQFrT7SbpQ== X-Google-Smtp-Source: AGHT+IEVXSXkw085oDvvWfPml14cbTQZElHnedX5HQ1+xrEfL7OjLIxrqCMvit7SAM7BpPy3zY3/Wg== X-Received: by 2002:a05:6a21:183:b0:137:3eba:b81f with SMTP id le3-20020a056a21018300b001373ebab81fmr13305516pzb.3.1694425709623; Mon, 11 Sep 2023 02:48:29 -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.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:29 -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 , Daniel Vetter , Rob Herring , Tomeu Vizoso , Alyssa Rosenzweig , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v6 22/45] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Mon, 11 Sep 2023 17:44:21 +0800 Message-Id: <20230911094444.68966-23-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-Rspam-User: X-Stat-Signature: h1ntxk8g35b91za6y5dpnktsd3yi48kz X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A4B8440009 X-HE-Tag: 1694425710-771287 X-HE-Meta: U2FsdGVkX19UPLu3aK/PzeHkDEnV+gWyR5ebY+f7jiDu4+LT1uAYEb2+JrkseDvz75BHstMwoTdXOIT7g0XSMaBqv4ewfLz07GwSMWb45m8wjwx4NfB0oliVxmuccRNrS7v/v7TTtkQNIDoYuRcqzYYELd3RNSqVCL04fl1Q6MtkgoLM8//GSoPnnQHNtm/W1gfTsVasneHuqO7guFulu5yQRxW5CdwtdIMyRXXHAVR2B0/4T9W3B0Nh3ChBxHnAW+nJyA1pZ7oXhYuwFwff4QBRXGnw6sJRVZvvR/HSOSUIP9NtMve9j/1vEmfGDKYv4hQCCswoPZSu/X+lrkxG+gQGJoBdBkS5i7jE2v8997+qlCmBhBcJs/R3lXYazxwZVBcCaTYBx2zGPz9XfA+ufWT2o6L10Q8+yyFEbUluA6faqQ3rmexH5rrVldHasJ5DCrxMSPI385ziWm2xT2Qfm+mLESIhkFoFJb+IOrITrkLkymb9Zhw1GK58XRCgVQI9uGsu750poTqxKP+3t4CdiKJ1SnXFyMOm979ECVruom0AhLOr6iIiSApLceXUx6UUUFIAd7bcAdk6rqAv3G1xIvuwyicfPgLDO+ge20ti3gvqIJy2hANKpSuHus1zc0llJ2X9GzfPkzlBi8+FG9hyxf2QFNgWKPf3cy+EbGu5yq2QlxDRv0alFTjvPNx2Hxsgf7bi6Af/KM6DjzXoI19f/M+FZsHLAsnpnmN+9rOv4VT25kIRHCtY1IfmcgGvcK6wXAzatMt0duASmCJFG0f7qnGQOaX+cL9MPr9LWvsTV/w1LpZhC8xZu+vRJGvniLApSkLUakbLgqI6FIme6Lublf+WA9xDquOrKlWIyo8LW36/TchyE77eOSjEG7YfCendF3b6rNpqoXAXd1qlkyiqPnmQofGUofYf5nXMPqggWyPEBB6K6JyT9oN+W53XXfTzuPwtxpNtuudQteflcV4 VR+rs3VZ tBipkLs7kw5GZaoTJDmZSwh3jBqvLKD2Gp/JqOGGnvlqGJyMmMQMMIBrebAY3KSi5v//dNym3um3gPqvWRouydAljugjLb+wdSUjGu7yiLzyHs6jRP5c3amGKL0S463LiYB6cPPsp9kljgvoM6g16bzoSbAtqagBFjd7Fiv5OcGvyrPhW1uNdzJ3DpW07f+2WuNItZSInCMKG+TxV/X3bV5xIpt96qaLs2BFg1ahQN7IuvP35xGcbGcYRhJt3WuruFgmws7LqKPEddakm4Mhb4WxpQF8f3LxKuaXsHKrykZhl1ecVZRDhi5iSsL/y/5QVmPaZwswZGtQWkXru/fTepqrhKRoMbJ8S641AnVYyVwWIOYaJpl9ZTURPxl7HV0PwD2fJsbNlkYI/MHOeF8MpkFuI2Xij2y2y/Rfp5HdXF/Xu9rLkBbsvwHc3uweP+Igoy53OKzQnoX92BoPpNan5kIztwBx7gjJDnk56bU50GV7YsUJcP+c3WFbSCjNNCwVfNjA7B18X0mqtTFr1aQgcvM+noWIGJoraKz3zntXu5ITjICwpZY1XY3V958nZlewT6YM2qzpfXFTZQ5WEaB/KoP2V6N0ZNrdPLnDFffeoVwlVM+NRF/iIYV4cGaPdsj0hZjP0qw4pe1w01Pw9KbMb+QFjBiPaQzD8TOzUiorn08BPOs4= 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 drm-panfrost 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 panfrost_device. Signed-off-by: Qi Zheng Reviewed-by: Steven Price Acked-by: Daniel Vetter CC: Rob Herring CC: Tomeu Vizoso CC: Alyssa Rosenzweig CC: David Airlie CC: dri-devel@lists.freedesktop.org --- drivers/gpu/drm/panfrost/panfrost_device.h | 2 +- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 +++- drivers/gpu/drm/panfrost/panfrost_gem.h | 2 +- .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 29 +++++++++++-------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index b0126b9fbadc..e667e5689353 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -118,7 +118,7 @@ struct panfrost_device { struct mutex shrinker_lock; struct list_head shrinker_list; - struct shrinker shrinker; + struct shrinker *shrinker; struct panfrost_devfreq pfdevfreq; }; diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index a2ab99698ca8..e1d0e3a23757 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -601,10 +601,14 @@ static int panfrost_probe(struct platform_device *pdev) if (err < 0) goto err_out1; - panfrost_gem_shrinker_init(ddev); + err = panfrost_gem_shrinker_init(ddev); + if (err) + goto err_out2; return 0; +err_out2: + drm_dev_unregister(ddev); err_out1: pm_runtime_disable(pfdev->dev); panfrost_device_fini(pfdev); diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index ad2877eeeccd..863d2ec8d4f0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -81,7 +81,7 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo, void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping); void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo); -void panfrost_gem_shrinker_init(struct drm_device *dev); +int panfrost_gem_shrinker_init(struct drm_device *dev); void panfrost_gem_shrinker_cleanup(struct drm_device *dev); #endif /* __PANFROST_GEM_H__ */ diff --git a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c index 6a71a2555f85..3d9f51bd48b6 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c @@ -18,8 +18,7 @@ static unsigned long panfrost_gem_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct panfrost_device *pfdev = - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev = shrinker->private_data; struct drm_gem_shmem_object *shmem; unsigned long count = 0; @@ -65,8 +64,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj) static unsigned long panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct panfrost_device *pfdev = - container_of(shrinker, struct panfrost_device, shrinker); + struct panfrost_device *pfdev = shrinker->private_data; struct drm_gem_shmem_object *shmem, *tmp; unsigned long freed = 0; @@ -97,13 +95,21 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) * * This function registers and sets up the panfrost shrinker. */ -void panfrost_gem_shrinker_init(struct drm_device *dev) +int panfrost_gem_shrinker_init(struct drm_device *dev) { struct panfrost_device *pfdev = dev->dev_private; - pfdev->shrinker.count_objects = panfrost_gem_shrinker_count; - pfdev->shrinker.scan_objects = panfrost_gem_shrinker_scan; - pfdev->shrinker.seeks = DEFAULT_SEEKS; - WARN_ON(register_shrinker(&pfdev->shrinker, "drm-panfrost")); + + pfdev->shrinker = shrinker_alloc(0, "drm-panfrost"); + if (!pfdev->shrinker) + return -ENOMEM; + + pfdev->shrinker->count_objects = panfrost_gem_shrinker_count; + pfdev->shrinker->scan_objects = panfrost_gem_shrinker_scan; + pfdev->shrinker->private_data = pfdev; + + shrinker_register(pfdev->shrinker); + + return 0; } /** @@ -116,7 +122,6 @@ void panfrost_gem_shrinker_cleanup(struct drm_device *dev) { struct panfrost_device *pfdev = dev->dev_private; - if (pfdev->shrinker.nr_deferred) { - unregister_shrinker(&pfdev->shrinker); - } + if (pfdev->shrinker) + shrinker_free(pfdev->shrinker); } From patchwork Mon Sep 11 09:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379077 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 04B91EE7FF4 for ; Mon, 11 Sep 2023 09:48:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 800FB6B0206; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B11E6B0207; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 679226B0208; Mon, 11 Sep 2023 05:48: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 556366B0206 for ; Mon, 11 Sep 2023 05:48:41 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2F25312094C for ; Mon, 11 Sep 2023 09:48:41 +0000 (UTC) X-FDA: 81223842042.19.B639571 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf11.hostedemail.com (Postfix) with ESMTP id 5AF5740006 for ; Mon, 11 Sep 2023 09:48:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=klADAg1b; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425719; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=PStI7luzVZJh/mYN7JpVoeKJU5ij79ho49wnrhFm4xVshN/izVEP+5ksVsaFwNSmxxCsw0 i4RArjdeDacj9QlzswbwGtggOo8SFxVKblAgpilgT8yUXa4JpAgI5RcSAHte+yZlITwLeW 0ueSH9FXao1y82sUxxpDoMqdBVPB63g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425719; a=rsa-sha256; cv=none; b=F5u+kWueYcxpQfHHDpbyzuvpZUDMlUOTNeMEKZDAfXG8Zju2ZX7UAYLgsxuI7g61VHBEYS uvz+IdcMws5mKICTBAZHekx9GzLPKBXpbY2eGw+YUZKeN2SivJ5h2d2unMHI0HrybyR4Jz NuF+r/gtnOp+HDCB5CHOFgK8tWJEMYs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=klADAg1b; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1bf7b5e1f06so7710625ad.0 for ; Mon, 11 Sep 2023 02:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425718; x=1695030518; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=klADAg1b+/aA5Bg3a5mBt0rPKlJv68cq6MLEl5wSWeJgnvPpxZKO8c9FIOS2DfRESB EmV+dAlDGn4qsri6x/tXQK6KD+IkNuhXbG7DHhwM1A8thBztcpe/2wSaztw3sBuL7AnV UXLi/T4NiWhiEm8TX47DlJirToSzzDedK29NXEknzasn0F7uilenjUgIy6H3y5Zu/sbB hOtiI3p3Ljq1VUGyn3rhi6mEwRn3blTNTvP89qPByvG/XziQjpl3udl6gqqp6aOI+sZU vLNLwC+FJEgigOl59Ku1+/LE+HyN1S2ThOkkPrxF2u8Yqup7b1TXIOHYOw8FgNbi/P/4 wYmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425718; x=1695030518; 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=DERoMXizB4tQD41l3IFVDcK/UoRWwvr52IaKs7kkWyE=; b=i8jewwm0gLmcEXLn4dfXGcp1eF5vSMlpa8eh7PB/fAhfnbFHIruUtSbYbM5gj8BvIc 5dHgWVNYOc0U+PG9bmuPA3BOaMdHLKLO+kpzfSmLQwY7Lo9F4OPDEOeS4U2gbXNpx5qw SY4hbwRhfSON7IgPylIA3BWiOGe9cPFixUup4hPMzBIfZSXWrY99wHgVSzTlHab1z3LV +w/LK5FYr6qYd/hHXws7Z2rojdtwB2o0IUT5TdgvnDKvWJ3fovlwMbUcF7SFl1LQmIoQ 3cqgYNo7NUyRy6vWV9dCDBsCLGaCi0fPue16HtNWybkVyNcvacAVXkkVgxtMVPUiZVRz b+xA== X-Gm-Message-State: AOJu0YzXpVG3tNAFBoj24o6LeRsv9dhcw51ZgCsZyFf+pDTZrJrxr2go 2yO4ZqHqMtVqeZFO9KLGE/i3Jg== X-Google-Smtp-Source: AGHT+IEof/1ztyaPWaM/x9VlgcIownTF4cXEcNkOuH5WUE9F6/4W1qtB9/ubZOdVJeDf39167O8pew== X-Received: by 2002:a17:902:d48d:b0:1c2:c60:8387 with SMTP id c13-20020a170902d48d00b001c20c608387mr11160274plg.0.1694425718378; Mon, 11 Sep 2023 02:48: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.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48: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 , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH v6 23/45] dm: dynamically allocate the dm-bufio shrinker Date: Mon, 11 Sep 2023 17:44:22 +0800 Message-Id: <20230911094444.68966-24-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: 5AF5740006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: uegpkh34jq7az7hnzf3mqs19z63xnq57 X-HE-Tag: 1694425719-932164 X-HE-Meta: U2FsdGVkX1/Zx1AZbofgQA/sV8XLpGKMwvuuf9xvU3jHRgJ/U5VjQHphy6ft4VFVwnTg8V2Uy9xpS3o8meH+L+e5ObH/nFREd4ac1HaO4tU71tjxfPe1B4sPvx5CUgnoVW1sWQ+w+0teMXa9FbGJWdVwjIzG4HojNU3jRB7fOxsTWoGvven70z9DSFYVueWfpAEx/0nNKWfF3sXDoWtQPgDIubgA4vW0UV17mOq+R4EAPLSzaTslHXUr+Rr8eT9W5gq3YrlRXkF5syf7OxltLWC/qLgDu6ft6DBBTGEuzHViSfCh+5CGfgtsXbpYilYi+ajEzeaI+QDw/gswJ4pE0txZL4zkUbaNFcfG5/prroBTd4bMzXgqK2q3fOcXkspNILpIYonEUvvMCbIQXG70WrAx/L3Axga0ps7kg63sCSbXh0KkQdhK8WCLvAuh/W4DF2A40HLzxsebsIv2I04oy8tvpKhaiTEzikNH46pvBvJzsJt4fACOMLPqKh5Z4x6caL6yzIahUGcQUGbTK0VKEjtziMdetHZVNLAKpXDMwSVuXKPaPH6gSWibLEgKTs/x14tQAq9rzWRwHoLuIw3s0r1E8jNA2K/ON7WC6I5Bpgjy/ogqA1vOTZM2AB51dIvtzV0MwLJGBFjE0llIu0g0UAJKl8xrH3699OJr+SdSp/CrKQX0h5NiEycW034RwOkuFjciUA2YWAbx7h61AS0sW9u7bubBx1qg6RllR/CYyXUHRDIm3AYnsfKWOxgPzwyjVj6QQf7kIQw6DBLPQAS900aE7lBGRpJ+ZBum+7uFFQHeidizGknA6BoRae9m0gKSwlO/Bref37bdRXphLeFKGog3VX7x8krZz2LJMKcHOfQjTFofppIZ5udA6w58R/JQ1ZsPMPD2BfWb+phy2zCKDcwu7U1RwA2ThYH2FDhsUijOyRgdLU62Yd+KYy2rFSb43fxFjeay/BxLfO0p8/L sIB2sbe+ vREXARHl/tQz6UWlHFcH1bW3Ec76GThdrJ9XbV7kvXMbQM2UgzmnWrbvVL0dwX33DAc6lerugiLzHCwGkXFILJIEEoFt0BVPgxiPydrQJNMSPUTiAqp7k350MftnKNXZRnO9Y75qpadUruD7b+XtMfeqLyPCv+CvHq8PlgmP8p91ctGvuFTi61h4FPZlvMSpVDSDnhHVGVopeSOtqQ18q4ONTtR+bDWsi/MH7E7H8IpKs7dQ0T9Hrox7Zzj4CRHUEFILNn2lcGUOxlDZ/DJKgp2AoLCzfeN3PtCdBgqTN016Orx8Zj3ZWUI777JkE1hd/JsaNZ2cBmfUktk629ZacUv5ykFaj+ky4/G9GJX4jORTjzr2+mbEmm2rVAKGeutHYgZrC1Gh3MwRRlziXSqhrbTSgYyzwS7GWE0h6eMoX7QpokfJGmdhYFNHQCcYomACWt2wIwY/tWjpSYwpAxn7kykC2t7lm5j2lrhg6sv7clMvcv9NMDSkUIl+djQ== 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 dm-bufio 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 dm_bufio_client. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alasdair Kergon CC: Mike Snitzer CC: dm-devel@redhat.com --- drivers/md/dm-bufio.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index bc309e41d074..62eb27639c9b 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -963,7 +963,7 @@ struct dm_bufio_client { sector_t start; - struct shrinker shrinker; + struct shrinker *shrinker; struct work_struct shrink_work; atomic_long_t need_shrink; @@ -2368,7 +2368,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink { struct dm_bufio_client *c; - c = container_of(shrink, struct dm_bufio_client, shrinker); + c = shrink->private_data; atomic_long_add(sc->nr_to_scan, &c->need_shrink); queue_work(dm_bufio_wq, &c->shrink_work); @@ -2377,7 +2377,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); + struct dm_bufio_client *c = shrink->private_data; unsigned long count = cache_total(&c->cache); unsigned long retain_target = get_retain_buffers(c); unsigned long queued_for_cleanup = atomic_long_read(&c->need_shrink); @@ -2490,14 +2490,20 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign INIT_WORK(&c->shrink_work, shrink_work); atomic_long_set(&c->need_shrink, 0); - c->shrinker.count_objects = dm_bufio_shrink_count; - c->shrinker.scan_objects = dm_bufio_shrink_scan; - c->shrinker.seeks = 1; - c->shrinker.batch = 0; - r = register_shrinker(&c->shrinker, "dm-bufio:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (r) + c->shrinker = shrinker_alloc(0, "dm-bufio:(%u:%u)", + MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); + if (!c->shrinker) { + r = -ENOMEM; goto bad; + } + + c->shrinker->count_objects = dm_bufio_shrink_count; + c->shrinker->scan_objects = dm_bufio_shrink_scan; + c->shrinker->seeks = 1; + c->shrinker->batch = 0; + c->shrinker->private_data = c; + + shrinker_register(c->shrinker); mutex_lock(&dm_bufio_clients_lock); dm_bufio_client_count++; @@ -2537,7 +2543,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c) drop_buffers(c); - unregister_shrinker(&c->shrinker); + shrinker_free(c->shrinker); flush_work(&c->shrink_work); mutex_lock(&dm_bufio_clients_lock); From patchwork Mon Sep 11 09:44: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: 13379078 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 144DEEEB57E for ; Mon, 11 Sep 2023 09:48:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4ACE6B0208; Mon, 11 Sep 2023 05:48:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07DA6B0209; Mon, 11 Sep 2023 05:48:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4546B020A; Mon, 11 Sep 2023 05:48:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7E33F6B0208 for ; Mon, 11 Sep 2023 05:48:50 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 658AE1CA24C for ; Mon, 11 Sep 2023 09:48:50 +0000 (UTC) X-FDA: 81223842420.15.ECECEB8 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf07.hostedemail.com (Postfix) with ESMTP id 90B704000C for ; Mon, 11 Sep 2023 09:48:48 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UdqWth2l; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.180 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=1694425728; 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=ruGIazUIgd5W3iD+fpVWztgrL7hXLBFpKRJYJNwmlEs=; b=H9JUXeOY/mvjYVMF8Y0UO4yH0vle+wgMSLqg3I+N1eovTiL7OOFA9+0Ww4sTpqutFfg4yy 2ESYeDhBh5M7yWVta5YFNMbfktGC/kCi1DA6tSXm7UAeRb48+DBDEi/fCn6WjkR51Y7VQe sMo9y8wMypxABErijmdlXBtSXyCN0Uc= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UdqWth2l; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425728; a=rsa-sha256; cv=none; b=DDkxlmR4p3GoeivUU2c+KdMQMOPd17+/zYgv79ZtqwwrRyyYRgvRif8ZYyeawt/0a2Q/Ek 2BD7fBeZfdurSBPQYPisbXb1swe8EZlwmb+pGe5OlUC5QIBzrpd0anv5puRfxVKIOEiOa6 IX6vKDBZGT3ULFbPf3WR16Dt9b4Etx4= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1befe39630bso9367055ad.0 for ; Mon, 11 Sep 2023 02:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425727; x=1695030527; 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=ruGIazUIgd5W3iD+fpVWztgrL7hXLBFpKRJYJNwmlEs=; b=UdqWth2l5E2KGCdwt0wOgOwGPQp8Uks/0pPRe5ARsQBTpXvtVTKqk6gGp87LLqKQrE mwG7r/mEmzvVEvEYEf7KW4nka+3z4NNNfd2lLUtGfCQAtqJQG693GxktE7q01xLqSKud +pOtzfMyfg7s5OMDDaoKwWuCNNs0bRSQXvyCiU9u7pwdeBjvMZ6Iyc6gV9xY03TYBDIK MO+bHF1/gR8sFVuFoI0ZiM5ezTU6JW8/8azCpV75P2qTSBea/orLPtTrB6Q09NjJeMyE MKrKqPhXW2p7aIip/dP9oP998zBW0psCL/w5xH/RZ2qHWQkHLVpfVVdhy/tCNkYHEymv QLJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425727; x=1695030527; 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=ruGIazUIgd5W3iD+fpVWztgrL7hXLBFpKRJYJNwmlEs=; b=WmLSOEcXc2YwtAf93KUXyUjUFgdjDZS3MNx5z4k1cAQI4k26aU59nIO2weCGOsJKCq PzB0O8snH/VkbKu0cDXMw5J6DYFMvxPS5mQJsDn6QtxJtY/jOJ4WHpKsF4+qPcpFojpw VdCXLUcL317FYOscCHA5UD9Scv7eTG9W0modQ1lz9DjgG3Jo64eQPhB/SELN1icIqsfF vtZbZRWQMukyibsD2+ZnIHj2k/bWctURx831hE9eadIaEoCeXZBzpvH6q6gVAv2SIOIo Dfse5zHjBeu2B1/yGqw/uDDcEi2LL/sE4zMVBl55a1TMmf1oTQRbKqQEX+rixUK3HrAP sVgg== X-Gm-Message-State: AOJu0YzsLxMmfNwxfV3k2OpKFrHkkwRnyJ1+L7/X6N59Wyb12H0eUMLT 6Evqd5KS5PXhMAVeof90W+sBQA== X-Google-Smtp-Source: AGHT+IGGBhJFk/SRU3E2zGlQ2j/g+CUjwQeV+kN/9j9QP3+HgtWpTi+Be+pjzGQyb1HeKYNZhEoDDA== X-Received: by 2002:a17:902:e849:b0:1b8:aded:524c with SMTP id t9-20020a170902e84900b001b8aded524cmr10985885plg.1.1694425727595; Mon, 11 Sep 2023 02:48:47 -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.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48:47 -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 , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH v6 24/45] dm zoned: dynamically allocate the dm-zoned-meta shrinker Date: Mon, 11 Sep 2023 17:44:23 +0800 Message-Id: <20230911094444.68966-25-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: 90B704000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: qgrmutgbwqdfr94ry63fqbxcdj37nfze X-HE-Tag: 1694425728-128698 X-HE-Meta: U2FsdGVkX197FW2YPw2vuTGEBPBzl9LZlf9ojnaqdmZI3Aafa5PECtPJcyl2Yjizq4nn9l06k8IG0b8X89Uh4LPm7qJRhTp0UzYbs6wWCYeXMYk1bmNdoG1gfVb3MPX+ctYGyByym+tssl034qWqCRj9lm9IvaXnKtnLXvWEkd0pbBjApW7WnCG6L5j+zldftItBJU69I8srT7c4XsXqgVSG9agknH+vLbndyl0P0U3E+1GwvyHbz5WJCE4Wd7QsTcZtZzjdN6I5X9VE39dmYq4KMPum2YdTuckX5lj7Z/6oA2sh72woSj9oKhd4wqwS0C7l3joFeX7zn83yvqzKoR5kJkm1azg2RCByqYuP50/gIbiTcSlqBbepYiKR10IT63Lyg9mJM5uSgC8Itakht+cnJRCHuiE3h97su78GYdQbT3WPi6nTg2caMliTUQBVr+Hoh/CHfEF8L9W8ntISIPhjM0aKThFgwxm++/mrTVosnNWh4H+d4OgJTq/oQHYHVRhmiZ8lb6V45WlVKBMDR07aCHrBdTxUHPW0RLzwGlduJSSDjb10kQizdTHKTN2hsn1Nw65uVb7++bUkhbsNWdDP7ROofyTbyNciKfnScEwt1We/pPkhDo2X33q7wVrQLA+ZJQAJNLCemFrj6GlZZSQ46JMkKuWZkU1gQlXP1pygVOKkROfYkqOED0UiOfxrn7fvgvU5M63bfKEZwg2VKgWZZu3ien3f6UBxwORvUA+n/L+UN0v9dx/7m/6kzBW0dAEscPAZlGgKcJaTaS7BgOm05TJQpNoTbWKge0RUrgR83DDNRDHOZVdkG4UdMFFW/mslj7J1lN23Z9FWJil/7HWELGAjvtczxXDPvzD382Z97324ar1m7DlbLeaZEKZMgp7cF55LvmH6Yv2mjhtmqcbM8DT+W3f9Xs0H/tZ187I6MDzal+MbJBPexgK3hr1jdyflQkUvwCj9B00rdHc eSbFUlXv 7Fw/N0vvx+RQkNFwnIaI4ZY7ZCABLxjZpPIwQVhZXTMl3bcZRv3z2FdsXle50bbK0VfNga70sq7hb9dL/adL8/l2ZgJ6JUlpZZCgXjfTkMDzgcDWBkLmcqfE2pTjiAAi/GZio+EB7jTogZRQvMK5SBpj51JQMl7nmNxBESYoUOZIvAqlPyfWBjqCNcnlQLuXjpiQiBAJqE5QDid3HLWP3FcUx9wvyDvgKno4+0ZjzSWmJ2UvzJ2ha3OINfggckOZvfxE7zmJVBXxxXX1MQiljGeCCjxxu8KEEoRmnu6WNy/aAuf+3OMKS6sDcwirDfcPnFo51j9osZlyrrpeJ4tLW2I5kGwn3zwGpl1jzze6q8GfYUkZsT8Kk/pOK6RNPCY7q2bsjAeTLUaXWHrQ/X97I1SBYtJq3/DVNNX13+B6TwEDHUdr1KsotlHszqgi+A+AJ9ruHPAjC2/HItLPawkn9QNwOIAyMYEIkbrozgnuXLm3RUb1vbOnPA68qog== 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 dm-zoned-meta 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 dmz_metadata. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alasdair Kergon CC: Mike Snitzer CC: dm-devel@redhat.com --- drivers/md/dm-zoned-metadata.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 9d3cca8e3dc9..60a4dc01ea18 100644 --- a/drivers/md/dm-zoned-metadata.c +++ b/drivers/md/dm-zoned-metadata.c @@ -187,7 +187,7 @@ struct dmz_metadata { struct rb_root mblk_rbtree; struct list_head mblk_lru_list; struct list_head mblk_dirty_list; - struct shrinker mblk_shrinker; + struct shrinker *mblk_shrinker; /* Zone allocation management */ struct mutex map_lock; @@ -615,7 +615,7 @@ static unsigned long dmz_shrink_mblock_cache(struct dmz_metadata *zmd, static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; return atomic_read(&zmd->nr_mblks); } @@ -626,7 +626,7 @@ static unsigned long dmz_mblock_shrinker_count(struct shrinker *shrink, static unsigned long dmz_mblock_shrinker_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct dmz_metadata *zmd = container_of(shrink, struct dmz_metadata, mblk_shrinker); + struct dmz_metadata *zmd = shrink->private_data; unsigned long count; spin_lock(&zmd->mblk_lock); @@ -2936,19 +2936,23 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ zmd->min_nr_mblks = 2 + zmd->nr_map_blocks + zmd->zone_nr_bitmap_blocks * 16; zmd->max_nr_mblks = zmd->min_nr_mblks + 512; - zmd->mblk_shrinker.count_objects = dmz_mblock_shrinker_count; - zmd->mblk_shrinker.scan_objects = dmz_mblock_shrinker_scan; - zmd->mblk_shrinker.seeks = DEFAULT_SEEKS; /* Metadata cache shrinker */ - ret = register_shrinker(&zmd->mblk_shrinker, "dm-zoned-meta:(%u:%u)", - MAJOR(dev->bdev->bd_dev), - MINOR(dev->bdev->bd_dev)); - if (ret) { - dmz_zmd_err(zmd, "Register metadata cache shrinker failed"); + zmd->mblk_shrinker = shrinker_alloc(0, "dm-zoned-meta:(%u:%u)", + MAJOR(dev->bdev->bd_dev), + MINOR(dev->bdev->bd_dev)); + if (!zmd->mblk_shrinker) { + ret = -ENOMEM; + dmz_zmd_err(zmd, "Allocate metadata cache shrinker failed"); goto err; } + zmd->mblk_shrinker->count_objects = dmz_mblock_shrinker_count; + zmd->mblk_shrinker->scan_objects = dmz_mblock_shrinker_scan; + zmd->mblk_shrinker->private_data = zmd; + + shrinker_register(zmd->mblk_shrinker); + dmz_zmd_info(zmd, "DM-Zoned metadata version %d", zmd->sb_version); for (i = 0; i < zmd->nr_devs; i++) dmz_print_dev(zmd, i); @@ -2995,7 +2999,7 @@ int dmz_ctr_metadata(struct dmz_dev *dev, int num_dev, */ void dmz_dtr_metadata(struct dmz_metadata *zmd) { - unregister_shrinker(&zmd->mblk_shrinker); + shrinker_free(zmd->mblk_shrinker); dmz_cleanup_metadata(zmd); kfree(zmd); } From patchwork Mon Sep 11 09:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379079 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 906B3EEB581 for ; Mon, 11 Sep 2023 09:49:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 345D46B020A; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F5FE6B020B; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 197426B020C; Mon, 11 Sep 2023 05:49:00 -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 081806B020A for ; Mon, 11 Sep 2023 05:49:00 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D86201408A3 for ; Mon, 11 Sep 2023 09:48:59 +0000 (UTC) X-FDA: 81223842798.07.A123658 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf08.hostedemail.com (Postfix) with ESMTP id 1006C160018 for ; Mon, 11 Sep 2023 09:48:57 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YOj6IdCF; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.48 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=1694425738; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=iyhIsNI0LOJQ4C7+FxB7Or6+46V61W7ZHlg4ufF+npj6TqdpBYj4owSdbD9Rju2z7v65rR uv2mg9aaII5ozQbexaf2VwvVkHpdR0ZoQCUrjHjbNuy6kzhG2uVKbJXWuh4Ynz5P5aBIRT bYatQkQrUm/SdXKb44yI+viT0HLFcXo= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YOj6IdCF; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425738; a=rsa-sha256; cv=none; b=1LLOtOPPh8kCim+dTcMfUTjFEHChR1GMJG2LkfSbZkRL/A+7s130KLw/358e7fYZYwMThw ybW+EijyM0lodCD9pMoqmLuAIaGWtwR7i1KHPLUzBXR0LE3j5AYIMdjkQ9o46PV7hmUSu0 W5T70DxIIrUq7DKIkGhoO84NH1vIc6w= Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-273d9b1908eso716542a91.0 for ; Mon, 11 Sep 2023 02:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425737; x=1695030537; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=YOj6IdCFFB14yl9zRUgkblgikz7eGwnXnRWU6rZ1V0Y/3zaFn75nVpvRuh8p+mi9xw myJSml30BKDlrGhdL7m+LzyZ/7GtGuEmjXe3DwTE9Aoo4B3JeG/zRMIUyodlKrfUCnFo k/JWbCcCU4rQuDdiBo+Nb8SNPxnCUNC09Qtgvx1QfME7vnhfhdbrSUvNAHIOpiaQZMGL h7IxJIE8pOtRdxytw4fGlXWqWGsoZ5G4y2hExvbs/NCt7d9bv3f6cHuZDDBWTlXQG4mi ExNqpYQS2gA0o619V1wAol02SsckD0DZR4ib+SQqSiZQ7Z21VQ0v+WdrPU2n3O25GVo3 ytRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425737; x=1695030537; 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=3Yj0gPfexl8jpeLTCYtbI5G1wb/s5xsc3LDcKfsQ+pE=; b=CDNRW7bpvGnTgcmKAJCYQ6/r8wguCBqpDbWhqd2x+DlEvVGzzgDiahXKMhR5jBEQVl 6SAfMPQVsPKuXx4TGNWS3P6I7eUBxNo4AKWuIbH2pIpdVnV5KBgGqv7SjVAbf9gxoDo+ vsv+wtUTKP9sJF6d/GxcSP06GvOGhHvcwBD80BPb/TVEhqyXPkf0WwaHEZNgN8/KMNZP YFKEYTqk5Z3vSYzOT3feaJgZ1G7siVMNC+WQfu6GslzB/0HmanowYDrYTtMJERYpHN/P XmFYpsHCDJ7w7tess+7tG7ithO0TcbVL4fB7ur3JKLFwWoPRQ20SWyGRYZxciKmH6HXx HtBg== X-Gm-Message-State: AOJu0Yz3M2xoZUioJw9LHjE0J/w+8JaV7DS+FP8nJzMfRthQxvyFX4Gm 8rrxZaAEimPhrmLEDGnuEfQQIg== X-Google-Smtp-Source: AGHT+IFZ0Cuso7zcW7EGyUKF+CdPkMsrNNduA/1bSkXKanT+gK0Pmmcny6T+hZLeB0kr56AjQb9xKw== X-Received: by 2002:a05:6a20:4401:b0:140:ca4c:740d with SMTP id ce1-20020a056a20440100b00140ca4c740dmr14472508pzb.4.1694425737026; Mon, 11 Sep 2023 02:48:57 -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.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:48: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 , Song Liu , linux-raid@vger.kernel.org Subject: [PATCH v6 25/45] md/raid5: dynamically allocate the md-raid5 shrinker Date: Mon, 11 Sep 2023 17:44:24 +0800 Message-Id: <20230911094444.68966-26-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1006C160018 X-Stat-Signature: j5qprb3n1eepjryicjc1ncj63t3ufz6m X-HE-Tag: 1694425737-545099 X-HE-Meta: U2FsdGVkX1+VRdOaouldbe1FeL672HhGjZTD0gVx92eH3KsHdLhfvuZ2hG8yFmxsGMX8hRj8IFlg3aWCuMdPc8Yofx5JSUiCLKje3r0B/wtMujbBSrXF4PGpUOhUaShMWe5jBc5FQMrtl6o4QBJP5UvZwqIiiPyWkO/x8ICa+UAxdoUS4FvmzlGhmYar3hrxfdvckrfy3TGaV2aZA4526jyNwdK484/GKwwmphyR7IKT913v/zZZnlf2jqaMyC6QNYiXZzid408oEAZs3JA7YPdB0mFxB/1jr3GnD+0F1hjqgJR/MKQUcToZzTzhUXBppSP+9BPQyGTZnGK1xPxubCF8XM+E8wN+a/gPYB6hiJRy+9427gd3bY4rdaO1+IsuleFo1N6KqsBnieWEsPIKnvAwBUzgU1dZM6nMy7ikvmFMnhfImvYWGJCLyFKICQWrzTbORF/ICNkT2kNSdHJ6ri5y/DA9KcM4zjKpMDJkFhXdP/Du0gFHhZk9PP6ZLsjMcYgbJ/AUEpAp7106b+OOWL14S2QDnEFL35aC6bP74BcpaSL7q0sHAcN6O/7zNgCbZZ7GX/UUsoNDuv6tlnvaTEUsTw8rRskhW4okHHfYzrH76Z/utoynGHPcpn365ueZA7XUQv2mFqxvfNE8ASiefUmyIaKBTL1Y2VB+OTBg5ak4vXoC1BBt/s1tdHP2vd/G1ErYtHwxhmxRkXPnTSebTjQIMycz65UKwO+oirrDSg7gvIDaWHpYMQt26MOZAqxyDlCVgkPrhFMuNQ7Pgz+A9OluAKOyx2bNkGZTPOh3HPK8oqSgugELW8jcsc1Nkgzjf4W3vp1MmBdMOyPgSQph8Oas67+ykt4jTK9elNV5IZ00GrtEDPaZFeB7t9Le7hGSWF2CNMipVdbMEyK0+0IEBnjerzg6rrbFTwiZmSWp1WOE9Gpffjmj2OWOdC5XGkwfQ/uom8/z8XVp5VtjRP6 +gF6/5SX J3/2jv+olwcEMQfSSa6Z4d/ByHVKZumPw7gpTZKTU2np7sMjLBiAHPlTBzqdxGHhxVyihhvdKD8YN491lzqpe5zMT0SvlQf/DvLYmOxftkbkt5llMcSFmxFUJssj/TLrvNKdJE8nip8uVpq7F0umzl1qftCh6uitJBy53nZujzlvAz632pqw3WbyVyNyjUvBo3AHwXevbwibp9+3UDftulm3cdO75fY2Ml99Dfib+Th45cGBDG9j5tt2X5svZ5ktsCd3BrQsndlSijbmgK30X0dYiiMk+sd1Q72sRNiHGt7mVs69HADrUAxDgJgXdTmBdw+mph/GKq/Tj3N4+TyLlcssF6Nt+yPvJspNZIbpwlTCI345pgD39gaH/gBoo0rFTLlUYWIvni7PwJXmLP7R86GaXNMIuvP8y/hWI6WvZUFDJL+LoALcj/8r1P6ps7jYVKLJw7nCCD8rMSJeY3EFDwJU50Bnr6TG3XAd2 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 md-raid5 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 r5conf. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Reviewed-by: Song Liu CC: linux-raid@vger.kernel.org --- drivers/md/raid5.c | 26 +++++++++++++++----------- drivers/md/raid5.h | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index 4cb9c608ee19..c8d2c6e50aa1 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -7401,7 +7401,7 @@ static void free_conf(struct r5conf *conf) log_exit(conf); - unregister_shrinker(&conf->shrinker); + shrinker_free(conf->shrinker); free_thread_groups(conf); shrink_stripes(conf); raid5_free_percpu(conf); @@ -7449,7 +7449,7 @@ static int raid5_alloc_percpu(struct r5conf *conf) static unsigned long raid5_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; unsigned long ret = SHRINK_STOP; if (mutex_trylock(&conf->cache_size_mutex)) { @@ -7470,7 +7470,7 @@ static unsigned long raid5_cache_scan(struct shrinker *shrink, static unsigned long raid5_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct r5conf *conf = container_of(shrink, struct r5conf, shrinker); + struct r5conf *conf = shrink->private_data; if (conf->max_nr_stripes < conf->min_nr_stripes) /* unlikely, but not impossible */ @@ -7705,18 +7705,22 @@ static struct r5conf *setup_conf(struct mddev *mddev) * it reduces the queue depth and so can hurt throughput. * So set it rather large, scaled by number of devices. */ - conf->shrinker.seeks = DEFAULT_SEEKS * conf->raid_disks * 4; - conf->shrinker.scan_objects = raid5_cache_scan; - conf->shrinker.count_objects = raid5_cache_count; - conf->shrinker.batch = 128; - conf->shrinker.flags = 0; - ret = register_shrinker(&conf->shrinker, "md-raid5:%s", mdname(mddev)); - if (ret) { - pr_warn("md/raid:%s: couldn't register shrinker.\n", + conf->shrinker = shrinker_alloc(0, "md-raid5:%s", mdname(mddev)); + if (!conf->shrinker) { + ret = -ENOMEM; + pr_warn("md/raid:%s: couldn't allocate shrinker.\n", mdname(mddev)); goto abort; } + conf->shrinker->seeks = DEFAULT_SEEKS * conf->raid_disks * 4; + conf->shrinker->scan_objects = raid5_cache_scan; + conf->shrinker->count_objects = raid5_cache_count; + conf->shrinker->batch = 128; + conf->shrinker->private_data = conf; + + shrinker_register(conf->shrinker); + sprintf(pers_name, "raid%d", mddev->new_level); rcu_assign_pointer(conf->thread, md_register_thread(raid5d, mddev, pers_name)); diff --git a/drivers/md/raid5.h b/drivers/md/raid5.h index 97a795979a35..22bea20eccbd 100644 --- a/drivers/md/raid5.h +++ b/drivers/md/raid5.h @@ -670,7 +670,7 @@ struct r5conf { wait_queue_head_t wait_for_stripe; wait_queue_head_t wait_for_overlap; unsigned long cache_state; - struct shrinker shrinker; + struct shrinker *shrinker; int pool_size; /* number of disks in stripeheads in pool */ spinlock_t device_lock; struct disk_info *disks; From patchwork Mon Sep 11 09:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379080 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 5A0F3EE7FF4 for ; Mon, 11 Sep 2023 09:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB7D76B020C; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E67CE6B020D; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D300C6B020E; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C30A36B020C for ; Mon, 11 Sep 2023 05:49:09 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 885ADC0957 for ; Mon, 11 Sep 2023 09:49:09 +0000 (UTC) X-FDA: 81223843218.02.736093F Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf07.hostedemail.com (Postfix) with ESMTP id B59234000A for ; Mon, 11 Sep 2023 09:49:07 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=biBHz4rB; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.175 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=1694425747; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=MjMb+tDB59+FWxakX2eTpInAhFP9AywY1N7tsOCzywl7nyORcdYs5q9VPAgzwPTu1bwCyj yisLllIkzR6cEsiJMRWUX77j205bfCGz/OdnFI+i4BN6c9VyykghfPNjGJ7oO5bXQ6C/mD LDsMnexguc8xM/5D9TYSNcqAuRrs/5g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425747; a=rsa-sha256; cv=none; b=E58jbKwLFUHOvlw3x1YAN8sYkvOKp2hxv0u2sQ8n7gsZyPj3Ywfxq/c5t0vL3JQB9zrgxm bsltkaKLsy+vbw+6e1/EqsYG4Ydk9Lo2FhDbjPag5fNuyTqdRiclPKd9n8m4q5/u5ngI6+ R/8j+CaL8q7bLGd20edUfsrj50UEtAE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=biBHz4rB; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-56f8334f15eso230473a12.1 for ; Mon, 11 Sep 2023 02:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425746; x=1695030546; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=biBHz4rBqdNsCZgYBy1Fe1TAfYY3izYguVgA4m8OREe/gRwpHu+bOrfDY3PY7W4cqI fD0gEliggVM7mwqKnNvdWAUcVvvIh7yjzXQHJaweneQKuMQZ6xlHKbYI2PLdW6zVFjF4 jJeK3Miry23J1jq+IS77c5tZlJRS6kOXwFHjYjVH8+/zQX1zCiKX+UhAoMwIiR5b0TUQ Z8E8GEkhAvU5/S8xI+PXSnpHTspZOc15fGmvbaq3PxLDAuZav/SZPqW7J7U+E2IfeqJj CPzP6KM4gspcKyJTCdRNaMyoGgkurOHUTqHuQ79GgX7g3O+UHYtHyMStWuUB9lL9L4lw 1Cew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425746; x=1695030546; 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=Fa4A7mARo9UASqTNF5nYV+l5Qm4MYZjHRGtSJYP4Y4U=; b=seH0ya2epAyIeKZR6W3B7s0+hY/8q9yr3ZUVPaDMkz3gvU5cc38c70SyMRyl1QIypU Hukfyw88MUZ9NIOenV2G8AsNDC9GeMIb8WR5qQ3Rne/FvTLo6efMTaqbWV2sClm2B+ZO ++pu+uVen7lmFbPV8aad9PR5uI7kmfcXdnYO9a5vs4gXensPqnq1YK1iKQtyes2vyshZ urv+HwK7khsnD1Ea3rfx5WVQpj5mET+iJYme+ZlMMUFYsy+61H/eS74+pyNBy/0UQJGf fZ7C/elbNq/bDXU4ejfC3CGyKOg+cEEEp/IxUEjVc9Xnso26tIJjczijHzqqDtCNk0GR ZmCw== X-Gm-Message-State: AOJu0YzLeckKgYgsk233g9frq4jYgU+WNRZ4rrhlNYY5ytsCtEY2fa5f P+1y443EBtynvyfwngqrDoNgqg== X-Google-Smtp-Source: AGHT+IFB4SYhQnUqjdoilwCEK8hAhTVrnXXU8/drEtqr5yeRvfcPj45sGXWOGMKyaN8MzCUyMc7RRA== X-Received: by 2002:a05:6a21:9983:b0:136:f3ef:4d2 with SMTP id ve3-20020a056a21998300b00136f3ef04d2mr12710572pzb.3.1694425746623; Mon, 11 Sep 2023 02:49:06 -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.48.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:06 -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 , Coly Li , Kent Overstreet , linux-bcache@vger.kernel.org Subject: [PATCH v6 26/45] bcache: dynamically allocate the md-bcache shrinker Date: Mon, 11 Sep 2023 17:44:25 +0800 Message-Id: <20230911094444.68966-27-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-Stat-Signature: e8nbi4gmunbqnkz8ku8jdn5jdcxybg3y X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B59234000A X-Rspam-User: X-HE-Tag: 1694425747-548208 X-HE-Meta: U2FsdGVkX19LEloQTBSayAUKgyVpm/Vx9f/wVDYXSr58Sup2mH1q59LGAzi2HMnxLE7Rhp88x8K6AYz6VWDR7G0Yg0yn+kc7yG0llQVR1eN7kLQ194dk/IjhMBUua+0U/BpobmYKcehXtmQmkp0Tam/e3hXnZEjXkwaTqVPfQCwVze3wI2FkFk2zNq1oYJcv9p3raYb555qEVIHSWhN9osxIme9OdtORk0KAd5d4L8w12Yq7xfJqSuNyGvUK/TjSO3iy9nH5rkECBGH0s+YzAq0GOHYwITl4a5zS6x9icuJ9k/ruBFsZ4U3SJkoNaUBl3uioxbRK1UL5GZe84BGKJ4bdAJC6kh6LRq6WTg19IbNaza4TyZBRcutD38i9XV66rC10swHAD9OyJOIjaxzPsVl3jhCxsO55hjFllFgeLVosovixfFjwbCyyH8pkUcG16gk3zb2+2uFpp9L17SUbkf8C7TibPdwK5OcepxuV0PFP34vQuNCozGpqp+ZejV9QkkMJ+0DFyfL9UjgdE3qFMpaRY/P1FuM2S3WW18Nb8Htzs1IwCeHZd/guz+9IUhsea2dMolGlCvZDhdu9SQzIGSJK5MIZJn6RekTf1WH4t0uxA/OtuUqqS4A6+CVWJxFWiudX6uifBu6yV8bMMI/CCjbwimUTUMJAeuILwXwmieO7UpLseB7X5sQkbCo3tgoNBp0l0r9+IR+t1JJVf7RzwLZyGtjlicbWgs5Xh9M0rt1d8P6DN/N6DJ5kwFHMDXjhMWZEp7x3VVe2O0S+sUtBhypRsmhe3oJEZYURnX0CQmhQeyXvllHe9Cipq8WG3DPcR2YWlutAwD7CaHqyaggQfzvDLMnqvO3XwZZUhzYM6EdKaKMKDUV4grFQegJaFuc/oDn5k/nmXY/VtqcA+aUT+2P01U3/iqGoaOW+a7TOVtxv7DvSVXOBMPFxA3JMjowJ/53NT77cU6UVVis8nZy zupBDhmD YTW+znm2nDXuXvT7UXJ6xWJh4WceGkqoAvcCWK23VyNs9bLecWChzgJzaCmOjH9mutozHbXDiJ4HZRo99ScNXewYw86tbPQxIZj82RnT7qwMOPWteP4ceXErDk8xaZ28u2hErX8WnvpFhvlyX59QmR4GKDQkAbFjKrLkVO8CYxw0srkjFAmCoiAFsf3r/38b9WUWtbA35yaNPyZM5qo2cv49zapixtV8tEI5ceTkFubzqQe4N88vchmuygXIQX5z8ZmnCdPjTMYutbRdBO8ZwOcYSskj3UjyBRRDao/dPjtvqKwUn/6XuePxZvWY/Amaj7YSf7hJ3iL4c65zxONHTtaIfhL8JGd4ZGl7HMjaa4Xgkt15qXvXxu1zZNT0VS1/PPxPNEXx9N7KVo8gSYI0uwyVSOkFGS2McEslfQc7LErq70uT3fLr22gwDN3vH4ajJz8VQC2XBII1CWQ5i1qv0Z16S+LFak7xYjqv1iwz95CW1S6NRWEn5alDaJguWywR/aJ8gSMTDcH/U+/HUjrKMVnN8CpRLu4P+zBELEvRN6a4QbiS+GiVnu9QqH9i+d02Z41PB 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 md-bcache 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 cache_set. Signed-off-by: Qi Zheng CC: Coly Li CC: Kent Overstreet CC: linux-bcache@vger.kernel.org Acked-by: Muchun Song --- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/btree.c | 27 ++++++++++++++++----------- drivers/md/bcache/sysfs.c | 3 ++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 5a79bb3c272f..c622bc50f81b 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -541,7 +541,7 @@ struct cache_set { struct bio_set bio_split; /* For the btree cache */ - struct shrinker shrink; + struct shrinker *shrink; /* For the btree cache and anything allocation related */ struct mutex bucket_lock; diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index fd121a61f17c..ae5cbb55861f 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -667,7 +667,7 @@ static int mca_reap(struct btree *b, unsigned int min_order, bool flush) static unsigned long bch_mca_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; struct btree *b, *t; unsigned long i, nr = sc->nr_to_scan; unsigned long freed = 0; @@ -734,7 +734,7 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, static unsigned long bch_mca_count(struct shrinker *shrink, struct shrink_control *sc) { - struct cache_set *c = container_of(shrink, struct cache_set, shrink); + struct cache_set *c = shrink->private_data; if (c->shrinker_disabled) return 0; @@ -752,8 +752,8 @@ void bch_btree_cache_free(struct cache_set *c) closure_init_stack(&cl); - if (c->shrink.list.next) - unregister_shrinker(&c->shrink); + if (c->shrink) + shrinker_free(c->shrink); mutex_lock(&c->bucket_lock); @@ -828,14 +828,19 @@ int bch_btree_cache_alloc(struct cache_set *c) c->verify_data = NULL; #endif - c->shrink.count_objects = bch_mca_count; - c->shrink.scan_objects = bch_mca_scan; - c->shrink.seeks = 4; - c->shrink.batch = c->btree_pages * 2; + c->shrink = shrinker_alloc(0, "md-bcache:%pU", c->set_uuid); + if (!c->shrink) { + pr_warn("bcache: %s: could not allocate shrinker\n", __func__); + return 0; + } + + c->shrink->count_objects = bch_mca_count; + c->shrink->scan_objects = bch_mca_scan; + c->shrink->seeks = 4; + c->shrink->batch = c->btree_pages * 2; + c->shrink->private_data = c; - if (register_shrinker(&c->shrink, "md-bcache:%pU", c->set_uuid)) - pr_warn("bcache: %s: could not register shrinker\n", - __func__); + shrinker_register(c->shrink); return 0; } diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 0e2c1880f60b..45d8af755de6 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -866,7 +866,8 @@ STORE(__bch_cache_set) sc.gfp_mask = GFP_KERNEL; sc.nr_to_scan = strtoul_or_return(buf); - c->shrink.scan_objects(&c->shrink, &sc); + if (c->shrink) + c->shrink->scan_objects(c->shrink, &sc); } sysfs_strtoul_clamp(congested_read_threshold_us, From patchwork Mon Sep 11 09:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379103 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 1E4A7EE7FF4 for ; Mon, 11 Sep 2023 09:49:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83DA6B020E; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B34196B020F; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D6716B0213; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8C3486B020E for ; Mon, 11 Sep 2023 05:49:18 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 6DDB040753 for ; Mon, 11 Sep 2023 09:49:18 +0000 (UTC) X-FDA: 81223843596.06.0DC722E Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf15.hostedemail.com (Postfix) with ESMTP id A5367A0022 for ; Mon, 11 Sep 2023 09:49:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hkmsW81B; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.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=1694425756; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=RrblDNzmkFjhHMzlfXgn6cHiNDEGEJkff30NVa99vkvCvEtRk8OYMuTFtTIhKgFyBAXXsh yZz/YvaxyQ19E/Z5msvScQ7STy/VgXglP1UfZRuLdi1oB3QwyLH+6euZ5sjYiFv8i+80UW QVeH0Fuz2KQr91IkpbPu7Ko+5j32fTk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hkmsW81B; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.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=1694425756; a=rsa-sha256; cv=none; b=rMrbbVDqWv/PDw4mk8sw0tVhHzresK+DXB7GPLimtG9ozQQrbjH1jCVNkFpPH3b7hirhvB SRoQ/nS0FkMIqlRw8PU2GtCMROZXXPcVTzZsFg9ztuILYLuzOxF9Emz0qQey5Hr16ld/e3 pilDnoG3XLHRM7sot+RddQbYpguJIGY= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1bf1876ef69so11142465ad.1 for ; Mon, 11 Sep 2023 02:49:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425755; x=1695030555; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=hkmsW81B4YxYNoZmwdtDSKnpCbdum8aP+xRhJG9LPkYn0XUZ60ucqXdbASQegh1v+b Sdt9DFzqo6GoArXZbMMBSOZsHTmro3vcGEIGqwTiDrA5fljBTe/yCu/Barh9UJ47uxfz XxsI9+y8RNkcYX7muQ5Bc8Nc+py99Td2LciDBpBu5hlbPDKquspjET9VJtaoxhmM2jfs 7RzdwZrLNNFhpx49bce20zhsL6G988Gv5C5PlR81EI7jOVew951emMi4Pq8g5LrQkG4x 2BdjUC7eeFO8CP0N2KcLA+tbTIZb9rCUYhYOK4EULQ8ha3vif6cVplgMFFlrnYvfaDIQ Ivhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425755; x=1695030555; 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=Iv4+I9qs+KANLJaK53QHVxwskZBXOowpEQY9lGK28w4=; b=ISU7mwBML9Ngjettl4c/0lChUPFd4TcksRTscR30sz+dIY82kBHd/3FR156aqQu/wZ JfZi0ZFHqzZg2cwr9+APK/3LqW4Aov4PfbvaOD/cMNavl6UyTR1tL+doJrkIoWi9BMi6 xHpNrZdRp03lFk0XPH+yX/z8YAkOA3RwUEFMvK4u5OUBRiLGa2/RxybRau7CfjgYyV5P ba7038BIUvJUCuJJxusgLcNmfEAYjL+XnFsbyGpLg7atUIYb1op/X7T9FaaaqGKYKCwq kvIewqjYMQGxA6tMQ1iDOynyMqXrOpU2PoE3OhVDKof6nfXva1T5A11HOMKZJTLom+rj 2ZMQ== X-Gm-Message-State: AOJu0Yz5u4q3nBKsCNP6LaCU7qdV9ZgRfWRYHdyUtoKzIgEU43Jp5qzE EXTPzErXerKNB6Y+iqxKEYwrPQ== X-Google-Smtp-Source: AGHT+IEdRnAd72WYbN/lPKVmYN7Gm8oLIBUCIcL/8BMMQo0OE3Z9NszhBcdotvpIkMipjaUIUmLwpA== X-Received: by 2002:a17:902:d508:b0:1c1:fbec:bc32 with SMTP id b8-20020a170902d50800b001c1fbecbc32mr10682658plg.6.1694425755638; Mon, 11 Sep 2023 02:49:15 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:15 -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 , Nadav Amit , VMware PV-Drivers Reviewers , Arnd Bergmann Subject: [PATCH v6 27/45] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Mon, 11 Sep 2023 17:44:26 +0800 Message-Id: <20230911094444.68966-28-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-Rspam-User: X-Stat-Signature: bis8sakgjeohtex85t3hityc3kieu9ju X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A5367A0022 X-HE-Tag: 1694425756-943083 X-HE-Meta: U2FsdGVkX1/HxsO01lMdC+OlXQ9678NT2zfdICCp8HY71bzKsbPdHgVlNJCC/zPVQBuGCTjjh0bhfjWHrUzHDrW7rSLKC/1WIdUFRvso/dnYNXgKFIweNFsMIT8LtyEWe2eTQmpx52fMS1UMVQh/aSiubz1apV1U79nwkXQGdlcyY+1tmR04InhnBCHWuXHfHzcKVn+IDzAKVMBcOxukHeXoasPMxyg7QlPyJBIOL3NToyXzel15EeoavaWlhPsWf6ocLpLG9oQpacyKc92sfkjs/GkKYGx4vXaWXmIo5fa+y2Y9lSqZrLEBBPQm6jwOl2kKTybl2sZIMgN4sho4aRjJkgjNHde91Pf2G0v2WD+4SUmBn1C85S+oHVu3L7WJ08GSBfpJkcwzNODIFx9qyl7RrBBpIJcPTAKjseAeLsNO5oh/ABT1QoB+5ri5wjt3u2agsjg/ZXYW/lwUPHDC3Onx0VmRZbErAl1Bl92hDtv9rSYKFjOrbrZtTkWu4J2jJH6P3ddBriaTrauIt8eqQ1WfOozF9YggB/GKsmJITEfD3dT95N/petiByrtnjHBc5v0NOYzIKyjI9oj7Qb0CxoVmiUTP+2xqSiHCNYUEEDWD6x4n4nUHIx0BoevnthnHKzXJzBIPmQMecfUU4yyNsxM6OoWku3JH+I+8V8clBKmCDGl46mGPKe1mL5cFHi2xFQA2Y3vs0g4e8MhNg6t+vUC/UeQk352EreVXbWojWi/VX14ixk57J50hf9uBm0NA3yESRwiR2YCba1pXWlAi3JF175gSQjQY5Y93fye63mWIChGfwDzfwdPZavR82BC8j8lY+BBFaFwAAz6pWVUsvzu+D2GPG52ElL8HyKDxjeV682+rhxc7LvddceNeDSOgyo6KmqCIqrphURDdnmG+cgdl3M3Iy4nf4amDQBUIRj0aheOaPYM18B+6iwtk4KXpXbMmxN/6pTccnMuw47V nOAl0jHb 1TQYFrCn8ZBGosMNgMNgQRrqwCQEOoDN/YaBatFo4vqNTwhJDqKrmSzzUjs73k7mPYlbFSpti/jVird2/ZZ1hGElqriT+nTKgfPIAJeOcBhXTGi9IGQn+sv71U6KjhZPrCrivIp44dhEuboXjqpLtiW1Vcf0tJJRRcwOzRkf182D8KG66OGvukZ5EKdypsh+YSne7Opw4TRFq71WYU2C0nTy3KOIs0FIKQArTZDL3wCTRt5CoDVrD0zxTDFP5/j40H2QAqOS0ZCFuNQjhPYceVCXzR66id0V4oQ1byc0+aHFo4mNPVpJ8ZVDanY4Cjw8TP01X76nHhK8CbqMYBmtB8TJGuNLyGOwinSY58gJDO0vF1WSNwD+B8MmufGaxSozNU84Q559sG/kUj/reQZYZAh5fb5cKtIG9Kx3v9B20u/IcLEt3w97nCPlU8rjqrhMwI/rRsmNnKAieVrYWrZuJlzVQ4JNmMH1K2IARfkd1fuCgllKvR+W3nR2cFN/EwLcEWIcgcMfFP5OWkuE8VS92Ydn5hIxgJuY/GLJzeKTryGTP7cE= 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 vmw-balloon 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 vmballoon. And we can simply exit vmballoon_init() when registering the shrinker fails. So the shrinker_registered indication is redundant, just remove it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Nadav Amit CC: VMware PV-Drivers Reviewers CC: Arnd Bergmann CC: Greg Kroah-Hartman Acked-by: Nadav Amit --- drivers/misc/vmw_balloon.c | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c index 9ce9b9e0e9b6..c817d8c21641 100644 --- a/drivers/misc/vmw_balloon.c +++ b/drivers/misc/vmw_balloon.c @@ -380,16 +380,7 @@ struct vmballoon { /** * @shrinker: shrinker interface that is used to avoid over-inflation. */ - struct shrinker shrinker; - - /** - * @shrinker_registered: whether the shrinker was registered. - * - * The shrinker interface does not handle gracefully the removal of - * shrinker that was not registered before. This indication allows to - * simplify the unregistration process. - */ - bool shrinker_registered; + struct shrinker *shrinker; }; static struct vmballoon balloon; @@ -1568,29 +1559,27 @@ static unsigned long vmballoon_shrinker_count(struct shrinker *shrinker, static void vmballoon_unregister_shrinker(struct vmballoon *b) { - if (b->shrinker_registered) - unregister_shrinker(&b->shrinker); - b->shrinker_registered = false; + shrinker_free(b->shrinker); + b->shrinker = NULL; } static int vmballoon_register_shrinker(struct vmballoon *b) { - int r; - /* Do nothing if the shrinker is not enabled */ if (!vmwballoon_shrinker_enable) return 0; - b->shrinker.scan_objects = vmballoon_shrinker_scan; - b->shrinker.count_objects = vmballoon_shrinker_count; - b->shrinker.seeks = DEFAULT_SEEKS; + b->shrinker = shrinker_alloc(0, "vmw-balloon"); + if (!b->shrinker) + return -ENOMEM; - r = register_shrinker(&b->shrinker, "vmw-balloon"); + b->shrinker->scan_objects = vmballoon_shrinker_scan; + b->shrinker->count_objects = vmballoon_shrinker_count; + b->shrinker->private_data = b; - if (r == 0) - b->shrinker_registered = true; + shrinker_register(b->shrinker); - return r; + return 0; } /* @@ -1883,7 +1872,7 @@ static int __init vmballoon_init(void) error = vmballoon_register_shrinker(&balloon); if (error) - goto fail; + return error; /* * Initialization of compaction must be done after the call to @@ -1905,9 +1894,6 @@ static int __init vmballoon_init(void) vmballoon_debugfs_init(&balloon); return 0; -fail: - vmballoon_unregister_shrinker(&balloon); - return error; } /* From patchwork Mon Sep 11 09:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379104 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 7997BEE57DF for ; Mon, 11 Sep 2023 09:49:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20DB76B0213; Mon, 11 Sep 2023 05:49:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BDAB6B0246; Mon, 11 Sep 2023 05:49:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AD286B0248; Mon, 11 Sep 2023 05:49:29 -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 F11FE6B0213 for ; Mon, 11 Sep 2023 05:49:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id CA5A4C02D9 for ; Mon, 11 Sep 2023 09:49:28 +0000 (UTC) X-FDA: 81223844016.17.1936A0F Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf01.hostedemail.com (Postfix) with ESMTP id EEBFD40009 for ; Mon, 11 Sep 2023 09:49:26 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GDdBf59D; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 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=1694425767; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=Vpi+wOnkmZWoLvldaarDjaC9Dv0jDj0ZKJJ0BNLsF0hTYKcN5x1fjmwdCE1FWHicgvjfdZ vdyenX2yR1oz1ENh89kfLNo4WYN0UuruV9yLNR8RPDRi0iWEhx4kaI5/cTPU/ZSltcsqjX icYk9RjfiSDlRotV/ZZOT03dnP8USyM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GDdBf59D; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425767; a=rsa-sha256; cv=none; b=AZUNwbaMzzVFUt/EkL380sqG3YzM2QNH2ku+Y/nOCIQ2oLHs9nyE0E7Oi152qIhh2XudXz HpoC++cV65NjU878fr/phUVMmMdrYryBv35UVzXIgeMSrOrLlWwy7pBZ4qYDrfiSACgJYM wi2HJNCCDbel+DQYjo18vAwlGWNV3qQ= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1c3c4eafe95so468395ad.1 for ; Mon, 11 Sep 2023 02:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425766; x=1695030566; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=GDdBf59DOGmk2Gtzgj23iH2o3ql82lXlogFzSTVczOXZQJcXW5ElCsqfh9f/n8sYop eS0HKAuJrrbjq67xWsfVN2DyT8UcLnQLn7zB782xgb4ZXGwFnTJf3ZTHa0uNpfLt7kwP hHA0fLs+NtHVRWwThXsHSM3mZ4tAJ6dHUPRrp0QYGyBBKtY6IENtGNOgb7qbUW731gme yLMbeYYQGwNHTNMLMSlAzfp4PbnLE8PcOog5PgkvyZp+2N29Zyn6aciUPx0Dte4g1Mra 4RQjlY0NkJ0qJLHsQyFnij0Po8jRp00HJnaWQJ8czAWps3+bMcPLNIVosUWWKvy2sj0z Jk5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425766; x=1695030566; 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=EOFLy8aeJhd3LY/OhniqtUCJXkFQlNJLK1Gu0rv7etI=; b=W7mMm0pgPk/jqpHSQwVGOX1VNRf3vs7W24dzdxHQKzRxSalR1Z1O+Yx5HkDuH4j5U4 nesn/ldmJZphfcBkSpmIXdp7sBzpBcOxjBgf3yHZGSxl9nsFm3Igl8pVlv0793lhK3hP PEPO3SdLqQohxj78BaC7l6bmz/04k0BtREmzUgbO1L07dc+leRpMZwA6YDDI6HqT4kSz 8WXHVpJ9YnLscnLyVdL0RpjJrZzwnRzX6Z85KwQSy5DOxkLzEtSDtZd1XVDFTqt6fR4l 1t7HvzTf/NwgcFcMhn9EXR2EZJPIW7zrjpr9kjrJ3XR1b4bOnC1N9cnymNH/ulS3skKx XDTg== X-Gm-Message-State: AOJu0YxNXO8p1qptw3+ZNoIHgIe79AbxiZtnel3H1IKA1k02NjjBL4Xb WtpBDbWhidjeWWcIObWT7B4XtQ== X-Google-Smtp-Source: AGHT+IFDkXMADJzJ5jjUq9PfJV9F8/TFu1J7WhBiuuPnpwyRrr8PIbDWnsDRVAoYbT3X6OqKjBwp8A== X-Received: by 2002:a17:90a:6d26:b0:26b:5fad:e71c with SMTP id z35-20020a17090a6d2600b0026b5fade71cmr8202972pjj.2.1694425765927; Mon, 11 Sep 2023 02:49:25 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49: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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org Subject: [PATCH v6 28/45] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Mon, 11 Sep 2023 17:44:27 +0800 Message-Id: <20230911094444.68966-29-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: EEBFD40009 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: iiega8c7myh9zaxidenjrkp18w8oujyo X-HE-Tag: 1694425766-486795 X-HE-Meta: U2FsdGVkX188AMgtZtE5M0BeZnrE0rOqNWLdOc9tHbjBh2CNhOJQkDREsspFmhmjjA8ql9XQQUk1dKKurvAf4r0Ucta68cuseiYWROi1X4+8mavO2MKtLGZy54DcrsvgUcLrfIBy3coe95SoioHowJYkMPAvo/D+ySJz/tz4c4HfHCVpLKLrRYxqCrNv8muTyr4gGSvcVl284or14DXIHIM1JDjTevPsG0D+f2x9Qg7bgx6YJgtkskDvzXBuBjUV+SKpengxmf+zLo9bVqypqfhelo/SdqUK9QHbbQ4XzmbZ4fTtRGiMwTyionRfe8zzxIKzk/Q9TmM/lE3d5QQeEk1qKXJ8r55HU1170qxY8A6GUx0J7AApokMOSY0HCexuSKq5merM9y1R9+92bME/I0NJgE3R435beJKjB8ZTEytn6lCHbc7Z8B/HtwA9+1ia9RWhfWk+R3NeGq6WH9UWbDYgle2PYvl1jehVk87ss7P5bPGY+e2OoXz9F7jb37d4TG8mK+RvxLPi7zqSTNGIjiVzn8DZ3VYzJHufKxVrhXgPfgg/MbFyxwz5b5B08WjLGuQ4D6hWvhkv55P3Ob+aOstk4WNOB2V8ZAAbDWJGheknbMq88MMVoeAWmlkL3rSc0x/QbQ7jtZTC4xZi4k85nJUsNr3rK6X2TGl4F12z8+qT90xMTZ97mhiDYXNXt7qJsY1Gu7d36xj+37a+XBM2zpjHpnANARmBTasEz9kweN+2wmVmHiXBj1yhf7zyI7jZlaArP2B0jSLPM2K/cHOnMBmA3yXWDcO2YTyEsnOADWTvEbsqnNOSJy/7FH2nLwc7eQ5pRWe9+U3P4n3g4gfB7JRrWqLQNfm3jBJYtwYlfFAyNkNLHRQN58hNmV9Xpz/ThXREvGvjmZAd+yzx/v+AnNFjPrgHrNwoQRB/Zn9vruZyiA2sJBdm5T29cGZv7N6hB5JW+JKHGzeVA3nhV63 giS1lgAe Wk4eu07Wskc4yQUZJDWYegaiOukzd6cSUzV49Xjv29EMuW/fwWm2hdkr6I+Ra293HORtJ+zPyF7ds1gBoaMJW+Bpb0SZevMftrYnyKnXpDUsxrD7uHUFoTnUtXA+Xw+NkO+ox4gxpk70dwJQ676iqBQENpI2fSLGIhyqbTPZ2pT4fFu3RO9F+ZExQaegkD7YoEjjwahpDFlRoD2cU9UuU06Wahvj1QrX6FquJohH8kzo+veAqqBKgz2aKMhNRZoHVYEv4fKuqhM3Evl8tEJJwrZnEzVRTfDbmijXLKsYnnMHQRABiOS0EfR1/Nnc+W/FAcxac5ki9REAdTrzqiDAWCoteRt8usspc1a9xPv+m3xqn1f8nlOujI1lOMdVE2S2is6Zz0ye53oAn6JcoalRjj79xZyq6S67P33PjDhyYuTtJ/mLia5T4g+48tZAHtIeUKM+DV1SlB+axXi3KpV71rZXFBDEbc4UwZY8P2ncrHj44i/+YLG1YhE+GjN2FXKcGpUiADEG9tuOV1/JCsTlpm+MXpdx+qbQsCoU5HlGYvco/dV1++IeZYwCpGHomQlVcAoI2 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 virtio-balloon 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 virtio_balloon. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: "Michael S. Tsirkin" CC: David Hildenbrand CC: Jason Wang CC: Xuan Zhuo CC: virtualization@lists.linux-foundation.org --- drivers/virtio/virtio_balloon.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 5b15936a5214..5cdc7b081baa 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -111,7 +111,7 @@ struct virtio_balloon { struct virtio_balloon_stat stats[VIRTIO_BALLOON_S_NR]; /* Shrinker to return free pages - VIRTIO_BALLOON_F_FREE_PAGE_HINT */ - struct shrinker shrinker; + struct shrinker *shrinker; /* OOM notifier to deflate on OOM - VIRTIO_BALLOON_F_DEFLATE_ON_OOM */ struct notifier_block oom_nb; @@ -816,8 +816,7 @@ static unsigned long shrink_free_pages(struct virtio_balloon *vb, static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return shrink_free_pages(vb, sc->nr_to_scan); } @@ -825,8 +824,7 @@ static unsigned long virtio_balloon_shrinker_scan(struct shrinker *shrinker, static unsigned long virtio_balloon_shrinker_count(struct shrinker *shrinker, struct shrink_control *sc) { - struct virtio_balloon *vb = container_of(shrinker, - struct virtio_balloon, shrinker); + struct virtio_balloon *vb = shrinker->private_data; return vb->num_free_page_blocks * VIRTIO_BALLOON_HINT_BLOCK_PAGES; } @@ -847,16 +845,22 @@ static int virtio_balloon_oom_notify(struct notifier_block *nb, static void virtio_balloon_unregister_shrinker(struct virtio_balloon *vb) { - unregister_shrinker(&vb->shrinker); + shrinker_free(vb->shrinker); } static int virtio_balloon_register_shrinker(struct virtio_balloon *vb) { - vb->shrinker.scan_objects = virtio_balloon_shrinker_scan; - vb->shrinker.count_objects = virtio_balloon_shrinker_count; - vb->shrinker.seeks = DEFAULT_SEEKS; + vb->shrinker = shrinker_alloc(0, "virtio-balloon"); + if (!vb->shrinker) + return -ENOMEM; - return register_shrinker(&vb->shrinker, "virtio-balloon"); + vb->shrinker->scan_objects = virtio_balloon_shrinker_scan; + vb->shrinker->count_objects = virtio_balloon_shrinker_count; + vb->shrinker->private_data = vb; + + shrinker_register(vb->shrinker); + + return 0; } static int virtballoon_probe(struct virtio_device *vdev) From patchwork Mon Sep 11 09:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379105 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 1E10CEE7FF4 for ; Mon, 11 Sep 2023 09:49:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B83DE6B0248; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B342B6B0249; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FC3E6B024A; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9067F6B0248 for ; Mon, 11 Sep 2023 05:49:38 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 67189B3993 for ; Mon, 11 Sep 2023 09:49:38 +0000 (UTC) X-FDA: 81223844436.13.BD10B47 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf23.hostedemail.com (Postfix) with ESMTP id A7616140022 for ; Mon, 11 Sep 2023 09:49:35 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=J6QrfXv0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 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=1694425775; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=s3WdlEz9A8r2eLqIECtLyv3xafm5iK0E/pdvpC0WQ+8ejMQjrwjESy8TFJ0Tufi+sTpJt7 nnELEbgCP05sIb5+i6sXKCyNl88C0cJT30qcvIbYpD/K/rqCKdx6RQfHw4xLLCfPx0MOyH M/3Nx99GfyiZA7WbrhnidEq/BwmOT18= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=J6QrfXv0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425775; a=rsa-sha256; cv=none; b=bSIp84BFdDt0zzKI9DmFsOXCywMfwuhgC0JJZLkVC622sNkof2TzVJTA2ZhsRRRvF08qeL oEvJOgKinzCLYugMRF1FvPrtU3ZpkaYYmJJhhgWWHDSvu4MhImJpVWdkYTrNmkbVv/U15g t73oZ4pHK6B/e8KSTzIIzb/eF/tmDIg= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso7703515ad.1 for ; Mon, 11 Sep 2023 02:49:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425774; x=1695030574; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=J6QrfXv0j8aBrICn8leuggz+7hg0w/wifEzmIFRI9nUBFWjix6XaycAU0An7ETRLsX K5hGAXz9cUS7JuUwRv/Ua/S8K94ElsZB3nmqLxDbVudQ+ei/YVY2PMal0tdGNNtoKSdR RkB6ZeIb57RHzDndz2MzLpunPtwkcGUDZflw1AFWHnWFLGQl2+iwjiZiw5FlZWMxDKNo MFiMNNGcUxRCJaYeqqXEZCZdua/4NP8L8/INBVuAP7F/VWizirBSsWQXsVoWer8GxjNh UxMuraLcQKRdlFvJMsSkQSnKasN0J/VGtk0xqFARoWM8M8MJu8uXy37Wvr4AKb6mA7Ds DXfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425774; x=1695030574; 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=CtzA3GFH4NUmzMiy9OwB7HPEUi8j2KPzX996I7+AsIY=; b=JuuCp2Ylvp4fUL2Dmuf/ev8UI2OgrpE969L49P39nPh51PhnbfCbcnUxTuC/Lw2g3b WQjzabgS/1ziCxIzq7LCabSqQWr3izNxyw30esI9vBSbOoJAW2pEASzunNqHt99cZw3N Hbbqow0E1QYmuz509OM0wf25kvgaunKuf8cj2EZ9xEbg4a8kC5S4AloK3Yi9yfvuoUgv EinDWBNUCCqZbOzjnHGTTYrDVzy3+9s0SSLQygeG3d30V8ybjW56NmqRIBexy2FkYOaI /I00xeXeQl+rcDpISKux6iOZghhwHF3n9DsQbn8jg7wjndf99jRKAL3nqOB6r+BeohWu kfkg== X-Gm-Message-State: AOJu0YzYEGvdHWqeJcDWP3Ov+gNBei8qhSct328HWTBCa6U0A18uJkHf oxmLnuRn5XKqjjwHnaYH2/01ug== X-Google-Smtp-Source: AGHT+IGPH5rXG2DhyxB6chvRHKVjx+5Bo9SHNmAMgS3dYgtQNb6hmClqPMLOMBQwFJcONSVD+tzP0w== X-Received: by 2002:a17:903:2448:b0:1c1:ee23:bb75 with SMTP id l8-20020a170903244800b001c1ee23bb75mr10949821pls.1.1694425774641; Mon, 11 Sep 2023 02:49:34 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:34 -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 , Alexander Viro Subject: [PATCH v6 29/45] mbcache: dynamically allocate the mbcache shrinker Date: Mon, 11 Sep 2023 17:44:28 +0800 Message-Id: <20230911094444.68966-30-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A7616140022 X-Stat-Signature: rrn3siac1i6p9d14csza9hsx7x5cd5x1 X-HE-Tag: 1694425775-329227 X-HE-Meta: U2FsdGVkX19awBfYW9V5nxUlBoRfgVnUdry2zdvarWoK8MlXjzVLgAirwiQLAr+5UWXPjDu72n3JfVnBIG8YyJk4ueryExggWHt/Oe1fv7rFsDacMSVt+p8m0f8kxeBHtBcmZUlE9Ldpd0XhvzDhdVP/0lTjkFAflwyNpblzO9F1xbhP4LkxNFDDeguYgOXzOfQ1hgWqCZLNsK6KgRuoXpq3kZEFLY35u318dee0nXp0G9mTK61pH5XwvZLKfWnhxOWn8g0gzD4S3obkJD3UBfsKsTDeTMT7UZUYXWe6NJbDW/3NNiIcnZdAhdKI1P9KlgTTP8DiVaD7JOrubUonJvtaiAaZqFUOtrfC+Zzd2ANgAyo8ee6NRuUNRqJlIIz1JgJ5Dc4E3Shu+B009umR5twVMlO3Ns0+cWwxV5uJk5IhWk5qMR68AVFLzowTYxBD9phVzO/sYZaB++emrHHuOwFGRZokDAXDVovWAXvlZ5DS+WvPXsxZkgNoERlf+Emb5a4KCkEBcqaPDqWmYI6Kgp1CKq7WmUlOhIxGcuoeXwSh8M/7LqP30umW+a/WkswfANUTgT4Lis6q9Jr0283wYA+N+Xs4mhlxFW1c4/TRXBLDtvcu2TYu0qC6JvaQHRFB6b6yDQHiBBbMmkbkYB61vxMZvnKgNnXVYo+AStyWCWrAGLAtVxEss/UxkZW6scmVF6+8OmGJ/HCEtzU/dVz4ft00z/lBO+K2z4klLJurRJaNdubK34OEdYRa97Mj5ij75fwPHNXCc46pi2h310mUduMbwqrEC1domL7Lxib0gzVkacHnGUpyUch3kzDeLsOtt9M+QNAj+xq1Hh8gBfK1ik0DRRMFTLPVtcgziSIcj8+rIytFoBRoJtdheH6yypopEXCJtkBSh8aNh+xcyyzg4g6JkbDke6tkyaXXjrunUbkr3SSWzhgmdkVUsetKe0vPvq5Vq6Y9tgWEaxkLR6S UnwpTK8A t8PlqtZjJGm25utGpwr9ZFhVPtQvGOOq5KdJ4MR7xOUcI9UMEfNVXTEdVFaRDI++/j53sowr/IlqE2IYF4CiLNafjudUzDhN4Fc5p2v6Wj/Qkbc831+V8sfMQ3AYKbFNlbGoPeQWfIJ6K1d808qOa/CTw2/1aCVrnR8k6mZQoQgzhFpgsS1+5dV5UhIjyDips9FjAxjxP6XAzdrmxwAfj5fSOKOY1YWlX+Zq9Euu+30ppkd/SpIPDAz8fSf+mf18r5u65bdrQ9AZ10HR4SUB/iITN519HqAj+e8Y5SLgvkSeyMy02FuiPNh5axXaY11XVdtHHpGPhowbybsWq+oNi1kwvZUeuO/cY1DQ2m0zcATR+WZ4ouGo67VrHyuxQ7NfvH3sag1598IlROG8MLiwZ4vuOtWH4p+01oAEQoY/RwwmGWiduF/hJTtAjFbF1jmMg1nKwZvH6ymQHlMCnAEXL/LQ1h2F2sr7r4mNW4laYqmddS7XeX452xj5htbCfW+TYtIdD1dXAePbxFSOT75fYS1CBLg== 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 mbcache 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 mb_cache. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Alexander Viro CC: Christian Brauner --- fs/mbcache.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..82aa7a35db26 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c @@ -37,7 +37,7 @@ struct mb_cache { struct list_head c_list; /* Number of entries in cache */ unsigned long c_entry_count; - struct shrinker c_shrink; + struct shrinker *c_shrink; /* Work for shrinking when the cache has too many entries */ struct work_struct c_shrink_work; }; @@ -293,8 +293,7 @@ EXPORT_SYMBOL(mb_cache_entry_touch); static unsigned long mb_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return cache->c_entry_count; } @@ -333,8 +332,7 @@ static unsigned long mb_cache_shrink(struct mb_cache *cache, static unsigned long mb_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct mb_cache *cache = container_of(shrink, struct mb_cache, - c_shrink); + struct mb_cache *cache = shrink->private_data; return mb_cache_shrink(cache, sc->nr_to_scan); } @@ -377,15 +375,19 @@ struct mb_cache *mb_cache_create(int bucket_bits) for (i = 0; i < bucket_count; i++) INIT_HLIST_BL_HEAD(&cache->c_hash[i]); - cache->c_shrink.count_objects = mb_cache_count; - cache->c_shrink.scan_objects = mb_cache_scan; - cache->c_shrink.seeks = DEFAULT_SEEKS; - if (register_shrinker(&cache->c_shrink, "mbcache-shrinker")) { + cache->c_shrink = shrinker_alloc(0, "mbcache-shrinker"); + if (!cache->c_shrink) { kfree(cache->c_hash); kfree(cache); goto err_out; } + cache->c_shrink->count_objects = mb_cache_count; + cache->c_shrink->scan_objects = mb_cache_scan; + cache->c_shrink->private_data = cache; + + shrinker_register(cache->c_shrink); + INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); return cache; @@ -406,7 +408,7 @@ void mb_cache_destroy(struct mb_cache *cache) { struct mb_cache_entry *entry, *next; - unregister_shrinker(&cache->c_shrink); + shrinker_free(cache->c_shrink); /* * We don't bother with any locking. Cache must not be used at this From patchwork Mon Sep 11 09:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379106 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 444CFEE7FF4 for ; Mon, 11 Sep 2023 09:49:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCDF96B024A; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7E316B024B; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C463D6B024C; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B39466B024A for ; Mon, 11 Sep 2023 05:49:46 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8D85C1A0902 for ; Mon, 11 Sep 2023 09:49:46 +0000 (UTC) X-FDA: 81223844772.15.4CB204B Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf08.hostedemail.com (Postfix) with ESMTP id A769316001B for ; Mon, 11 Sep 2023 09:49:44 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EPNSA7iK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 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=1694425784; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=f3Il6vRyXdfK6MCl2yrcJ6yMk95fVtzD6pfrlrFOHcKg6D1+BfzkoefDCOBYz9vBmQJ/N6 a8n7zREBMCEfEb2FKTwzzig4dgCEdag2x9Kg8tO9+NHpk17s4MtW9+7iV97dCU0KMp+CBK IxEtxsw2lOaGIPnyDKUHu1x2nQW3vaY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=EPNSA7iK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425784; a=rsa-sha256; cv=none; b=8MyCNqjX3b/cxpj9EaKq8LaqJfwDhLv/eQS/NHoFP8IYt3WzKxa6jDcePsQ1NIpPQ2Ke/s TLvDJGaWAVB71GyQdtMep72DCZ0rQAMbExxdXjiQUnOmv85zjxo66MGHY5ukNTLTJt3+Qi 9W771AV7x2HdsuifzZ9+Oj80Qo8Nu4A= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1c3c4eafe95so468845ad.1 for ; Mon, 11 Sep 2023 02:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425783; x=1695030583; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=EPNSA7iKJPAIlzZCSmjh4aNN189BhfFREiSD88wKXqXuC1YsGjf46/8ep1V+OzfQqH de7Y/TA8l/VqsS1lbqSa5R4SC6Bvp+TgGcRVLp/5CyTasEnChYZ/TZAbZt6vYmDYSDEq r/zD0/3es7Vo4nrD6enoEiVJctgmsrfTpJyQAdz04iqfkvKrgO80yEXFTY9coLC6fLJW PawzhHlRyiFxmvBp/Llnk3ahM4G7WQnoE2eqdyLkzY/mR3O4eFMA+y39Yl4NazPkrM2j w/shCiKvG7PX142DZuBEUpW88O86QHcbxtj8Fs2yo15/wS80BTSTBxl5sckrNJWnX8O7 SVYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425783; x=1695030583; 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=Jp6alE9W8p4SLI20jnJ2OSu/Y8SjbH33H7WP/Pdn6m8=; b=uj9BPP0fQWGp+OvnLG8zkIl0T5bFI1Mm/F0gucQmVgC4r+W/7gh6SUtFI+eZb1bE1j ejfeiia/U8CW48QyKAFjhJ/JfktDv38nnfgs8Tv9yb5uF6FmSTX4p70BNPasaNBOr9H6 c/0qh1l8oiHHdu+kaaiMt8xQeE+0RLIziFDSFv78VUfPWCCT/br3CFxRIuL+CrzWJWo4 OCVdooXkLo6vJ8aW00jJaMSQDpamaYp++usJPYdOQnhGxJqsVjDJG+FhI2bPZbydR3QR U1XxrYALgk+DwJR7C0nCFt0FRf50AcPMdoGJ6YwJt18SSefKWzVtSRL1H8qvvQAV6hum 5RwA== X-Gm-Message-State: AOJu0YyDwlPNaL+YlY5iR8ectpPUKWhXnj/TLJVpzgRrMG92U4FkvXw6 JPzsjQ4M890O2mwBSSKK/dGqpw== X-Google-Smtp-Source: AGHT+IEjw6f3kkK4YeAJ1yQh6xNTwLMG2bfCuz4XubHO4qI41qrhKwsBTZY5Hpn7PFnzgf8StICGRQ== X-Received: by 2002:a17:902:d645:b0:1c3:c687:478a with SMTP id y5-20020a170902d64500b001c3c687478amr331484plh.2.1694425783678; Mon, 11 Sep 2023 02:49:43 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:43 -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 , Andreas Dilger , linux-ext4@vger.kernel.org Subject: [PATCH v6 30/45] ext4: dynamically allocate the ext4-es shrinker Date: Mon, 11 Sep 2023 17:44:29 +0800 Message-Id: <20230911094444.68966-31-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-Server: rspam09 X-Rspamd-Queue-Id: A769316001B X-Stat-Signature: ppgto8p5isi8mqfntoaiwgn8u59xjjgc X-Rspam-User: X-HE-Tag: 1694425784-242409 X-HE-Meta: U2FsdGVkX1/tmc8ZvYy0VKAuwaomDgy+mB89+EnFGJnPfwY3nh/g/i+ddQIFqI29l8HSO68oH/2EpklOKx+WQhDgVv4NoW/16ef2Iz5ghJlkkcaUcLXCOMX3x5aCjbRvmCVtwSMJqvISDGoj346j7PCZKXyB/5NPd821xgvhLkj67aqvOFvDoGR9X8Oe49NZmcjkDgintxJEzFjXeoAkEWyvjIHN42zzOZcvHMxKFn9atBgVSt1MT+GTM2RuEveasEGq0Q5uxxhDCvRFGKjnvwOSbSJdpxWp4Drzj1wI+qM8tkuMkJIidvEJy03jIkXEhH5wWg4lRX+JilTUejvytgxJDXsLWP1v2qPEdstWKGzWn1aBpGoQ0n+2gyUT117pLY5a5tZ7dh+w8tK/BzKT7l2LaY64LvKliMkoA3FsvX74ax3o2jXVOR0/IXEcmL6U5qhRtZ9uJX1O2GxwRkbtNA9plIsdewjAdGvoKbX0kah9JZClKpeeIsq+91lx+xaN5Q5TgrEaA+AqOVQgf1SApnoaM3yZS7+vybGtd6swTnmcUpXkWa5iJ0NMjBDHLgEKQxo2VVVA2XfDpoU72d+DlXI5Z7Ik1j6auZR94dJsoBSeCUmJzA2RYWrsRUkhHnBuT03MWtOVEx2Ir2eViHecbgF4S+5bfahRSrTm0see5bpNTHpXWMYcE2VjGwDqyqw+dKnvEoeWkNfnuPDjObhIcyz09iO6VXsQX2Szs6C29UqESY9kyrjEiu9n4chQspzt8iilTq572yR8jXP1VTZEHSkfsqw2rkttA4SzP3wJ5hZzI0fWG++MQKpurhL+4GfhHryNG/dCIEMwCGg+syU9yx6BYhdPrK2xt4OOxaEDAmjAuf8b2WEK7CjyYNNZWFtVdSqAxLo9yahfRkfrXgt3YdOYFm2W4QzgLxwONqdphnrsRJDS8h2Rx9HZhUg8ErYw7QUry+36e5/q/fCeXvW tblZauEK zg8U5JAEGFecrPwosMdgYgEcPNb1emghblGjdnrvhHn9df4VVboBE4MldfHGmt/eUbuP7qTIFa4Z/A9Pit5JR6b2qwcTeviCnTx9QpWGagHUx/8ImUvPOF1bL8lGQRdAtNM7SPmQJdsf8Omnp9QUhEMRo/zG/pXnaisx3QYrsGlts4JbmXclIDJqLy7ryIRaZNKwjAzWfUDDlQfXCL6W1+V+G+LJXRQWc+MGdwgPHrwanDS4R9hb1FyMllki1DdYweVn1YqslyuOEgcOCEq1/vO8t5ngRS+n9Y7FSZg9cZnqAtbMpoytHzSqNefNkImC9ykRimCoAOSCoZ2g0+LwZ/KtV/D/KPU/PhNUzil6CUbDGG8qA9upbznwfsciSRxfO06LFNq3mZHumIbz7fZFVVhiMNu4Bi9S0PlsODxePg961eyBDAVfsCtYwJmbAXm04tz3BeMPd0rtPozwcgM92t4V4KR/T4psdmugWMkmFGCzL3OseB74++PKi1aQq5J8TtAX/j33vM/2Dm6PA0ZX4l8/gJw== 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 ext4-es 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 ext4_sb_info. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: "Theodore Ts'o" CC: Andreas Dilger CC: linux-ext4@vger.kernel.org --- fs/ext4/ext4.h | 2 +- fs/ext4/extents_status.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9418359b1d9d..8eeff770992c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1653,7 +1653,7 @@ struct ext4_sb_info { __u32 s_csum_seed; /* Reclaim extents from extent status tree */ - struct shrinker s_es_shrinker; + struct shrinker *s_es_shrinker; struct list_head s_es_list; /* List of inodes with reclaimable extents */ long s_es_nr_inode; struct ext4_es_stats s_es_stats; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 6f7de14c0fa8..deec7d1f4e50 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1606,7 +1606,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, unsigned long nr; struct ext4_sb_info *sbi; - sbi = container_of(shrink, struct ext4_sb_info, s_es_shrinker); + sbi = shrink->private_data; nr = percpu_counter_read_positive(&sbi->s_es_stats.es_stats_shk_cnt); trace_ext4_es_shrink_count(sbi->s_sb, sc->nr_to_scan, nr); return nr; @@ -1615,8 +1615,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, static unsigned long ext4_es_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct ext4_sb_info *sbi = container_of(shrink, - struct ext4_sb_info, s_es_shrinker); + struct ext4_sb_info *sbi = shrink->private_data; int nr_to_scan = sc->nr_to_scan; int ret, nr_shrunk; @@ -1700,13 +1699,17 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) if (err) goto err3; - sbi->s_es_shrinker.scan_objects = ext4_es_scan; - sbi->s_es_shrinker.count_objects = ext4_es_count; - sbi->s_es_shrinker.seeks = DEFAULT_SEEKS; - err = register_shrinker(&sbi->s_es_shrinker, "ext4-es:%s", - sbi->s_sb->s_id); - if (err) + sbi->s_es_shrinker = shrinker_alloc(0, "ext4-es:%s", sbi->s_sb->s_id); + if (!sbi->s_es_shrinker) { + err = -ENOMEM; goto err4; + } + + sbi->s_es_shrinker->scan_objects = ext4_es_scan; + sbi->s_es_shrinker->count_objects = ext4_es_count; + sbi->s_es_shrinker->private_data = sbi; + + shrinker_register(sbi->s_es_shrinker); return 0; err4: @@ -1726,7 +1729,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); - unregister_shrinker(&sbi->s_es_shrinker); + shrinker_free(sbi->s_es_shrinker); } /* From patchwork Mon Sep 11 09:44:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379107 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 4FCB0EE57DF for ; Mon, 11 Sep 2023 09:49:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6A286B024C; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E1AB26B024D; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE28D6B024E; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C05336B024C for ; Mon, 11 Sep 2023 05:49:55 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A51B0A0951 for ; Mon, 11 Sep 2023 09:49:55 +0000 (UTC) X-FDA: 81223845150.13.0AFC3AF Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf24.hostedemail.com (Postfix) with ESMTP id D15D0180012 for ; Mon, 11 Sep 2023 09:49:53 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dy7fH+AA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 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=1694425793; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=6u0Xs5USg/iacZIUvF49YMoLVAfdp1brHV2stllQh7da6he5olhpPa5wo81Bu7u6Zfmoax i6KDkwwuaGok2AovifFJFXX3GESHjYC/pFMVZvdDrrpzK1ohMVFFHXWrrhE+5PhPAkDTPi PsphVKsZvAJl1faGgTUxaYA+ofCozZM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dy7fH+AA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425793; a=rsa-sha256; cv=none; b=jbBiU9nxKVrcdMA/bD+kHvbsarICNeQJz+VfgnU8LNhmQTLxJIy7exJxiiiCRpx+RUtNMz 1IIyiHxbtKMBFccV7Si3CSF/o4I/RmxWMSVx760KmHNaRgiHunEdUkgOYmAZRxyhc8naY8 mldwi68xztk764gU1qdy+IRajz7SYRc= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1befe39630bso9368855ad.0 for ; Mon, 11 Sep 2023 02:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425793; x=1695030593; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=dy7fH+AAyfnS3G46hkXwzVFLtSNmJGuE1tNjOhO7jQogD62tsEv5v7q7Tq68cFvUtc Q4K4jv68JxsD59ytGcDP2cuiyv6cUk2t4bZQNAdowlmNBpz+NJ1Stm1jUfCgBAzlYykm 2PVFdOiSTM2OUMdr3YdkFIHeU04+kzKR1+eLzIQC5t2nhpzG42gEECNJzSrBkIqV/QZx 0GxQ5gdAhsomgHrDLc8P8WyN34yjfK+dIzHfT9Gg9RsbVFp10p7VfeRze9y6WwxrRDAY X0BRb/j/tAQ/HbA7eMnWOdfgYEeVagvblWyJ+FmLO5VeGR+ZwdRFm9HsdNSW2ZQ2yVuI 6chQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425793; x=1695030593; 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=vZpBnX4Z9eqEuCcIq983vZteHkZX7uUM6cDHYd9irL8=; b=xCzUPnS8/m/r17MljQfccJbxysV5NJ5iWUm+BASHIkzSLeciXUzzkVNPbUETbmo20G W36GiZh35ei9utvbLeoPvxNVG4Ji8rf/Ojv5icICZoZ6/4PNLfQMF8w4p/v0pO62OVgM VJ8oS/Jivg26RS165+puRnni6pfbQDYt4P3r3LZkj6W/4IGabP5igcn95TF/65eadhwt yx6y0ruV44EeDqh6wronimJyhqcNlTocbdwAs/68vlYbzMYPEynAYuhOFxBEgceUgsqh l3h2G1kubkbLM41fwTLNHxOZkeSUv5arLqy68GNGT1k2F9dEZ20Kc6mrjh1tzJsr/ZKc 9zAA== X-Gm-Message-State: AOJu0YwpV4j3MaTZ1iB5miNQkZ2mouLwyTkfw7L/OyKF3DKlggiIvcfE BSm7dk4TK/GbmXsqHkbvZD/T1Q== X-Google-Smtp-Source: AGHT+IFvqXY+jnOST4BZIc6AyFCejSJWSQ6rLQGam1YrCI9mLJF9ktChTLGkYjxBiW6SC49Zt3tINQ== X-Received: by 2002:a17:902:ced1:b0:1b8:a469:53d8 with SMTP id d17-20020a170902ced100b001b8a46953d8mr11187928plg.0.1694425792768; Mon, 11 Sep 2023 02:49:52 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:49:52 -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 , Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v6 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Mon, 11 Sep 2023 17:44:30 +0800 Message-Id: <20230911094444.68966-32-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-Server: rspam09 X-Rspamd-Queue-Id: D15D0180012 X-Stat-Signature: x4s558iannzghzoj9ppe6f9954dp9eps X-Rspam-User: X-HE-Tag: 1694425793-991989 X-HE-Meta: U2FsdGVkX1+j5l1jqwh6+mYSHRhJh70uFgBspNhatyYUrRDyra09OyqqRVDwz1ODLTCdOiI3pWtMsqnA8ynNQ4ritxB7yFjg3mR+bCHzKqgGTCwWOZwdS1cbmKrAct4acXBsN/X5I/xrzhuY/hl6CCC8YX0ojD5z8wPO1QTuxXW4pESNa5htmycgNW4smgMOwTbZxWQbAVR6OObpKgcKEnlS0StEiT8G5jmiSu6INhDazprhiWYchb7KjZdZMjuG0QCiCBsOEtRpXXh20bTks04O2JTOm1qm31Vos3oab9/y2HcpMeGb/STOAG2eH/CK4htUmEe6EHgpT4TVNeLOyRNLB8bHOtyDhaSXN0JQvDx0zkggmWYJOCx293fDAkbitKYuI9kBD5dKVfM+1Vo5O7PJH0s9yte8CnrxYp2USxFzuuBU6KCdTEYUxyWFTV//R/H9mBt7FsCaCAhScXnISor80P4JAR9AtwVKpwBvwztp5I4uNAc8anxcmcsG/z5v4KOJD9Mbw8ci5VFobxOqKoSngNezenojkCYIA04uul9Vgxr5qtIYOJVhxnN1esfFuAKOr8oihje8io91CDcxqLoI9r1dAsAMNe9Y8WfAMAJTSeo9OeLmZTAArlgKMVLROyUqsf9MGeVFpkgT7tyOb6K9N9btch5RPctGezs67I389bDbq6d22KFtVa3/8Xhi1Q9QSUpoKGnR3ZynWGYqonhDe4mzF5NYaVBjDTvNdxDsgOgw6lzt8e2KPE2ZaA+tlGhkIN9ZRI4JLPzSr7GHk/NmPRxc0pOTNs+R/jUiwfEIpaGB5WFN9WC+dSHmBMGLw8T3IjM4Wse0nr0nyYQMimvRuz36v/nhlbPmSkf5cvQPOvGOcKay3F4ORMXrdc+kEc9hiZhFkjFwHGXvQjOejUedPfwYAtfoid4Fj/FwO0vg71/eRi3Ul2IHFk+Xo4WL0rs+KJspWMtKJvUDNR+ SA/iZWMr 9Ktj86vOIX6GITXzy4iD32aURDtFv8ldH4ps0k09GouwHz/oaby3pkaBZN1cMwJ/FRUjlcBM/CjHtAQG8m8pbeibSyVSpliWseSWdypmL9jrJXjpWCaio1WpHlTn+KkSUTxU2HnqvdGuxqaHeyX2uZCZEreGadxTWCO6oLYr5JeWeVlEHGaCD3xsanMkbLdXrXCymVWzRPeFx4btIfQMSvxLG/fkrPIvY/g8ELmYO8+KayA/KCvWEZ7tG2x1TwxTQzCKmsmegxz/3Nd8wX37vLunrfMF4w7NAbUgBAW7j9XjfKd9UTuoHPhZypQ7AdQzeLjzGrnsQb9WukteiNG6ma68O25mV/gbE++xW2TTBIwu/mHIxh3Y38HXZF/rSO0AhOhBPhOU2Z5bPHD2UB30yhvHWw20xo71UvhuyyRaaHWZTOGqIXwaQPAGD5E5hk/aD8dT1Yby9bFGlcuUSBkl3K6ySP+5oLWkiOHpX 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 jbd2-journal 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 journal_s. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Jan Kara CC: "Theodore Ts'o" CC: linux-ext4@vger.kernel.org --- fs/jbd2/journal.c | 29 ++++++++++++++++++----------- include/linux/jbd2.h | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 768fa05bcbed..0ae19d527b22 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1290,7 +1290,7 @@ static int jbd2_min_tag_size(void) static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long nr_to_scan = sc->nr_to_scan; unsigned long nr_shrunk; unsigned long count; @@ -1316,7 +1316,7 @@ static unsigned long jbd2_journal_shrink_scan(struct shrinker *shrink, static unsigned long jbd2_journal_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - journal_t *journal = container_of(shrink, journal_t, j_shrinker); + journal_t *journal = shrink->private_data; unsigned long count; count = percpu_counter_read_positive(&journal->j_checkpoint_jh_count); @@ -1588,14 +1588,21 @@ static journal_t *journal_init_common(struct block_device *bdev, goto err_cleanup; journal->j_shrink_transaction = NULL; - journal->j_shrinker.scan_objects = jbd2_journal_shrink_scan; - journal->j_shrinker.count_objects = jbd2_journal_shrink_count; - journal->j_shrinker.seeks = DEFAULT_SEEKS; - journal->j_shrinker.batch = journal->j_max_transaction_buffers; - err = register_shrinker(&journal->j_shrinker, "jbd2-journal:(%u:%u)", - MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); - if (err) + + journal->j_shrinker = shrinker_alloc(0, "jbd2-journal:(%u:%u)", + MAJOR(bdev->bd_dev), + MINOR(bdev->bd_dev)); + if (!journal->j_shrinker) { + err = -ENOMEM; goto err_cleanup; + } + + journal->j_shrinker->scan_objects = jbd2_journal_shrink_scan; + journal->j_shrinker->count_objects = jbd2_journal_shrink_count; + journal->j_shrinker->batch = journal->j_max_transaction_buffers; + journal->j_shrinker->private_data = journal; + + shrinker_register(journal->j_shrinker); return journal; @@ -2170,9 +2177,9 @@ int jbd2_journal_destroy(journal_t *journal) brelse(journal->j_sb_buffer); } - if (journal->j_shrinker.flags & SHRINKER_REGISTERED) { + if (journal->j_shrinker) { percpu_counter_destroy(&journal->j_checkpoint_jh_count); - unregister_shrinker(&journal->j_shrinker); + shrinker_free(journal->j_shrinker); } if (journal->j_proc_entry) jbd2_stats_proc_exit(journal); diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 52772c826c86..6dcbb4eb80fb 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -886,7 +886,7 @@ struct journal_s * Journal head shrinker, reclaim buffer's journal head which * has been written back. */ - struct shrinker j_shrinker; + struct shrinker *j_shrinker; /** * @j_checkpoint_jh_count: 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/VgYudQsnyhSQny6MeAKudbLdgkMsCmry6ftRFh9pVW6nbOmwbLl3QWH1etQhEwWMghr6Ym2llg/qEO5wbNNWBqmzjFlLqvyd2m4Ahruo+zWejkeHygyDsQPEE4pfDz4h31TgqwMz5auhjvv9HH6Pkfwr+Oxzs9TbtmqdVVtjroKcCfDDyQ32EhTqhKIRewLrmH2jbXPQooQMJUyHx1LdwpdeJfQ0kXCbLOJdg38notqpVmDQ4Oy2F1uPe1kVeX4yd2sfYNvIaVetXVpWzhWdKksc/2znoVdQJ+HKvcmakdMwFHW77SWEsCLylKkoaT7SWlzdBwgu9HOXglqRSE5pezUJHlmqwCaW5/g00nc+XUKHvkKgRgoweHVh+ua3UeV3hvBy6+FDWgYK6QTUBXOhtYk8kn/L4EOMEM8PWfx3vc9wS9fS+9fqXnesQd3ILnGAcFyrAkDtziy3j4GU16qvs/ZxphOPNHEbtGOZV51EQ1ePNj50VaePwrUFmVRFqCpB1SDGA33GEzwV8R38ZDLErY82POL+XwVE10BYeW0Xgms6P0OsJlaUKrs+gsGeonBEm+YlN/oBiSzYTu3tof8d9Dl54doDxggxTXR7CUFZ+efcTM5uTgWhrJyrdMbqP8Nlf6kWX9AmgYzebqnzsmH+BMxuaXpTTpRupqRGo1Y4GYHD6vqj64X4FUOQ9X+LWV3+8zY+RDcR7bAUqcEcZHSHszmXAcDwjdnEx1yGKZi8SJqPUPlxQzKl6OcVwDiPwjZxHO8zbAFteBi5kb3V2vxGPGz3mu2j9EEIb07YbAz8hYDsANNRKkO7 6jjdXx8W 4OhvT1HVGEcQUIPUnN3Xoxrb/ga0E68K3X/VL5vcce5YMIv0mjqlN1mwOUGevJW2nQZrQF7w6QpL6dakS4gUu1Co9ir3F/4L01aARazfV89VIsikO5ptVLliJ77PFRqbDcGg0KhCe0HRV3tTqr2YWwB17miCKlHSExtTLmWqWuD96h431+WxS4sXT9Ytrnfv3TbnBWtlJgyeoftbMjbX0qp1oyUXAjurfbXwN/4kXdd4CRa/8+Kdq+Rd2oAbKN5M4O84oWu3ERpPHwoLsDBtFmMWVXi3HOKqe5ryF1D0h0v0plG9V1CvSpbiKfCJR8bwjQX4w2GSYjUhOB9RvZS+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); From patchwork Mon Sep 11 09:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379109 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 7DEDAEE7FF4 for ; Mon, 11 Sep 2023 09:50:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 235BB6B0250; Mon, 11 Sep 2023 05:50:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E6296B0251; Mon, 11 Sep 2023 05:50:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AECB6B0252; Mon, 11 Sep 2023 05:50:15 -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 EE6496B0250 for ; Mon, 11 Sep 2023 05:50:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id CDC27B3698 for ; Mon, 11 Sep 2023 09:50:14 +0000 (UTC) X-FDA: 81223845948.07.D0C4E0A Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf08.hostedemail.com (Postfix) with ESMTP id E5C1E160018 for ; Mon, 11 Sep 2023 09:50:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jYQc0pCU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 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=1694425813; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=VBsXECHPgwKWzzBJ2kxVPjqqD9cDsZj7wTGZXCs+v76JzsR6+A6ElHYc9tehl7eQvQ/hUH ppIIgpfMhmZZ/yu2WeoggUP98yh4Sxs0sjlE4Fw/ZFXdqqgedRaGWAWO2R6x9xsPwcpC1+ njpP51E3KUn3mIrug/52OHqUwV6M/aA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jYQc0pCU; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425813; a=rsa-sha256; cv=none; b=qL0ELcqexH7Pb+EZxDcMsMbCnenWH5pb7V1VO3R5PDKI35KUWOLG5jV8n9Fm6xuTJBxjkj OI5jh70Ti51bNu0gltjqeCd0dQxGoqRZEVojWYTXsrA6iZnuMhqrl6HiqUAvbtF1rW3u43 vMUrM9sTG/IqNsvqspvVkjQ+KU0pxxQ= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1c3aa44c0faso1787875ad.1 for ; Mon, 11 Sep 2023 02:50:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425812; x=1695030612; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=jYQc0pCUu6vOcJ+DbnAUu4nw1Tg8jujvBC7VQIkRXJGDK8ERaf6oOGMx7RT+dzFNSV Yp+qvieSUcw4bRrqwWUibxmUaNwoTLqWKn47BitaO5lQ+tdBsCfQbWLoSZQ1Pa76TC0e MjtPNLzz/K9dtGtOn3FIqCgAj6CytEO9fYSUINf2c0jFeid3OBVo5LY3ysyhGm3AHkp6 zTXLrD/a4g/9qI4epN+mh3uqPQBrU28lWZAwVuW2ESOrFLm8BVSdwl0OU/UCWtDhUVFA rk5pLEW3tkwTtD/leZe2KdIHCHDIxBdSuBC6K/jZMjve54/Bs5BaHaa7g210HEDEVJzY 46Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425812; x=1695030612; 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=iZYFEziqHKQTs36ii9IxaHzQyRy7+HnptX1eUkyxsok=; b=dEE6W0Blq6a6PM7LLbK+rf51aHd7l9BZwsUD38BNUF8+h4oUs9X/dd7mW+atgZZBsR tyfRm2bcIGZrzPv1Il6IFG08yHg8U/dmxC8Xg7NKdnS8tes6J4eqewZ0CuQkfAj+tYRe EPsSmMTMGosvsIGrESbT8ssFsFfxnzglbXukuc9PfwPk3qIsvTc8l4J5vRhKlzRdT5bh 7gRa89tmKegFgZwK0eS4FVcoOdABMOnAmVmDv9z/PIHeu53VZfZ/CT9MvapPsY/0L1Ww eY7KENVqkLN4mU76ONEJ4h+D9B6J4PdJ0NCTVhMKrV4Lc7naglxd4ygPs+DjIjW03ikk Zg9w== X-Gm-Message-State: AOJu0Yx4jiuY+nsiFDdinYU1QE7ZM2TditaM0JFPzqcnIIAVrG8rnMTU Wltrz8bKTTka4gPQNTW/QkN3zQ== X-Google-Smtp-Source: AGHT+IFx01yGZSAgnlbIN2EmaqAGM45aSzdAGkHUGYMQpSItramkO401wN4MdrY4LUd5pZ7aoS8pCA== X-Received: by 2002:a17:902:e84c:b0:1bf:349f:b85c with SMTP id t12-20020a170902e84c00b001bf349fb85cmr11526001plg.1.1694425811998; Mon, 11 Sep 2023 02:50:11 -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.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:11 -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 , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v6 33/45] nfsd: dynamically allocate the nfsd-reply shrinker Date: Mon, 11 Sep 2023 17:44:32 +0800 Message-Id: <20230911094444.68966-34-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-Server: rspam09 X-Rspamd-Queue-Id: E5C1E160018 X-Stat-Signature: b3sxw7n74ifrzmrt16kab3wuwirbgdf7 X-Rspam-User: X-HE-Tag: 1694425812-530953 X-HE-Meta: U2FsdGVkX1+KzxvGdk8lMibPiz7AyenyYbNCw8YPcQsMZ5iu0x4HmJm5/boJDcKT1cQoVbPK2l1FyjFqUsee+dVS0DEv5J/I5hjZ5pLdXnEb+iBvRzTuo1/6O3XwfuEgCeD86QoIkSDZ8IlzdF4MVieKbcL1NCSkLFoR4D+FpTy0emlsy2mP/SF/yiXPsWXKPXcue6dFh/TOjeo3v+qpIEp0enHLrN2Tj9FotZkWbPC3gfUwzD9aH/a6I9Aer2Glw0RDWuxZQijoqd5S1MhLL+lRdNzNwvXBW0b6sWuNQxF5BV8tjCl1ITcLb9GnMwjO9NmbVy3+eEuD9h6iJ5VTFQlgrW7zmVmaIgQrr98Q07p2mkLKT36Ba2poNCmxTSJU97Cmhi0wUZzzK4yCd/KmJTKr1jOfF1iNw93AjuL0sqCXmWmacbu8000jBp2QVlKPMsUCm6B2ltZBu38IS8WQDjeUmL8TlTTPAj1JHHVavfoYIWYKVzfIbX0MgoaahkkjcS5/HI32fizRoeA6/xM85cb6hkmg6AXopRNGs2DkPix+4Eq/kMv2iS5IqcFgcWm2Wmq94euZgdcsaES/nGctcSVrts8UTO7ouBWLvAfrw0xVYUp1JgHaOrXBxYmqbPLrKPptOWXW3jTXivPL5fCw/1vhZCbOmMaQZet8aHYYVlV8hMB3vshUiCxSpUqmsxB9IXAWhCc3lPLu3G9o/qfN971TNhsmIFs1a1FrGjlhXIbFrT6aMl4U0HkNrWYI9B56tX8EBQbsgENQIsp1tRXl5DRSUCqbISSo2XLgaCEgcsOuZlt4W+Rac/FZCtVVYVuN4Cw1MbOo3Vkmvbntnanut+3f72jPACHsNH/ZU5wt3XbeyLLCdkXvrgs9fNVBCa+5Z2Ou1vhnIq4nMwYVmEQBWIDanDKVw0F7xIS3klu69/qxhKo9nBHEoENR7CyiD2h4xfdTYbZhbbzL7u4NY1R OLqQprTg 2c4/fpkzsPQ8TLnQsGmDR2JqY4eZrT04eBmARMFUAyk8gaVG0xpaioUyIZ+CYQTzzerqyKCFu2tZRuZY5bqnwNXmNoLLvevGGqMsCyRDhlPXbOmv/JO/6EDECFQ9BgeAcyc7+Q0cqW7URDOhW3u74qW/FSTfRA5U9f07DB5KiY0BJD+Sa3rNp3XdcrnpLyRHazT4X6ayXEQz2qXTkmtPyrGa628QRZADOljhBrNMJpVPaJeCjgOmcwOlY7CTGa0bK62vFfA1OHdUlVjS0EZzfU7NKTAsQfkRHEvg3hbDbPjtsbLE/tw8CbgO9iJU+6YzLfLHmuyG8WGAswmY7zvwOJbgsVoQ8aqGVg4Na16AmFhFV9xri9Gv16EoNrcgRi0/tVrw/FcuQFnTbcsPAXxqM1sJoKHitTup/ATTxcAAgzdJ90LD+awKNBtjXrIokBoX50Qgd1HRE2zoX5Z7wN5TjRcn/UYnG99qPe8N3UsKreOaDo+Zex1a5f7e5IYP7lZtKllUsCBqhS+wUZCi0NIqOmU4e1rqxUSA8tfIJTwuqD/+4WVML6zJaXuQMvlvk9yrkuhjRbAtpulZhsB54IsbiOpBX6SjW/cjW01iU0ISqAnb+JMw= 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-reply 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: Neil Brown CC: Olga Kornievskaia CC: Dai Ngo CC: Tom Talpey CC: linux-nfs@vger.kernel.org Acked-by: Muchun Song --- fs/nfsd/netns.h | 2 +- fs/nfsd/nfscache.c | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index f669444d5336..ab303a8b77d5 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -177,7 +177,7 @@ struct nfsd_net { /* size of cache when we saw the longest hash chain */ unsigned int longest_chain_cachesize; - struct shrinker nfsd_reply_cache_shrinker; + struct shrinker *nfsd_reply_cache_shrinker; /* tracking server-to-server copy mounts */ spinlock_t nfsd_ssc_lock; diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c index 80621a709510..fd56a52aa5fb 100644 --- a/fs/nfsd/nfscache.c +++ b/fs/nfsd/nfscache.c @@ -201,26 +201,29 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) { unsigned int hashsize; unsigned int i; - int status = 0; nn->max_drc_entries = nfsd_cache_size_limit(); atomic_set(&nn->num_drc_entries, 0); hashsize = nfsd_hashsize(nn->max_drc_entries); nn->maskbits = ilog2(hashsize); - nn->nfsd_reply_cache_shrinker.scan_objects = nfsd_reply_cache_scan; - nn->nfsd_reply_cache_shrinker.count_objects = nfsd_reply_cache_count; - nn->nfsd_reply_cache_shrinker.seeks = 1; - status = register_shrinker(&nn->nfsd_reply_cache_shrinker, - "nfsd-reply:%s", nn->nfsd_name); - if (status) - return status; - nn->drc_hashtbl = kvzalloc(array_size(hashsize, sizeof(*nn->drc_hashtbl)), GFP_KERNEL); if (!nn->drc_hashtbl) + return -ENOMEM; + + nn->nfsd_reply_cache_shrinker = shrinker_alloc(0, "nfsd-reply:%s", + nn->nfsd_name); + if (!nn->nfsd_reply_cache_shrinker) goto out_shrinker; + nn->nfsd_reply_cache_shrinker->scan_objects = nfsd_reply_cache_scan; + nn->nfsd_reply_cache_shrinker->count_objects = nfsd_reply_cache_count; + nn->nfsd_reply_cache_shrinker->seeks = 1; + nn->nfsd_reply_cache_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_reply_cache_shrinker); + for (i = 0; i < hashsize; i++) { INIT_LIST_HEAD(&nn->drc_hashtbl[i].lru_head); spin_lock_init(&nn->drc_hashtbl[i].cache_lock); @@ -229,7 +232,7 @@ int nfsd_reply_cache_init(struct nfsd_net *nn) return 0; out_shrinker: - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + kvfree(nn->drc_hashtbl); printk(KERN_ERR "nfsd: failed to allocate reply cache\n"); return -ENOMEM; } @@ -239,7 +242,7 @@ void nfsd_reply_cache_shutdown(struct nfsd_net *nn) struct nfsd_cacherep *rp; unsigned int i; - unregister_shrinker(&nn->nfsd_reply_cache_shrinker); + shrinker_free(nn->nfsd_reply_cache_shrinker); for (i = 0; i < nn->drc_hashsize; i++) { struct list_head *head = &nn->drc_hashtbl[i].lru_head; @@ -323,8 +326,7 @@ nfsd_prune_bucket_locked(struct nfsd_net *nn, struct nfsd_drc_bucket *b, static unsigned long nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; return atomic_read(&nn->num_drc_entries); } @@ -343,8 +345,7 @@ nfsd_reply_cache_count(struct shrinker *shrink, struct shrink_control *sc) static unsigned long nfsd_reply_cache_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_reply_cache_shrinker); + struct nfsd_net *nn = shrink->private_data; unsigned long freed = 0; LIST_HEAD(dispose); unsigned int i; From patchwork Mon Sep 11 09:44:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379110 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 2F36AEE57DF for ; Mon, 11 Sep 2023 09:50:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C47D56B0252; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8856B0253; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABFE76B0254; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9C7136B0252 for ; Mon, 11 Sep 2023 05:50:23 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6BC00140915 for ; Mon, 11 Sep 2023 09:50:23 +0000 (UTC) X-FDA: 81223846326.14.2A57048 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf05.hostedemail.com (Postfix) with ESMTP id 9D75C10000E for ; Mon, 11 Sep 2023 09:50:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BDA57x2O; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425821; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=yHeskCihNVbVdLtY6w7x00eKv1zqLoTQqay4WzKuvalSYHLq+ZeKxbmzd6+nKNL7ni7r8g 3g56ouIcKw0zkOn7F2LU5zD+IaJ62QXE3EmQtsLvWEzlYylEOm5GJspdl1l2FiO+ALm9un TPsfD7CEiql6513t7su8UfVujqU3n3Q= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=BDA57x2O; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425821; a=rsa-sha256; cv=none; b=ytoI1/+65ZdTiDqFmt9lqpuVcsMMIjuGcmh2CR8DU2ZMcgoZq1WjLHc0ag/3vzVKOHJ0ta kxzXllq88RsHR+cqyF7/Zj1dc4n36e/Zi4ARywn0Hfbfd/XwB3DrWKhYROG7ly3R/emhUw vuZKcXz2/XM+Sdd7ulDpTEXhMLl7Ihw= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c39500767aso6236915ad.0 for ; Mon, 11 Sep 2023 02:50:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425820; x=1695030620; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=BDA57x2OWmE7J1N6Z/CuLaYHgt3Vo9U+K5Ns+fpzRSRtpXqIdVEtuioE07SybT6T4T 2Wxfnpa2CG4sGEqCmvfQ+1RwXV2IkZ1+yAdGpXi1KCCA1QljgLtQHLNhT0EdqH/iCJ2g mbynfruRJA5qvtJ85aNk4vr1OmUTm52bRe4wx+1PBcjiLTvL991ql7NjRgDJ+ontna4Q 6JJnEg2TfRZbEKSpqIpteFsLMBlx0H5vwDqQUFvoPfbgv0nHgTCW9CIw4z/XewD3LM9D h2c0n6f5feY/GDmOSaVrl0prTVWhurmIK5kgZedKZ9wiuZ2E+IrGfBBdgCcmK5kXvYG8 FHBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425820; x=1695030620; 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=89uHTpJcIxLZo7abv8HLEcqu89E7sxjnosGqTuxXflE=; b=oR4+6pz922oitLXZrN6zBOLMQ5Tpw5AanqEUkszokDe0FqK8fem/eGwbc+1j2YDpbQ EHHZFVjHc0NnOmuwjCKBoa1vPtmo6f+yKy6esC1usXTSg6cRI2r/Qx3wRPpLlIeALXCn r1KqfYJi2Etjnhb9IjJEV0pRtVbVsjvxsGZrVCqeLiwG+MrSDUAP/UqLDUUV3O9ISBPw St4rL5l9WTthFU24aBaAXoGy5B6fCfQehIn9+fTBmS+/TjnHVq2qXV1JkOCq9MfhIRgC vAfGtNYVG6qE3vJIMEQKtahhR9R2qh6ZAJ3VtvD9IbFu2LEY3TyH3PgERS/CfaPcsB5l iRSg== X-Gm-Message-State: AOJu0YwU1gQnYGkEGQaCsDCwdzZtnu1IXp+8ncQBsRZW8BXYuGzn4Yvq 7OqWfUfSDKj76SALz2sgxnLahg== X-Google-Smtp-Source: AGHT+IEvj565qWnkofccC8hLFXJuQMn8WbyJUnUdIWHGtU6d/4Mn9yJ5j8IFsYM+kWtEVXfSyuocaw== X-Received: by 2002:a17:902:e5c7:b0:1c1:fc5c:b34a with SMTP id u7-20020a170902e5c700b001c1fc5cb34amr10661836plf.3.1694425820591; Mon, 11 Sep 2023 02:50:20 -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.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:20 -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 , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v6 34/45] xfs: dynamically allocate the xfs-buf shrinker Date: Mon, 11 Sep 2023 17:44:33 +0800 Message-Id: <20230911094444.68966-35-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: 9D75C10000E X-Rspam-User: X-Stat-Signature: og8kba3sqpgj6x1mut6ahqf7gf6bb9jj X-Rspamd-Server: rspam01 X-HE-Tag: 1694425821-423244 X-HE-Meta: U2FsdGVkX19uESgkNBkB016dep0acuBPwacWVTNakiJBwrI27h3sFJCWcMqS3nZONLUNRs4ZCBBMDNbkZYuofdZg1JLdbA923NlIx/UR13c45IVXVOT8C0QF29voMztJfWlc3NxDohZiTEHrBmPirDnk4bcb7CgwcutaAxVlC9jl7dEIXLT42ZcwlhBFrdyiRjU8EkKOF2OTG7kI0bGz90xgnSRqMlF8VvnHwXZVzxrP7uFoOrS4+dR2DXB0cY8y4NeJwnN/Zuw40GU9KoC81H3H/7fuLjWE3SmKtBQ3vkiNNz+MuIm4vEb+owz3hwItip7lafnAW4ZEjQgVxzGEDQLp9aEF0YsGXJk2FOQ0RSWCx8sDAj2HU7FvV7AHc67f2u5vzK8BC/aG4voVOShpqKdEPkKqsdt410z2nR+bzHIK/37WyNpCXq6GS1pjuRpqMskcjz+JugssH48LF5q7qRsl9Ne/+knRBAYR+E/6VTzBDZ1fOIn+W/Xid+qahu30kFt08c3RmIBKyaCvNRJWg8i1q4S7BIhNsKob8zstgNqKbPjWACQS/J5GMyLyxXGopnjNUtWTC/1erE1eaedqLOeR4oA1sHpOEz6CKmQD2LBa/MAHoLl08fRLkXufe7URmHb0xboVZlBl5Nu9T9tnnYMsd9YITFsGB1zMIorQPlqakj7RSS71TeQ+bH9h3EC4sWmu2lhlS90vW0RSii2O0hmHw19OG1GkC3zz+jTdQ4iUDtZK1NxSXblaScFwQpdEmiNPO9NZ+lgoUCuY0sznSgXHm2rWEk4NPAEU5t+xBuRyYfrmyvINMhi3fZ+JkqZcSCU02T/eFR5j2pLXXlGpsJnWSwWvb7v3mqWAaPXHsVfmgusWO+X1KjOisJpU7PveoBKaiN9ZEuEUVUMA+4l9bMlE/4YF8JlTkgvFWSL0G981OeOQEk8STeSSximqbJqfJuN6pBmZxK/nuUaC0/W 7IvsbMww 03GbKT7Q2JLxvkA2ejX27tO+icNnoRL1PkvcPoZFl0jAjh5m8SdZf+daThAn9KF0EXbl0dSJm5ITR5OuRMXTULXCnjqDhTNdd1rBEFb1/cO8BGIBid+IqzESstg7ewrZEv+ei8sEQufVhuvraUaMOYWNLdXUKbNZC0Rntlp1HXFvEQ95cIeCRZoyW4f6RSrF/IjEomUe/zR8oDs+VYMpltt2knVuoKoDeHgdT+K+FGLTZlclT1C4Oj60aE+LAdKf8SNnfDaP7rd/trdkcjswJj9HRgzM/2jLUo82HUeJLmouJ2QQtcTmaEA0aIYJtPnRnLE+50Qa+6wI+dI1U+XIYRvf71N5kOpIZXETGtERIbjalSCLX+LCzfA62upSDywaZIbAR6pB5UofyGTw7ek3mHaNwXnWW3ExCgoxQ9aDoKpEj9lk9nf+h4dxLXOOWrIm6KBZZEu24qzvDnMEkCdhbMdAt3CTCHrY7Ah9iLhoZmOabKanBOJ0indYrwQ== 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 xfs-buf 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 xfs_buftarg. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chandan Babu R CC: "Darrick J. Wong" CC: linux-xfs@vger.kernel.org --- fs/xfs/xfs_buf.c | 24 +++++++++++++----------- fs/xfs/xfs_buf.h | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index c1ece4a08ff4..9e7ba04572db 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1913,8 +1913,7 @@ xfs_buftarg_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; LIST_HEAD(dispose); unsigned long freed; @@ -1936,8 +1935,7 @@ xfs_buftarg_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_buftarg *btp = container_of(shrink, - struct xfs_buftarg, bt_shrinker); + struct xfs_buftarg *btp = shrink->private_data; return list_lru_shrink_count(&btp->bt_lru, sc); } @@ -1947,7 +1945,7 @@ xfs_free_buftarg( { struct block_device *bdev = btp->bt_bdev; - unregister_shrinker(&btp->bt_shrinker); + shrinker_free(btp->bt_shrinker); ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0); percpu_counter_destroy(&btp->bt_io_count); list_lru_destroy(&btp->bt_lru); @@ -2031,13 +2029,17 @@ xfs_alloc_buftarg( if (percpu_counter_init(&btp->bt_io_count, 0, GFP_KERNEL)) goto error_lru; - btp->bt_shrinker.count_objects = xfs_buftarg_shrink_count; - btp->bt_shrinker.scan_objects = xfs_buftarg_shrink_scan; - btp->bt_shrinker.seeks = DEFAULT_SEEKS; - btp->bt_shrinker.flags = SHRINKER_NUMA_AWARE; - if (register_shrinker(&btp->bt_shrinker, "xfs-buf:%s", - mp->m_super->s_id)) + btp->bt_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "xfs-buf:%s", + mp->m_super->s_id); + if (!btp->bt_shrinker) goto error_pcpu; + + btp->bt_shrinker->count_objects = xfs_buftarg_shrink_count; + btp->bt_shrinker->scan_objects = xfs_buftarg_shrink_scan; + btp->bt_shrinker->private_data = btp; + + shrinker_register(btp->bt_shrinker); + return btp; error_pcpu: diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index df8f47953bb4..702e7d9ea2ac 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -108,7 +108,7 @@ typedef struct xfs_buftarg { size_t bt_logical_sectormask; /* LRU control structures */ - struct shrinker bt_shrinker; + struct shrinker *bt_shrinker; struct list_lru bt_lru; struct percpu_counter bt_io_count; From patchwork Mon Sep 11 09:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379111 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 01AA6EE7FF4 for ; Mon, 11 Sep 2023 09:50:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93ABA6B0254; Mon, 11 Sep 2023 05:50:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EB146B0255; Mon, 11 Sep 2023 05:50:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B38A6B0256; Mon, 11 Sep 2023 05:50:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 6CCD76B0254 for ; Mon, 11 Sep 2023 05:50:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4EE98A094F for ; Mon, 11 Sep 2023 09:50:32 +0000 (UTC) X-FDA: 81223846704.07.7C0551C Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf19.hostedemail.com (Postfix) with ESMTP id 837731A0017 for ; Mon, 11 Sep 2023 09:50:30 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XkB4nN0v; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425830; 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=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=JzV3oB/YMzvOd8+knfJx015WrLLdvBTe4YVA39OsdwGRxsf5e+Hl1T3D+Yohn0lFJbqKmE XwOVZZGojaOzRg7N6kbygpmjk+FOwgNDdRpfpoDwNiFixLI2bH17OcZflKUAJ+p/uI/gG+ rEH5gDfEel5sk9OVkCtK6Lc04zAaK80= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425830; a=rsa-sha256; cv=none; b=154J4t/J82YYDaRvGx3YMvJpOETXIYsKIGnvZmfvDI4RXbL//tH3dBDycr2FVKk9ch69m8 nRQDw78yLhomqcd9uJmUs+yLAHvwDOR5OMbqgoVdeu/G5Ii+oXTH/RWMDIbTVyZcyijG4k GFSjTSpREB8t9KrRTpkraDNbUhP/1DI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XkB4nN0v; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso7705075ad.1 for ; Mon, 11 Sep 2023 02:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425829; x=1695030629; 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=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=XkB4nN0vpiPWGbxMoH9hqsAnzBIGiaC2S0D9o5rk/OsU9NJdYeOJHLdxpLkZ4654/q Reoz+bqyihTXcrEr+n1CS5eC7Z7cicTK/PwmEuE0Yb0Zqk1QsEopw8/A242KaDvY/jW6 PWaE/okaN3BTYYDkkzH/YNshlTQqIOmKyiggHs7utWZxbpYZVYIfX0Hwea3lbHQrB+p5 nqxDyreSIY5vEtjtkpuXl0QQ9izsiD88VQi9BjnNAIJkoFVIU8+ushaLW5hhoY+MZjZu 65feQgjW6PQOAGuV0QpaQXaWPnX0B8LxYuzHNWX8oiF43IkisNjk2GNGzke/6NWuDc5O U8Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425829; x=1695030629; 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=zo3gwSlnAgdCIAM8+Km1Wnkr2Sb5aG/GGOSO40v1R40=; b=JjUGDtfx5Kt3Jvl85mKHSByG1t21cBc8RTxc1Cr4Rh0fJnoEvIOT2JBaN1NbaAtTe7 1XNaAkzorbn6zC3PheQZFWhGx9PXOiNWAeS8iCjjYhz8EQD6+/SrqSwTQBrksqCmJLvs I9Akbz6LcOsY5cTqepOsIBteaBfra9/E/AdDrwtzRAoLp/sJY2ui5Fr1PB5tbM3noafx qnBfQOnTXVXiE6s/102q+2znrcnxR4FCkLKOb2oXHA7qwlowMRu36K83Za3lBcqtzYfz BDZ7pO0wcHtdfAUfGroLNbItAlgtQbs9mgCRAuk8FwXAUfehs6bPwQx+8wafsuyX0pEG d84A== X-Gm-Message-State: AOJu0YyKSjbbeHxHAs5p+Q35VAN501K83M8gbi2L81kCaSgQk4TXuH8j /aSTYJlbimg+2R76iQSOpV5FPg== X-Google-Smtp-Source: AGHT+IFNoTrjJm+fp4U1vSlQVTleS+unGs/tsdGogu2eeyLNoBUX0+IqdGoKEJL6WqzJ7IldBIpdvg== X-Received: by 2002:a17:902:e849:b0:1bb:83ec:832 with SMTP id t9-20020a170902e84900b001bb83ec0832mr11264528plg.2.1694425829510; Mon, 11 Sep 2023 02:50:29 -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.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:29 -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 , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v6 35/45] xfs: dynamically allocate the xfs-inodegc shrinker Date: Mon, 11 Sep 2023 17:44:34 +0800 Message-Id: <20230911094444.68966-36-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: 837731A0017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ox8b1yecgtitrrxbw6ehr1nqnmypahgu X-HE-Tag: 1694425830-489881 X-HE-Meta: U2FsdGVkX1+Y0weyKgoK6/YgsbEbMnVtUZ0su0eQk+wbtlegt1ilIXbshqDtgsyDkUA34QgvBcg78O1XWQR19j/Fm3SOlzSszdKzl5NYG6hbLWCEqtkAaArcEpAsA5dAx8d1Wu7Sa55MNzecoXWxR082xaZGeZCbjqufD0s5veawEgzKA3CEH+J3EhtSiW75+UYVBLe0qdXGtVc4NG/JZtQYfp0eI7qh1P79upgnrXQX63AqJO3HZpNFQBXjDuB88Vlc5Wbt2f6kVBlO/QtI1bkp/O2hxw/IXMFcTZi26FqpnrCjH3qi12ygepFCCGNPdkuLjFbQt7/1DQTxFFK3zywuTZbS7KuWVEy6v/bw1yUTMfQc/f7CpeTwGrSv2qmuJ3Ka/0hEaSjxFzQUZ/7WPAgr3TI8/+bUgTR/VKsdXg1lGSfzAornK699cFi/YGBx6jdEPlQ9QBJEm2rBPFUGMYcsDGaijL19obwZ4yzAmIsvxI8rk3z9ubHytS1cCteDN5Js9WIEg13ER4MimZPMv08YFnJEIU4aqweCRazGzaaLfvyNp4CJ9IcKyenfMUVworh/owP8B7qDAA8VfQ4P258SNkGUgwDb3JbFOBxCoybVPKfDt0Z+Xebd7RKbksFQ2kSX7/LHauG+da934v9nnz7VxjrAouO4Xtn8rHLtannQBRpLrGiEqLWBxLlbbgfhGz3eCUIHX6ydPhPSfB2XxRgy2uNuVU1ZnpTN8ESstc7W/N9+o9RO1zN+OJW4bwTEhT9jPRf9tcGGqKH/gHWDkMXR8n5g++9P6qR0H+8W5HIsZ0Iz/5Ux4qnWa44zKafKiD3OptQeZpfo8ERJg4lY5UNv8trFokBn25FS0/TdIQLq2ijQ7zQkFkjOQvrubZw50kxXLtXxvEL7Cini4H0QaIzcWKxtqKpTu+Uu3kRRb0W6BrC0lSQLDrkFaD0sblR7vIwMmG74q26e3cUjRjX DILIEx2z QOiCGAP0ySrrhp9wKErcjLNMCrZtqiCy0zDuuw/pRlorsu/ktU7LUoZByByt5VzjX84CRru38H9GwWaB261KpycwBMOOMk3iQbg59CULeX3nu/pgMFuFC7t1dyjjJTod12SlLCKpoFbsG48hmmkfZ0w3agGfnaULxwVmG5O8ikTXE4y3JEuV+tt8KLOJeL3eFg0E62OdYQHXdbZ0AL/8k4JZ8YH7xQp60EIXZHeT+PmASgA8ceMVOFoto9E2AJD5zG+ep03q7MTspMSWyKzTjTBc+h7Nw6hyQqn13QNHZhOrIy16zL3NIgdt52PMWyEWsK/w1IDjgVwXKTyEzOsSYbZrtCE7doznms8rgtMMiOnqeGe2urXESwP/6hxcTtonFMAWVIYz0ux+H1893xox+sg+aarBx4YTOi2j3VxxW8776Tzn9/g+QSYTkzuEFIjP7UKG9PDnSLwVooFRbT6tpt+y2Xkh6QGvEsVmVco0XKLIzD/IKJe4ewFYugQ== 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 xfs-inodegc 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 xfs_mount. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chandan Babu R CC: "Darrick J. Wong" CC: linux-xfs@vger.kernel.org --- fs/xfs/xfs_icache.c | 26 +++++++++++++++----------- fs/xfs/xfs_mount.c | 4 ++-- fs/xfs/xfs_mount.h | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index e541f5c0bc25..aacc7eec2497 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -2187,8 +2187,7 @@ xfs_inodegc_shrinker_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; @@ -2209,8 +2208,7 @@ xfs_inodegc_shrinker_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; bool no_items = true; @@ -2246,13 +2244,19 @@ int xfs_inodegc_register_shrinker( struct xfs_mount *mp) { - struct shrinker *shrink = &mp->m_inodegc_shrinker; + mp->m_inodegc_shrinker = shrinker_alloc(SHRINKER_NONSLAB, + "xfs-inodegc:%s", + mp->m_super->s_id); + if (!mp->m_inodegc_shrinker) + return -ENOMEM; + + mp->m_inodegc_shrinker->count_objects = xfs_inodegc_shrinker_count; + mp->m_inodegc_shrinker->scan_objects = xfs_inodegc_shrinker_scan; + mp->m_inodegc_shrinker->seeks = 0; + mp->m_inodegc_shrinker->batch = XFS_INODEGC_SHRINKER_BATCH; + mp->m_inodegc_shrinker->private_data = mp; - shrink->count_objects = xfs_inodegc_shrinker_count; - shrink->scan_objects = xfs_inodegc_shrinker_scan; - shrink->seeks = 0; - shrink->flags = SHRINKER_NONSLAB; - shrink->batch = XFS_INODEGC_SHRINKER_BATCH; + shrinker_register(mp->m_inodegc_shrinker); - return register_shrinker(shrink, "xfs-inodegc:%s", mp->m_super->s_id); + return 0; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index 0a0fd19573d8..aed5be5508fe 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1021,7 +1021,7 @@ xfs_mountfs( out_log_dealloc: xfs_log_mount_cancel(mp); out_inodegc_shrinker: - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); out_fail_wait: if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) xfs_buftarg_drain(mp->m_logdev_targp); @@ -1104,7 +1104,7 @@ xfs_unmountfs( #if defined(DEBUG) xfs_errortag_clearall(mp); #endif - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_free(mp->m_inodegc_shrinker); xfs_free_perag(mp); xfs_errortag_del(mp); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index a25eece3be2b..b8796bfc9ba4 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -221,7 +221,7 @@ typedef struct xfs_mount { atomic_t m_agirotor; /* last ag dir inode alloced */ /* Memory shrinker to throttle and reprioritize inodegc */ - struct shrinker m_inodegc_shrinker; + struct shrinker *m_inodegc_shrinker; /* * Workqueue item so that we can coalesce multiple inode flush attempts * into a single flush. From patchwork Mon Sep 11 09:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379112 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 F2B8DEEB57E for ; Mon, 11 Sep 2023 09:50:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93E336B025A; Mon, 11 Sep 2023 05:50:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EB4B6B025B; Mon, 11 Sep 2023 05:50:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D3F6B025C; Mon, 11 Sep 2023 05:50:42 -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 65FA06B025A for ; Mon, 11 Sep 2023 05:50:42 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 36358140928 for ; Mon, 11 Sep 2023 09:50:42 +0000 (UTC) X-FDA: 81223847124.30.544A225 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf26.hostedemail.com (Postfix) with ESMTP id 5C886140010 for ; Mon, 11 Sep 2023 09:50:40 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WRnEHwKt; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 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=1694425840; 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=aAoYQHmeR0aUipRnti9MSoo1QhYW8B305NLCegCj2mc=; b=BM2JSrNVOfScFONXvnubi9kFQXlDKDP/g46DTdk3pItRMmbvEZxIhoOeVubdjD8zL4Obo+ Qc817hILHPcrla0G6nWbgZTogTH388LElYW1P1wfkCExLdJ1bE72bKjhSc9945viIvpbEU M8O5tRdHrtXhrNIuHm7mCbD97PDUTK8= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=WRnEHwKt; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425840; a=rsa-sha256; cv=none; b=8IEJGgBcZsbPVWr88CjW7T3b5oeBJz5xW16qwjnihajSHCQeZ1izgDHZ9tlVCurgHo6ot4 uAt4/IYBVOXY3O2Dt9fwbi9tJ33HQ2zOFhhOj3AAb8sQUsQQT6LOfmoYWM3y4BlpWHNbi7 l2dKJc4t3s4Fpcbaczw+MXZwcXfEnnQ= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1befe39630bso9370125ad.0 for ; Mon, 11 Sep 2023 02:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425839; x=1695030639; 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=aAoYQHmeR0aUipRnti9MSoo1QhYW8B305NLCegCj2mc=; b=WRnEHwKtF7OwtNaza9ddcEjzt14pdS6G6rPt+iXXwBoJNeDzVEfZelvad5fDBoTjWK mgXP6CYnUFtetJAHXw6JugCwslDRABb+P+zKoomqvwlcAkv0pWLN/4I5F150dfTb0iAh HN47kErnxXSdBZrB++bGiwrDQtLsoFof8t0gjfHRyJGZQj3oSu/1C8pCXgJzlsP2682u tvFF7VKulJ/W3DUo8cCVRQQfUQjq3YkuxtVy4GfEETEKNtgO7jwJ2ONxIoKnGWtVaoGX ihV5lg5a2vZKBGL+fRKVqkXFHfJbb9F+ZTgenANeWiVuvl5tLtdMHMcOxDG6xEjB2Wjx OWkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425839; x=1695030639; 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=aAoYQHmeR0aUipRnti9MSoo1QhYW8B305NLCegCj2mc=; b=GrsolJx3RmCXl6EXt52s2Rri+UqqiLecFYe3/SsZ3UHrpDhNkulptl+1+un2lFL8kL So+I4DnQUFgGqCA9yxnlj99FPMx79UMb2IiOKVRP/MYU5Gthhqyy9SOi9UCZUbWzsGMj hjEtjqcsvVNyHfnTdvK3+w9pOGzI/usvv1C/hKDq9AYy9/f7z3Cm98pdvuayme0z+bAW xQc3vajPJZYeV3+nRau9eJKXj9+ROlMWTjFvwTLsLP8h9k28dnN0Rpi1iS2Lt+5PvvAl omQtBlZrHA84CyTf8Hctc1AsbrK34NQ93kX8lsaZjzeR/rn1FxOsKWY0FHzIHuqHzbwp w/4A== X-Gm-Message-State: AOJu0Yz8wsdCKjtrXqidzY9Tv7sIwM3aTIsJAjbhhDzspmLg1UgjAKPC ArLBFlhGPmc+qkJMSMM5rm2kCGBd7wH/lNAIwec= X-Google-Smtp-Source: AGHT+IFT+86I6bu5GOdEzWlfUK8qBkCzz3enuPKZPjEpOf5YfG0XONb6VNSqG6hacK72QD8znouzTg== X-Received: by 2002:a17:903:2843:b0:1c3:a4f2:7cc1 with SMTP id kq3-20020a170903284300b001c3a4f27cc1mr5320660plb.5.1694425839278; Mon, 11 Sep 2023 02:50:39 -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.50.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50: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 , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v6 36/45] xfs: dynamically allocate the xfs-qm shrinker Date: Mon, 11 Sep 2023 17:44:35 +0800 Message-Id: <20230911094444.68966-37-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 5C886140010 X-Stat-Signature: rjdzmsoueypcbr4r9rfy11ru1xh634gi X-HE-Tag: 1694425840-351588 X-HE-Meta: U2FsdGVkX182bbqOicZGoKHQFzQ5zho4hjqpHGofyPaI3Ju872GcoWuOBKqv/Flgg0BGFlHcC0YFvrI9a6ghGn+hK0emEmc/39xesMdpRDisijAyE4+ERP9h+eMHIcOgeLwMdQRf9EAGy5ZE7CjT5SGFBi6QK+kDcXbLKEKyp0I5uPrOiNCcOYRg/jwMM0diMwJFHwRAmsICjwm30gr0/pf6BZR0VWYEz5FgJlpJR1lTCYoPb1KK4SNoxlbi/HnIuhxBUfdxbxH3i6ca4ADiTJZHJOU5S59dRjL130DIeObDY8RFrkp/DykkvSZpgdJ8lT337E4FHAy3jWctPdgq1bkl5qWb/zQ7gNzE8mtTDE5x1hqr840uOhcZh8X/SfXYj1xiRSMRls8paqZ4XMKjSbfcHfJI2AXcUDPcpglpINN/ppGFqaiH/C8cft5ju+CotQjbSNyKMAKJLNxrQ9ZX+y2KyuXzDNt4dVjx3/SgXz+myY4/7D87JmjaBJwsLzhPnDFwuQ2uG+Zr3rFH1DyiBObPDpQICta7YRQFyUA8/KCh/PCOrCoRzUB+ESCrPpj6zGJBq+YTNsnbnOMA7rFCWPw3fXj9nDiwC0ypl2CLAgqBHho5mOpfhAHHXXgxM0XpBzfyj+bAsNngj9HW7rKK7frTJaNi8FcCu/8qdOe90QrnbPlQiRvzdzUCtNWv3IVLb/Lg5XaW9UQb7ReUbNLV3amTFxliN3u/zzNHgD0ZP8ANtORV6a+rQHi7HOBbrd+Xq4iP9qLh9L7JYi/ok2NdjGa90A5XBK05gRl/Rf5fGmOVHJanIKNGa0+Rulj/mbJQT/DNkQxK0Ax87tad9bRdHKvDQ7mMpzteDpK7oAHV0pa24UfOnO7m4bcPIV9ubRrfWBDZO75Wy1frrmAYvw0UJk01ac3dv/f8K4X3hV+rLLcMQYgDPZg2Hdlgdw4dBwwqrP+4UnbsiWFFmrRUCgA 3LC3EM2f 8jys7gvRpsp6pnDljWVuGc/Ne1paIYVroJGwj0yrpEYjH9ygHmR/psxhvzVKDRhUDBKPIsX9tQFa8bZIX+OM+c6lFEsmxPxY+QB4cK6y4GXquapAeqvfJzRGSf3GoiQTo1y85bM1DA2VKoSbso4pkipB9rNfTPdg0UtHFWDxaMM8PQ3ZsgyenLgsECPYLbWL8Ti2vvF/Ad2HTLOWESY04tpA5zAI54VZOhARqfq9IT9tNRp9JGkgXL8aApicP3Af065bYha075WuFVV+hVVeYGv/Z91fUxyxHz/HC/ftno3gB1/dv3XwqANc/U6VHOurBgXb+VCRUtHgSDQYtJiUZTmc0TNJYEv75eUsz2bgAxyfADhMQPkwLclkOFrSe4purKdBligRlgQGoVeYmx/5/dUlLUcCZBWgu6Wj2S926YSatGVRAws+1o7zlhO3C3nFfarb2RBrByS7bTSWh1vf4MZBOHjyibd63XPY54m2kLcN/EgBlMpGU471Djw== 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 xfs-qm 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 xfs_quotainfo. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chandan Babu R CC: "Darrick J. Wong" CC: linux-xfs@vger.kernel.org --- fs/xfs/xfs_qm.c | 27 ++++++++++++++------------- fs/xfs/xfs_qm.h | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 6abcc34fafd8..f45de01013ba 100644 --- a/fs/xfs/xfs_qm.c +++ b/fs/xfs/xfs_qm.c @@ -504,8 +504,7 @@ xfs_qm_shrink_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_quotainfo *qi = container_of(shrink, - struct xfs_quotainfo, qi_shrinker); + struct xfs_quotainfo *qi = shrink->private_data; struct xfs_qm_isolate isol; unsigned long freed; int error; @@ -539,8 +538,7 @@ xfs_qm_shrink_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_quotainfo *qi = container_of(shrink, - struct xfs_quotainfo, qi_shrinker); + struct xfs_quotainfo *qi = shrink->private_data; return list_lru_shrink_count(&qi->qi_lru, sc); } @@ -680,15 +678,18 @@ xfs_qm_init_quotainfo( if (XFS_IS_PQUOTA_ON(mp)) xfs_qm_set_defquota(mp, XFS_DQTYPE_PROJ, qinf); - qinf->qi_shrinker.count_objects = xfs_qm_shrink_count; - qinf->qi_shrinker.scan_objects = xfs_qm_shrink_scan; - qinf->qi_shrinker.seeks = DEFAULT_SEEKS; - qinf->qi_shrinker.flags = SHRINKER_NUMA_AWARE; - - error = register_shrinker(&qinf->qi_shrinker, "xfs-qm:%s", - mp->m_super->s_id); - if (error) + qinf->qi_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "xfs-qm:%s", + mp->m_super->s_id); + if (!qinf->qi_shrinker) { + error = -ENOMEM; goto out_free_inos; + } + + qinf->qi_shrinker->count_objects = xfs_qm_shrink_count; + qinf->qi_shrinker->scan_objects = xfs_qm_shrink_scan; + qinf->qi_shrinker->private_data = qinf; + + shrinker_register(qinf->qi_shrinker); return 0; @@ -718,7 +719,7 @@ xfs_qm_destroy_quotainfo( qi = mp->m_quotainfo; ASSERT(qi != NULL); - unregister_shrinker(&qi->qi_shrinker); + shrinker_free(qi->qi_shrinker); list_lru_destroy(&qi->qi_lru); xfs_qm_destroy_quotainos(qi); mutex_destroy(&qi->qi_tree_lock); diff --git a/fs/xfs/xfs_qm.h b/fs/xfs/xfs_qm.h index 9683f0457d19..d5c9fc4ba591 100644 --- a/fs/xfs/xfs_qm.h +++ b/fs/xfs/xfs_qm.h @@ -63,7 +63,7 @@ struct xfs_quotainfo { struct xfs_def_quota qi_usr_default; struct xfs_def_quota qi_grp_default; struct xfs_def_quota qi_prj_default; - struct shrinker qi_shrinker; + struct shrinker *qi_shrinker; /* Minimum and maximum quota expiration timestamp values. */ time64_t qi_expiry_min; From patchwork Mon Sep 11 09:44:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379113 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 0E96BEE7FF4 for ; Mon, 11 Sep 2023 09:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A268D6B025C; Mon, 11 Sep 2023 05:50:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D6606B025E; Mon, 11 Sep 2023 05:50:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 876A86B025F; Mon, 11 Sep 2023 05:50:51 -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 74EE46B025C for ; Mon, 11 Sep 2023 05:50:51 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 46E50C02D9 for ; Mon, 11 Sep 2023 09:50:51 +0000 (UTC) X-FDA: 81223847502.14.106282D Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf26.hostedemail.com (Postfix) with ESMTP id 79660140009 for ; Mon, 11 Sep 2023 09:50:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=gejDJHzs; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 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=1694425849; 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=VTNYXL/R7M/nPTx6n9hiKgpOq1ZzCxN84K5zlnPRsiM=; b=BophKWZvQGfiDj9cCithyxz5/Nm/fvNUtaApwhXCZqD9MrtbNfRBIlzUHBS4cufGFDsIT+ J/ZZiZpOAqWFw3S0L/elHy319Qedh12yE+vaRauMtkub7bnt4cmjDVFhK8i7OFcxUtvrxA yEwfSK43oCI2amyRmv5iuVg7KgePTiQ= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=gejDJHzs; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425849; a=rsa-sha256; cv=none; b=kg0ZS2UeFtQDE3DYppYeLW3jhBd1xbtVc5ikWm3nsLboz6t6EhGQ5YrqYh/1caL1AO0arb 7b3F45EmljzGqY2/l/kZ7fzuSetqENRfUmrlWairKwK/5mFwgJV/szG3uPjYDwbVxk+mUa N8ucWgK8UGM9WrzLzCZUkJJiSwqiozY= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1c39500767aso6237495ad.0 for ; Mon, 11 Sep 2023 02:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425848; x=1695030648; 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=VTNYXL/R7M/nPTx6n9hiKgpOq1ZzCxN84K5zlnPRsiM=; b=gejDJHzsNiZjhRwMuFS+vibiZfCsPWiOqkajeDhn7Wwbi65S+Q7CynmFuuc7j/bd7m 24FwPLfa1zy+/liXwhTe7A397Btn/m8unxnLSAauZR0akV4b/ko2OUp2pRB5cONfVdNg v2o033GpR5k1Z/8xyrMBYVeMxDLzmepBwZSweboS8HhXfvl/6IsA/VRQotihDdFEhl+n AmCCQRp7oQwfElf4nJTU5pJK3uUeKjoKxaiA07blbDRXuqXFEbfk5/zYFPWsAczO3p7r JYnP13C7cuvk75yewQNhsJvxkl+CoEw/YtP2oaYM8KW0JhtXLnvBgjSuMi9E8JtXT4BN XZLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425848; x=1695030648; 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=VTNYXL/R7M/nPTx6n9hiKgpOq1ZzCxN84K5zlnPRsiM=; b=aSxJfyMAt0qLrf1opIO7wGMiCfbZNADGXduAqV3GL51AA922WX7HTP+ZE+L9yOqFoC 6ooqq9j9tT230AQn1sKF9vlYF8r9MPkCpECsHgHTTjI3CoY72oDvmViYGkQoVrHv5896 MoNdrIxF18/v7/DsjHFCUjbPCcMZfzzw3eSQjpfwtlgqAV/9kwdPF10l+1fJ9J+taQVC avb10NmyAdXxLtrmcH5DiYmajEtNzS+71FO+QtWeCJMTA3W9cpM+cF9zA0gXrq+jTOMl f9yvXnbt85G7bs+MuSi20uwnYas5jmv3ZYT9ySlXf3vhQkUuz9ktMfOAmVzqm8R8tZHd UMyg== X-Gm-Message-State: AOJu0Yxp5qrDyV81fLYF9ejUiQ7eLaUhyInhOdSFer75t93cPrQCdCrQ XWX6TUzxYx5oKV78Ciau4NBklw== X-Google-Smtp-Source: AGHT+IEacDPb0mHmf21GNbuP05fWsDcTy2ksO8DVITs4JFo4XsRI7vg8H5BM+TEndmXxdohti+42Ig== X-Received: by 2002:a17:902:e5c7:b0:1c1:fc5c:b34a with SMTP id u7-20020a170902e5c700b001c1fc5cb34amr10662458plf.3.1694425848453; Mon, 11 Sep 2023 02:50:48 -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.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:48 -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 , Minchan Kim Subject: [PATCH v6 37/45] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Mon, 11 Sep 2023 17:44:36 +0800 Message-Id: <20230911094444.68966-38-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 79660140009 X-Stat-Signature: 7dxqnmu5hgt4ojuehwdhrx6yni6o14yx X-HE-Tag: 1694425849-725486 X-HE-Meta: U2FsdGVkX1/ecULnUWRWkymN/Oply/icacHttZeV5mtG2UVUHRAvlff/m0iIPCdUGquicXNJ7XejjEA3DwQR+9s2AEyYSkom0HEaZnJJ9AwlGaofWAKQ56jGUohkqX0OVe97VG95FGq31f5AlQMC7p7vToO9jhg+cQVEoeWThZ5Xg/UosEOjm1Yr0quTkx9NstTPCNMOi9yaavfLPcNRI4lMATpP6VH1ocDEyvw55wDzdnGl9NOkPQgNWNq00rjGUhWx8XcKxq2F5ljrq2jCJOkwKAdwBIeuru7XScHq49uCDgcJ1ap5Sk5cXTgdTMPC1E1KRySL5dJd/YNXyiADrUi2mLeY/DfriafpAY3gG8gxxvinihhy4BtbjfmJzYXoUjN8gUHLz6ownkniHT86Gq/tOOiZifPiuLInahAiJ4kZMrLAkEw9l4xQSM1zFtVAy1Wego5on/1U/+LbFttnpsgMBpVWfWv0rO7lRDpLewYBru/ZoQAQazdvxBquYfq7ageLMbyQyIcEJW8Y0M1xcGfCIlCNEjSaYVdjIvUAILle/FXoiPYWVVxod0F8jNBNjsoH1r+aKmmgNR5Y0O1Z5a3LNaUHxXNe/dCpawAT3z+xBwrKbxJLaeml5MA6ZZii2ulBxTCVgF3iACbWthL6m3ofaZYNIxhU6+NNff3mYgA+tqX+CheD4par4sN5botrxz/sz2L6s4XZoHPN41lI2N2eo1jg62sY1nhBwoMkU46OJlX/703APGF3uMahPfQDTLo0fk3xLEAV31ZLirRonF7s2tnjMIqt6WhTJWw91N+NILsF0sf2xf8BKot4OwivjJmN6Xius9gprR4T/giusMZZfTXjBUrlHeIrcHeVUt8JIUqtHGXosZPRVA67ahBPjWMXd2+72hZ3dre3mLbp2pFI/x0leKNPrai9wuDZaJfJqFqJNYNrhWZT8w6ivqsQ+gRwBR+z+sDsiQW5ova ONfTXzMa zbVYI4bvrwqPpWyeZABEZzjUQHL9PxUOKJgYQchUycBZFrC8ZxIJlB64dcfNXG91CXIy6vgFTQWcwndcMPI4pU+iErgKdAEiU7LF1K3ofr55my7hHIeuwNfnKL8/7ufBuBqi5YVs3bMCke5C8DdEACRyzNn28uaHEhr/2Ds6zTiWxcNpu4TGcs1nG03Q1ioHyImtohA+FUGVXGnf8WiVg0flUacR/WU6Mm54wJXlb7H+yRIEuhADR26mhuN9VT3NVb8MsOG1TeOL8UvKvrsbK2XVxyBSmXAFpbMnqWvd6N4M9W7sncaDC7Wc7bl4pZo5pz17kUchj2unQJ7rfbcdLO6QSsSQ2wkgE+JTENsRdPjTpFyqWB/Lifk9gD7wQj47NTMKSC4HeodUxFBVGOpAcwIIqa5hipa0gVyZ07qMIBpgzUCju2XuHhxtx9JdU12C23K2RerzP13bus7mVD+ogNRcHza7twzxjcYc6l7JFf+bOyulEmRu70sJLzyt9RSM2BP2FkP0DCepa0s4KEb/M8cZD1u4DV+z+se3z2qSPviUMvXmZ0k/fhdpv+iSHpUp+wvxukWRjDMvVtxY= 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 mm-zspool 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 zs_pool. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Reviewed-by: Sergey Senozhatsky CC: Minchan Kim --- mm/zsmalloc.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b58f957429f0..c743ce7a5f49 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -229,7 +229,7 @@ struct zs_pool { struct zs_pool_stats stats; /* Compact classes */ - struct shrinker shrinker; + struct shrinker *shrinker; #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; @@ -2086,8 +2086,7 @@ static unsigned long zs_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { unsigned long pages_freed; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; /* * Compact classes and calculate compaction delta. @@ -2105,8 +2104,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, int i; struct size_class *class; unsigned long pages_to_free = 0; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { class = pool->size_class[i]; @@ -2121,18 +2119,23 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, static void zs_unregister_shrinker(struct zs_pool *pool) { - unregister_shrinker(&pool->shrinker); + shrinker_free(pool->shrinker); } static int zs_register_shrinker(struct zs_pool *pool) { - pool->shrinker.scan_objects = zs_shrinker_scan; - pool->shrinker.count_objects = zs_shrinker_count; - pool->shrinker.batch = 0; - pool->shrinker.seeks = DEFAULT_SEEKS; + pool->shrinker = shrinker_alloc(0, "mm-zspool:%s", pool->name); + if (!pool->shrinker) + return -ENOMEM; + + pool->shrinker->scan_objects = zs_shrinker_scan; + pool->shrinker->count_objects = zs_shrinker_count; + pool->shrinker->batch = 0; + pool->shrinker->private_data = pool; - return register_shrinker(&pool->shrinker, "mm-zspool:%s", - pool->name); + shrinker_register(pool->shrinker); + + return 0; } static int calculate_zspage_chain_size(int class_size) From patchwork Mon Sep 11 09:44:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379114 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 A9FB0EEB57E for ; Mon, 11 Sep 2023 09:51:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F5846B025F; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A63F6B0260; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 394EC6B0261; Mon, 11 Sep 2023 05:51:02 -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 2A0286B025F for ; Mon, 11 Sep 2023 05:51:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 01E301CA405 for ; Mon, 11 Sep 2023 09:51:01 +0000 (UTC) X-FDA: 81223847964.26.AF236CC Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf17.hostedemail.com (Postfix) with ESMTP id 0FC5740019 for ; Mon, 11 Sep 2023 09:50:59 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hm52fbCO; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 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=1694425860; 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=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=nFqC6Bnc8NkxpCUeT1lBHCHusLjlBZwN2X9BwbTZn/UJO+nm3l218LKs3gIVWmu4eV3bOt HtzD9741FB0LY/lXhBa/2fMpb76EwNyeEvh8sZJSVPuKeyCFH7ptTIRmenwpbFA/FBDjY8 huWHpL5flBggqGtKh/7qD3WveTBaSAU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=hm52fbCO; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425860; a=rsa-sha256; cv=none; b=yZAIqGBgjZMSFAFbmhe6kJfATBll7JeFv0aZlPkz5I40pg4G/0JczgrbBGxoEHdIYTVA1L g5xiGg9kR5bKzntO93W9f2g2JRylw1P1Saf++zx00SBqed+UY1HdGr5RKk/Qos1AK5Qphw YEKQB/gEJ1gh0uic3f77GBb/lKchv34= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1c39500767aso6237815ad.0 for ; Mon, 11 Sep 2023 02:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425859; x=1695030659; 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=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=hm52fbCO6XAeWqboYIdMIRuZiN6rFafLWaBmhejB45IHN7IFTyEM4NYON9i2z6Cm2k Swe19SPr0rZ1s3NkBAPXSucQPMduzcnLd7tMXgEyIM7awVJttyWegqiuH5PTPetu7E5q Tgd+AfAKLABNtnu8xTeivoLvd96IkC0znuKIrFdps509Gol7dWJHAzoovtFhO1hKFlB0 lWtStc1v2ForK+d3KNicDgYzBDDW3QN1IJsnU6XHPIjdDHPX3RivZmVAIMp7Jh1rN3MA To9DKJpafl/WAwcGWgaiWIWe0fFj3YbWkRPnESuuZ/y9xVfV51Hc29MVNAfBLu2emM4e dPOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425859; x=1695030659; 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=UwQSoSJR+jSGtu7F9A/uGElinPV2h0dmFylLKakGH3E=; b=eb9L2U4ZyGgySn17F1s/Pabw23mmgTsT/vwboLQ78kwqId86sOmStpuMaS8TAtX+R1 BH3iqP3xwGy5MsIItvKUqmxiG8ykJOxFF64Jpd5040IXn5K945uMI61QVYmWdjxJWi0v TLRHYJnh/GHRYfbyxk5oBw47jWFWjjWe3WUMtbVnEsi+3jo9O6EA7mqszIvJq6mAS/Lx 1SdRoN1Vo5JrTU1VQ9tybtfpk+bgj3XhRjgkn7K0PWIlBA1UPLdJCGIIV9zy9tr3M3rj GUFZ/NVmkUgzv25Cor3ZBW1XFjuS2InxFGasQZNRAZ5W7Cfk71YURds6y92WuhEldB50 VOcA== X-Gm-Message-State: AOJu0Yxd9rMUFjfvJyT9epb+K4eygRILD6Wqqx9NbUqLLoa/StI5BJQT lH9cf8fAifweoHFhk/L/H6quFQ== X-Google-Smtp-Source: AGHT+IFK0C5cGs7QePEp9uLcPywDnGod8IFfwet3Jfbl6uzPvoZmscAh5Bx6Hmh6im2BgxS0qDp7eg== X-Received: by 2002:a05:6a20:4425:b0:14d:4ab5:5e3c with SMTP id ce37-20020a056a20442500b0014d4ab55e3cmr13477043pzb.1.1694425858977; Mon, 11 Sep 2023 02:50:58 -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.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:50:58 -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 , Chris Mason , Josef Bacik , David Sterba , Alexander Viro , linux-btrfs@vger.kernel.org Subject: [PATCH v6 38/45] fs: super: dynamically allocate the s_shrink Date: Mon, 11 Sep 2023 17:44:37 +0800 Message-Id: <20230911094444.68966-39-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: 0FC5740019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: p9qt9anqfpxyuq9byap1uj6sd9xk6sr3 X-HE-Tag: 1694425859-445677 X-HE-Meta: U2FsdGVkX1+R/zkkSPFLZKgegR9Q6KzP9+Bco3yyUstMdkmXRTgG11yEtMe5a1laaCF1tD1aMSVrT48vqR2W1tyz8Yrt0A0D9f+f4LKoSJCaWnW1cDrfLEoNFXwBhGskS0P9IOQbrpLNCL39aSHudCphV0Lskzpvr76/rXcMXiKa50A5NJmYWQp9vtkHqRCea+mrM80VRdFh7BFOmXPIE7SL93426aJwxXQShPWSkaOfOpiL6c48YMpUM4WsDF6znkegQCvi0JKtdDLkPTQ9FmeLLsRKo/WuDIdwqeJdGBcIpw2ooW0D9QCZrwt2VsgUXI6SYD+IGIJC8yGJpK7DNhtix9CcsOV7Rci37nYUwG50B5RkabUN7kFh7BPQilOPYC5SaBJbZgeJUe1mW3NVK8O/yMNbb2bbDEV4pfVdRt3Ltn/BKj2UIxqXbjDeQ6vbBpXF9UF/GIJpMaZEPtmr6twZcVk/0vIr7wDZCPWO4dclgwZDnLpZkAOCrlNhsngf2e/XarSeFJ8yW8qAOS2icpUhGE289bb0td02RedAiks1Jaec0VCWsps8MRhdcM2E0lIQz468m0LkD1yzjGOLgiHGSxvnc2bNBBj4zof26Ol8au6LZyV6hUAXLNr4oL+RTiN70X5V6HYalbkwjCI8u+hoJj3NaTp2L2xarMA9QS7W/so49qjJSYo00b0ri1IOxLDKA5MDs6ZFsDGs+BvHU906AKw62mvk9BadFyISEyFprQqH7+HSJ8prv5/hSO0GTTbPZOhjsoXgQDVovciIsb9n0ZZZiIQsZXyPSTQYiixhmeUnpkTyvZbGYg0TY+OxpK18+NzNl7HyyaqJdahZVNqF7J7aq9oX6YYuJKW0pG5zc12vAxOms6JLg2zXwx+BXACPa/pW9F4UE92vqqsBX4Wb8n38mfYJLLBGTvuLu4YAaxnvMrWd/1iHmVtovCTBb4ItsoPl9rPWnJsLUdC knIufwEG aqLdRlWX+OJYYSPLdFve32yhCpnjLr2oFNFLm7tApdQ0XqwHznNYuBv/Fjxp3xVPwJQnJefA/JsYXSA56W/hBB7X9CsK6PVl+yCL+x0R4fOquGGyZG4hC+NC135JGFNtc9oxQPvEb1VVdmqVrd/Np+A/wl/aF3PC43Kn7I0PT7X74GJMYGzorgWusMoJQQMQmuohNbKuhoxdZWxw6IM4N3ILzgndjPR8I0SAetXTQvj8TCWGvyasoktiNM1g8qG8nHcsKdOb8vEuh10z9c1kmdyRMFuJtzPqHAzrS93iemmG5cEzyXO+vSvd/fo+QjxNNpe5CbeDBYjZIVGlbZtSAXINQ2bh3UIhDtFAnuk/vXUpz0ZiLxzdSwPH70AOHSbFqabaAIHgjxyC8pkv/5ZZuvVzUWnDJAz1fllQOGRG/cOn6g86ajYYtImXgh6I4E29x/qqX9mNFLd0QJQoRNZMtZimMshghEwqKa4dAzJm676/FpIUxMXB33td5Fd0gj8GJvNTvrsmaol3/XzT9pnWgjdj5gLcAQqGQGS3JFaOdc/4G5p3UPSYOCekj+Unti9qQC5fY8elxtv9EpSug2xoPbIA721k59E9G1yPz7kMAbVjQH/DdH+nZ5bjUQNv04DOd4uP56TPUMW8qTPaqKPD8sMf6AUt97uQYz3y8MKP6LytvxEIIBWm7qC1T6ecvskZ7gAtvnaE3m+miNN+aAqpbaRSPg4cOyddDyD+nHJv67EKTGxxRsuZVlVdXyYabeHFSf5ek 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 s_shrink, 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 super_block. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Chris Mason CC: Josef Bacik CC: David Sterba CC: Alexander Viro CC: Christian Brauner CC: linux-btrfs@vger.kernel.org Acked-by: David Sterba --- fs/btrfs/super.c | 2 +- fs/kernfs/mount.c | 2 +- fs/proc/root.c | 2 +- fs/super.c | 33 ++++++++++++++++++--------------- include/linux/fs.h | 2 +- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 09bfe68d2ea3..3b165d9967bb 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -1519,7 +1519,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type, error = -EBUSY; } else { snprintf(s->s_id, sizeof(s->s_id), "%pg", bdev); - shrinker_debugfs_rename(&s->s_shrink, "sb-%s:%s", fs_type->name, + shrinker_debugfs_rename(s->s_shrink, "sb-%s:%s", fs_type->name, s->s_id); btrfs_sb(s)->bdev_holder = fs_type; error = btrfs_fill_super(s, fs_devices, data); diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c index c4bf26142eec..79b96e74a8a0 100644 --- a/fs/kernfs/mount.c +++ b/fs/kernfs/mount.c @@ -265,7 +265,7 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k sb->s_time_gran = 1; /* sysfs dentries and inodes don't require IO to create */ - sb->s_shrink.seeks = 0; + sb->s_shrink->seeks = 0; /* get root inode, initialize and unlock it */ down_read(&kf_root->kernfs_rwsem); diff --git a/fs/proc/root.c b/fs/proc/root.c index 9191248f2dac..b55dbc70287b 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -188,7 +188,7 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc) s->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH; /* procfs dentries and inodes don't require IO to create */ - s->s_shrink.seeks = 0; + s->s_shrink->seeks = 0; pde_get(&proc_root); root_inode = proc_get_inode(s, &proc_root); diff --git a/fs/super.c b/fs/super.c index 2d762ce67f6e..adadf6689611 100644 --- a/fs/super.c +++ b/fs/super.c @@ -191,7 +191,7 @@ static unsigned long super_cache_scan(struct shrinker *shrink, long dentries; long inodes; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * Deadlock avoidance. We may hold various FS locks, and we don't want @@ -244,7 +244,7 @@ static unsigned long super_cache_count(struct shrinker *shrink, struct super_block *sb; long total_objects = 0; - sb = container_of(shrink, struct super_block, s_shrink); + sb = shrink->private_data; /* * We don't call super_trylock_shared() here as it is a scalability @@ -306,7 +306,7 @@ static void destroy_unused_super(struct super_block *s) security_sb_free(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); - free_prealloced_shrinker(&s->s_shrink); + shrinker_free(s->s_shrink); /* no delays needed */ destroy_super_work(&s->destroy_work); } @@ -383,16 +383,19 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, s->s_time_min = TIME64_MIN; s->s_time_max = TIME64_MAX; - s->s_shrink.seeks = DEFAULT_SEEKS; - s->s_shrink.scan_objects = super_cache_scan; - s->s_shrink.count_objects = super_cache_count; - s->s_shrink.batch = 1024; - s->s_shrink.flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE; - if (prealloc_shrinker(&s->s_shrink, "sb-%s", type->name)) + s->s_shrink = shrinker_alloc(SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, + "sb-%s", type->name); + if (!s->s_shrink) goto fail; - if (list_lru_init_memcg(&s->s_dentry_lru, &s->s_shrink)) + + s->s_shrink->scan_objects = super_cache_scan; + s->s_shrink->count_objects = super_cache_count; + s->s_shrink->batch = 1024; + s->s_shrink->private_data = s; + + if (list_lru_init_memcg(&s->s_dentry_lru, s->s_shrink)) goto fail; - if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink)) + if (list_lru_init_memcg(&s->s_inode_lru, s->s_shrink)) goto fail; return s; @@ -477,7 +480,7 @@ void deactivate_locked_super(struct super_block *s) { struct file_system_type *fs = s->s_type; if (atomic_dec_and_test(&s->s_active)) { - unregister_shrinker(&s->s_shrink); + shrinker_free(s->s_shrink); fs->kill_sb(s); kill_super_notify(s); @@ -818,7 +821,7 @@ struct super_block *sget_fc(struct fs_context *fc, hlist_add_head(&s->s_instances, &s->s_type->fs_supers); spin_unlock(&sb_lock); get_filesystem(s->s_type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; share_extant_sb: @@ -901,7 +904,7 @@ struct super_block *sget(struct file_system_type *type, hlist_add_head(&s->s_instances, &type->fs_supers); spin_unlock(&sb_lock); get_filesystem(type); - register_shrinker_prepared(&s->s_shrink); + shrinker_register(s->s_shrink); return s; } EXPORT_SYMBOL(sget); @@ -1522,7 +1525,7 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, mutex_unlock(&bdev->bd_fsfreeze_mutex); snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev); - shrinker_debugfs_rename(&sb->s_shrink, "sb-%s:%s", sb->s_type->name, + shrinker_debugfs_rename(sb->s_shrink, "sb-%s:%s", sb->s_type->name, sb->s_id); sb_set_blocksize(sb, block_size(bdev)); return 0; diff --git a/include/linux/fs.h b/include/linux/fs.h index 4aeb3fa11927..801ff3d66caa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1265,7 +1265,7 @@ struct super_block { const struct dentry_operations *s_d_op; /* default d_op for dentries */ - struct shrinker s_shrink; /* per-sb shrinker handle */ + struct shrinker *s_shrink; /* per-sb shrinker handle */ /* Number of inodes with nlink == 0 but still referenced */ atomic_long_t s_remove_count; From patchwork Mon Sep 11 09:44:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379115 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 A316BEE57DF for ; Mon, 11 Sep 2023 09:51:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 459046B0261; Mon, 11 Sep 2023 05:51:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 40A2B6B0266; Mon, 11 Sep 2023 05:51:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D18A6B0269; Mon, 11 Sep 2023 05:51:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1ED0C6B0261 for ; Mon, 11 Sep 2023 05:51:10 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ECE95C02D9 for ; Mon, 11 Sep 2023 09:51:09 +0000 (UTC) X-FDA: 81223848258.06.CFC971C Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf17.hostedemail.com (Postfix) with ESMTP id 2A1814001C for ; Mon, 11 Sep 2023 09:51:07 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kNh1kkMy; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 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=1694425868; 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=Fa9xv5O6zRN9YujHabqvlTbDnEkmHba3eF7bPn48dFs=; b=NiIYl8AikasUNSRTHyVjVKDUwr1SnV9qocBfeZD60QlNe69oCE1n3x/l+FDQlEeT+qnXQg 6EcNbj1WzW9RdkTMWO8Z4SuJv6qa59lacELWIH8Qu9jwNJXMCWRGurf5RlNYEFT0DY9V/q u/BOZoOJnqiaArXcTC+AxP5QQXC/YWU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425868; a=rsa-sha256; cv=none; b=wlsw9mcJ1jynSKQavXHMHYbZBLx5d1cdtL3OShSt2s6wTH1Sh1N8bmw5iTqFBZT3kNrlgc QNoGEWJ2uwPFvm9x2Z6pzlF4K6nWJ0Buk+A84vZN/tPdS4QMUejgJQWSee/w+D9Dts/E2Q pTJEtT4UQCLBivuCz1KPq3Q3pKWsTMc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kNh1kkMy; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1bf7b5e1f06so7714275ad.0 for ; Mon, 11 Sep 2023 02:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425867; x=1695030667; 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=Fa9xv5O6zRN9YujHabqvlTbDnEkmHba3eF7bPn48dFs=; b=kNh1kkMyxaWdSUYzEfHAd31ima8lwkvgP05vO/qmt0RPDwl6rhbrXznc6ddWt2BVlW YItXPBjUHAq9eqJAF3/t6Wteo4Mv5TD+naZ4pha5pPU4FkSv+kJbuqvjtoO7wHy/wych +9bXUfXoU8Cuz68FYOQz8Wsoq2pJ2SyOyLP7CIKM2modIUwwZsvr13Qxsbtk5xB6+Z8o 3i0FHVRYF7pNE46S5GhSncFkITcEGEO/irZcmxBK40XSlBatqZgQqVXXMQxZoCSOsUaF 9bKMVYdR1QxkJqB+yPbH2TkrPG5piNs2V1Dm1xhk/Gd8xICxR/1STlxPgYnOMM0+NFnx H8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425867; x=1695030667; 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=Fa9xv5O6zRN9YujHabqvlTbDnEkmHba3eF7bPn48dFs=; b=w+DnpO+dgjcby7kkFlBJ3kzqVS0hK/HGyYWI4HU6sAzxgZ6x1+brbj+nIVUO2JV7c1 otpuzzE/AB6y+wanb/j/gcwosIXAad5LYpoXNagIZL87ZUkPwq3rfLIJ9F+wo+Tw3+LP YoaS2/YIexg0E8rJOzWTtdPAZgz+u5/nkia9s9QfgHErZzUR1EudwbCtyzHEHgVCFm7O p4PTXDlSTCMUIKrF9UT5TARRe+LfCsGkDfEaK2pUVZHrxGhGzPofmbj77yqpld7qgfZF VZBVkZnHSG4uZMctSc5hF7pOAU0EUprrk4wVaUFoC9atCiu8PeXZHzfP0S7po12xgUkg 9ZLQ== X-Gm-Message-State: AOJu0YyZbvrNv5uVOzDZejebuY1I3VPR0Gr1cIxbjL9jFPKVGHbstFlK ZZhh0qMce9kkrlP/eEls6WjOOA== X-Google-Smtp-Source: AGHT+IHGQbme9+SUFaGqtXxW3dpwxnbADbFKKzuXkjeBXh8SM/R1CUkQJ1X6e1o6BdROvLlqkFtmJw== X-Received: by 2002:a17:902:e5c1:b0:1b3:d8ac:8db3 with SMTP id u1-20020a170902e5c100b001b3d8ac8db3mr11070242plf.6.1694425867096; Mon, 11 Sep 2023 02:51:07 -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.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:06 -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 Subject: [PATCH v6 39/45] mm: shrinker: remove old APIs Date: Mon, 11 Sep 2023 17:44:38 +0800 Message-Id: <20230911094444.68966-40-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: 2A1814001C X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: h66uutomg59ijmmcycbc3efwyp43yb1c X-HE-Tag: 1694425867-527177 X-HE-Meta: U2FsdGVkX180it09w7xQZpOEkDTyc/ZXcGtyjLJb30ZiuihnXgSlNr2cClKJvtb905gHmWzTZlXfd6l9sGaeByGAmkeYEElW4h/3s32eRQ8sON1DB7f5cfPPN1DCrtweNVIHAuER0ms9J4KgsRrdR2Dp+mVPhZK9OBe9suug2NHLFfvmgwr4Z7fWcvIFvGv2BmrG3KHhkyAjUYN5d7ac3uBDQLNKz1mZ8V7Ap8HgyzltrAgmqrHnZzIHcK1Pt5dnyldiawL/VwMkdmZkB65cpGyPTXr/7BsXJG39GZSy5sRHwoOpuyDkBblKfYzxe5LiqoVitoz7ZpV21auEXfI0IWCkmmzxm7xxCCBswfO8cSo6Gpe76a/DhpgRO0ZEsl7OxJLGjhNTKfK4VVOmVKFH1iErtEtc8E3DMqhukUAr4kmNivl/lKFZJgrfL/2zGY4RrQk99i/pFj87ze2ysSvlL0SV6bvuLg9m/ZyU3wL24ryrMSuqaZlQfq+pCHLhov8pJObu3GUud7DdeDhKPpIm9ifTTIIjWiCFhlzYqGyQJfW9+UjzqVkF7c2tdNTwaMzVRxlotR9H+l0PJ4ZAnIS8obKCftF2kQu8S0SNYwZme/4kHegeDakSe//pXtTG+Ug/gnV+R9a/0fXBaD1LlvoFHNF6cSe/BxKZLJNSnQ8ttlfTeEQWAXURUW1QW/w9wgmFEdC8BRPDZbcaSrH5J887UuHMP0KFE+FVzViiN9hPHhit70iFU60T03oJYmTVxCrftwiKezp3nJzacmf+CpoFOXxQcwLhymBU1v0n694gcBl9S5JRswWSzhvKM0npb5ArGzD6cd8B/pZYHoFWlROVZvI8WYOOwqNGr2EXcCsnFfg/beEaDUcsrPWdPwobxIXcUmPEMaHUaDtKXz2Wl8nc/861t89h+Qu8PpKmyzUIrMSjfdgEFFSCupd/avXv0qcnaKJ58k+iPop6ZPLwCNC 6YE5Axvb OCzvLF1+FjPxGtrOrYK5OJKPndy3x0FLCYd/RydiE7f0VYHEPCd9MYF5O3qRYFJvrU8ZiUCz8mO2KIiyuAvbpJ4cW/VG3bNLvJQV2gkc4yGdAQTbs4TV5vjYYXsAQLXxgdbn5Bnb8MHAfy8oR2oAVE/1zWCi/B1JchHkjMLpneVCXuiorvlbWvuQGrt4MvqYUJ7a73ezdP7WjdLSUod8D+84DjWLFOxDlwL2cvxuaLFAskxajWJpGIU1mkwcau0buIJVAASLpD0ZI27IfnnjQKVYCEyzxmvsRh4s9nPV1m9ADeUHLCDHHM3LmVeFOYRhHvxOfH+CoqtkHttvB7urpyO8X+Oahw0be/ODjLqgGKj0vM15FanADVOi4uuBDx50YmooG8rlkDhyJMYYSIFxOzxQ9PG3LlsXjjZuw 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: Now no users are using the old APIs, just remove them. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/linux/shrinker.h | 8 --- mm/shrinker.c | 143 --------------------------------------- 2 files changed, 151 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 3f3fd9974ce5..025c8070dd86 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -103,14 +103,6 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); -extern int __printf(2, 3) prealloc_shrinker(struct shrinker *shrinker, - const char *fmt, ...); -extern void register_shrinker_prepared(struct shrinker *shrinker); -extern int __printf(2, 3) register_shrinker(struct shrinker *shrinker, - const char *fmt, ...); -extern void unregister_shrinker(struct shrinker *shrinker); -extern void free_prealloced_shrinker(struct shrinker *shrinker); - #ifdef CONFIG_SHRINKER_DEBUG extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/shrinker.c b/mm/shrinker.c index 201211a67827..d75be41b8a5f 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -651,146 +651,3 @@ void shrinker_free(struct shrinker *shrinker) kfree(shrinker); } EXPORT_SYMBOL_GPL(shrinker_free); - -/* - * Add a shrinker callback to be called from the vm. - */ -static int __prealloc_shrinker(struct shrinker *shrinker) -{ - unsigned int size; - int err; - - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - err = prealloc_memcg_shrinker(shrinker); - if (err != -ENOSYS) - return err; - - shrinker->flags &= ~SHRINKER_MEMCG_AWARE; - } - - size = sizeof(*shrinker->nr_deferred); - if (shrinker->flags & SHRINKER_NUMA_AWARE) - size *= nr_node_ids; - - shrinker->nr_deferred = kzalloc(size, GFP_KERNEL); - if (!shrinker->nr_deferred) - return -ENOMEM; - - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __prealloc_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - - return err; -} -#else -int prealloc_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __prealloc_shrinker(shrinker); -} -#endif - -void free_prealloced_shrinker(struct shrinker *shrinker) -{ -#ifdef CONFIG_SHRINKER_DEBUG - kfree_const(shrinker->name); - shrinker->name = NULL; -#endif - if (shrinker->flags & SHRINKER_MEMCG_AWARE) { - down_write(&shrinker_rwsem); - unregister_memcg_shrinker(shrinker); - up_write(&shrinker_rwsem); - return; - } - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} - -void register_shrinker_prepared(struct shrinker *shrinker) -{ - down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); - shrinker->flags |= SHRINKER_REGISTERED; - shrinker_debugfs_add(shrinker); - up_write(&shrinker_rwsem); -} - -static int __register_shrinker(struct shrinker *shrinker) -{ - int err = __prealloc_shrinker(shrinker); - - if (err) - return err; - register_shrinker_prepared(shrinker); - return 0; -} - -#ifdef CONFIG_SHRINKER_DEBUG -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - va_list ap; - int err; - - va_start(ap, fmt); - shrinker->name = kvasprintf_const(GFP_KERNEL, fmt, ap); - va_end(ap); - if (!shrinker->name) - return -ENOMEM; - - err = __register_shrinker(shrinker); - if (err) { - kfree_const(shrinker->name); - shrinker->name = NULL; - } - return err; -} -#else -int register_shrinker(struct shrinker *shrinker, const char *fmt, ...) -{ - return __register_shrinker(shrinker); -} -#endif -EXPORT_SYMBOL(register_shrinker); - -/* - * Remove one - */ -void unregister_shrinker(struct shrinker *shrinker) -{ - struct dentry *debugfs_entry; - int debugfs_id; - - if (!(shrinker->flags & SHRINKER_REGISTERED)) - return; - - down_write(&shrinker_rwsem); - list_del(&shrinker->list); - shrinker->flags &= ~SHRINKER_REGISTERED; - if (shrinker->flags & SHRINKER_MEMCG_AWARE) - unregister_memcg_shrinker(shrinker); - debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); - up_write(&shrinker_rwsem); - - shrinker_debugfs_remove(debugfs_entry, debugfs_id); - - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; -} -EXPORT_SYMBOL(unregister_shrinker); From patchwork Mon Sep 11 09:44:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379116 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 6624BEEB57E for ; Mon, 11 Sep 2023 09:51:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 061E96B0269; Mon, 11 Sep 2023 05:51:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 011F56B026A; Mon, 11 Sep 2023 05:51:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF4D46B026B; Mon, 11 Sep 2023 05:51:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CECBD6B0269 for ; Mon, 11 Sep 2023 05:51:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 99E63C098C for ; Mon, 11 Sep 2023 09:51:17 +0000 (UTC) X-FDA: 81223848594.12.026F5EC Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf01.hostedemail.com (Postfix) with ESMTP id AC87140005 for ; Mon, 11 Sep 2023 09:51:15 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XmaQCZfL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425875; a=rsa-sha256; cv=none; b=Ld4fwTvFD78miNuPvQFf0m2i9wdAdpbyu4veTzXwDsipVv5DGfPs6HZDN9SQWLjULQRJx0 pJB7yg4GMzjdnfjcTAQXNn6nh3nRuB57vaeC9R72qrAhXLQrgpGzsrY+StAGBIRQLhu2ms RtslUv4JAeye4iMhHB60Vu39IElzAi4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=XmaQCZfL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 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=1694425875; 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=yMaXJkje3i/zFJo6Lh17j4Pm7mCYv4E0cjAurLUuXbw=; b=ViKplrwD/uKRMmr56s76ONuNIimwC4Oa1bIf+ezDQlN+8U9eQ5K8pCTagoKamxxXgyAADC 914KQk3fryHqk/tOzntCKPlBBe8DlRpXlI//dxWLZvs7hSPpg8AgqqURlSK4q99CDKSU+H KruaGP7CUd5lanXywkl5opDhdx/D2YY= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1c0efe0c4acso7092245ad.0 for ; Mon, 11 Sep 2023 02:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425874; x=1695030674; 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=yMaXJkje3i/zFJo6Lh17j4Pm7mCYv4E0cjAurLUuXbw=; b=XmaQCZfLxbupypS5DxAkLTEuxcpfbrMH9HLqZvFFuVgxeWY91pdqcwPRZ/ER+RDHRe fgIGOPemXMm5eVG+N5IXU2/JteX1csbO356+Vs0akkMMKQy36+agJ/GuTK6TCWZNRpaU K8HK4jHcByqMSYLPQfjee4/FweI2iqUsR1FA8F5u731TP50r86avkwYB2gUbr06SW3Y9 i6lYERW/c2wS8Ni9FfrFJayTYCaWoomncHVmsXE9mHYV2sbv9WxGgvbO0VmcGLM0gfCM A6vNtMyPUTQF6zUd/+Rk6Ie6PNUoTZBVjvGlPRlukljdQMSPro6edEjKKIco2UjV9gms +iYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425874; x=1695030674; 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=yMaXJkje3i/zFJo6Lh17j4Pm7mCYv4E0cjAurLUuXbw=; b=BSQw30q1VhMTBsiSj16spUsPoyrPgV799qubV9eQ/XFbQAupUEI+fYJfpHW6YJzJe0 UgHNMb/m0sjgjynk8GesBDkSj//UcMIZWbGP+yDX9R/K6M9JeNqYe71bUaS8uEHTLCc2 1+ccgjRUNtxbYbhZKtwbEE1oKKyPYfC4yqKhpi4fJUpHHE1pyi6ufj0pAXFlLGmCvuET 5WhP4Fwm1MmGjzq1c1WYbbyvQ1MrG7LkH75VMrv5KB5K+yOHtvELBdCLjMatU0dBYsPI 4eYYMWNeQxeA0+q4NXQ/qMqdLk3gdaezkTvW6FkGPhexolSBkPkwh7qqi9hcCqvGb1bH Josw== X-Gm-Message-State: AOJu0YyYUm8Bxphey761a7ZfEZKZAO52CZ2pUeRVVEno/wz/Ni4exKUh 5/nn34trXV6ZRH9CRvlTMfGgdQ== X-Google-Smtp-Source: AGHT+IHz9tDgQYYObWI9lwQr6rXGL3w6VteEfJwZzap+sfysA5KeWyXP08u/4VZWYH1QEEehgDiD8A== X-Received: by 2002:a17:902:d48d:b0:1c2:c60:8388 with SMTP id c13-20020a170902d48d00b001c20c608388mr11588743plg.6.1694425874532; Mon, 11 Sep 2023 02:51:14 -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.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:14 -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 Subject: [PATCH v6 40/45] mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred} Date: Mon, 11 Sep 2023 17:44:39 +0800 Message-Id: <20230911094444.68966-41-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AC87140005 X-Stat-Signature: 6qogak38fgsk5eswfoujmedyekz3rorm X-HE-Tag: 1694425875-466989 X-HE-Meta: U2FsdGVkX1+4Lz2xmebpS03nNo5EHnD0U3QA+iKVAzMrHIurKElLpYLDrphkpr5itjZv6apppKAF0uEyXOxEsFmL08e9jMCuYik+CohIBgQAdQkL9Hk2ryZ5dkAYgUPWVm5+oYNT4gEQx9P4VNNmwDQd7X0YjsjkyWYZiazqQXwoT50PCoAnuvfBGVU9VwsjCDyixRyttQedybNT/E1XeLBxmi1AlaT7oXWNbph6je/xFgUuxIqEd5licolMA4lfxt6v3jQIe2n0pN4H+Nj2mb4I3i/mEsvyeObWCGFcuEHdDj0ZVqwCg2i3x9hZCgovcv79cp4jmVkC3dIRMKKR+tQloJ4AUzfJ+LeRSvqHoHdHWyhxVA1A4a/EnM7UAQENQVhmH3Up/L1uCAnWLVLM5OlOOy7yCBv3nvP/vnGhDFEdkLVQUsNFnbgdzM03fFeiiecXCi228rxW0wbp3YDEisTlkr8oKBh+fs2PcQ4jK4CzB8Buskxui/KYrUZH4T6lDsaliXUNUyFAYkM+5bc4/MOylArr4ST/1XNWGFWuHWeyYlpwwWfn0PTaLANYRQnkrKygD6RfCYGYWVSyYT8/B3mo2ynMlMTBB2XwTLt0IKdM7Zs6qmslvi1tmt6JpYXdQS+wWFToUk9tmVvTxKkkatYmvVufzvk++KZ9MFm3/4ylhjqW/O0Vdce/yUfb4qd++xZFViJtcifWJWYHE6GyQDC3AtMuMg75KsIgBJakbzxcgrMPO1agIOXFj7Xqp8Sl9BmwBTYmTtahje3t8rYtyh8kYLu38B/Ee56bFnbhFuMnLC0uGTRaPVyCgGB6cIyY4niI8AJkMa900Qw8f4tnqO240exRv2tMtyXEr5ehqZMe+cotLbOScZerZ+n8Vc0duZbV6K/Lfb05ocGzSXz2XdzTdk+pZe8hDWrg5/Nd1NjGIupJJzFbBGNRzX81C4KEUYBINta3it9VtS3Llcn 3ksawPGq umVF4/BGwzabhAqQq5jXv1xkbm/4pRKJghCwaAQLzvWGbeI3rwZvHtbZgqRgR7oxBtGTrU7fLtQqeYlwO4oknc5bF+USQIqI4FnbBtiLh4rOz/2gSGAlWTSpVGxSE7lRSKzcSZkpX//xZIwMFchTy4lR5UCE8NSKwNatUSz+PNC+9ZLy4hfFuVwZGUw9olAvRsXa876qiCaBnu9hwHg3Y3n6wvWIM2YDx3yGshsVF8EEL7nvKmH1f7iQyvBMuETWuClWfgTaLZY7cIWcsvd5OEDfAs+MZi5ZQ2XowiitSCIiea2WV3d3JLVClMl5+15fkDBrwnxcXPKq2GU2GQUloBreVqu10Ajez5QaOe4lPnyffvNk9fKXeECr+RiqhlgmZUG4vrq6crWemWvbeji1kRl7Mp3f/enVrlmTe6TJpVYgJ/Cm6SHQO8ptnomaynJN1FgzvR2nk7n6KiOxL1WJzG3nkA7YYtaL95dyOQDGcCFpuzxiONvvPxksFM/tHuwGW0BwLMueLkxCwoBH0Ug0xth6VaA== 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: Currently, we maintain two linear arrays per node per memcg, which are shrinker_info::map and shrinker_info::nr_deferred. And we need to resize them when the shrinker_nr_max is exceeded, that is, allocate a new array, and then copy the old array to the new array, and finally free the old array by RCU. For shrinker_info::map, we do set_bit() under the RCU lock, so we may set the value into the old map which is about to be freed. This may cause the value set to be lost. The current solution is not to copy the old map when resizing, but to set all the corresponding bits in the new map to 1. This solves the data loss problem, but bring the overhead of more pointless loops while doing memcg slab shrink. For shrinker_info::nr_deferred, we will only modify it under the read lock of shrinker_rwsem, so it will not run concurrently with the resizing. But after we make memcg slab shrink lockless, there will be the same data loss problem as shrinker_info::map, and we can't work around it like the map. For such resizable arrays, the most straightforward idea is to change it to xarray, like we did for list_lru [1]. We need to do xa_store() in the list_lru_add()-->set_shrinker_bit(), but this will cause memory allocation, and the list_lru_add() doesn't accept failure. A possible solution is to pre-allocate, but the location of pre-allocation is not well determined (such as deferred_split_shrinker case). Therefore, this commit chooses to introduce the following secondary array for shrinker_info::{map, nr_deferred}: +---------------+--------+--------+-----+ | shrinker_info | unit 0 | unit 1 | ... | (secondary array) +---------------+--------+--------+-----+ | v +---------------+-----+ | nr_deferred[] | map | (leaf array) +---------------+-----+ (shrinker_info_unit) The leaf array is never freed unless the memcg is destroyed. The secondary array will be resized every time the shrinker id exceeds shrinker_nr_max. So the shrinker_info_unit can be indexed from both the old and the new shrinker_info->unit[x]. Then even if we get the old secondary array under the RCU lock, the found map and nr_deferred are also true, so the updated nr_deferred and map will not be lost. [1]. https://lore.kernel.org/all/20220228122126.37293-13-songmuchun@bytedance.com/ Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- include/linux/memcontrol.h | 12 +- include/linux/shrinker.h | 17 +++ mm/shrinker.c | 249 +++++++++++++++++++++++-------------- 3 files changed, 171 insertions(+), 107 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index ab94ad4597d0..67b823dfa47d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -21,6 +21,7 @@ #include #include #include +#include struct mem_cgroup; struct obj_cgroup; @@ -88,17 +89,6 @@ struct mem_cgroup_reclaim_iter { unsigned int generation; }; -/* - * Bitmap and deferred work of shrinker::id corresponding to memcg-aware - * shrinkers, which have elements charged to this memcg. - */ -struct shrinker_info { - struct rcu_head rcu; - atomic_long_t *nr_deferred; - unsigned long *map; - int map_nr_max; -}; - struct lruvec_stats_percpu { /* Local (CPU and cgroup) state */ long state[NR_VM_NODE_STAT_ITEMS]; diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 025c8070dd86..eb342994675a 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -5,6 +5,23 @@ #include #include +#define SHRINKER_UNIT_BITS BITS_PER_LONG + +/* + * Bitmap and deferred work of shrinker::id corresponding to memcg-aware + * shrinkers, which have elements charged to the memcg. + */ +struct shrinker_info_unit { + atomic_long_t nr_deferred[SHRINKER_UNIT_BITS]; + DECLARE_BITMAP(map, SHRINKER_UNIT_BITS); +}; + +struct shrinker_info { + struct rcu_head rcu; + int map_nr_max; + struct shrinker_info_unit *unit[]; +}; + /* * This struct is used to pass information from page reclaim to the shrinkers. * We consolidate the values for easier extension later. diff --git a/mm/shrinker.c b/mm/shrinker.c index d75be41b8a5f..6723a8f4228c 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -12,15 +12,50 @@ DECLARE_RWSEM(shrinker_rwsem); #ifdef CONFIG_MEMCG static int shrinker_nr_max; -/* The shrinker_info is expanded in a batch of BITS_PER_LONG */ -static inline int shrinker_map_size(int nr_items) +static inline int shrinker_unit_size(int nr_items) { - return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); + return (DIV_ROUND_UP(nr_items, SHRINKER_UNIT_BITS) * sizeof(struct shrinker_info_unit *)); } -static inline int shrinker_defer_size(int nr_items) +static inline void shrinker_unit_free(struct shrinker_info *info, int start) { - return (round_up(nr_items, BITS_PER_LONG) * sizeof(atomic_long_t)); + struct shrinker_info_unit **unit; + int nr, i; + + if (!info) + return; + + unit = info->unit; + nr = DIV_ROUND_UP(info->map_nr_max, SHRINKER_UNIT_BITS); + + for (i = start; i < nr; i++) { + if (!unit[i]) + break; + + kfree(unit[i]); + unit[i] = NULL; + } +} + +static inline int shrinker_unit_alloc(struct shrinker_info *new, + struct shrinker_info *old, int nid) +{ + struct shrinker_info_unit *unit; + int nr = DIV_ROUND_UP(new->map_nr_max, SHRINKER_UNIT_BITS); + int start = old ? DIV_ROUND_UP(old->map_nr_max, SHRINKER_UNIT_BITS) : 0; + int i; + + for (i = start; i < nr; i++) { + unit = kzalloc_node(sizeof(*unit), GFP_KERNEL, nid); + if (!unit) { + shrinker_unit_free(new, start); + return -ENOMEM; + } + + new->unit[i] = unit; + } + + return 0; } void free_shrinker_info(struct mem_cgroup *memcg) @@ -32,6 +67,7 @@ void free_shrinker_info(struct mem_cgroup *memcg) for_each_node(nid) { pn = memcg->nodeinfo[nid]; info = rcu_dereference_protected(pn->shrinker_info, true); + shrinker_unit_free(info, 0); kvfree(info); rcu_assign_pointer(pn->shrinker_info, NULL); } @@ -40,28 +76,27 @@ void free_shrinker_info(struct mem_cgroup *memcg) int alloc_shrinker_info(struct mem_cgroup *memcg) { struct shrinker_info *info; - int nid, size, ret = 0; - int map_size, defer_size = 0; + int nid, ret = 0; + int array_size = 0; down_write(&shrinker_rwsem); - map_size = shrinker_map_size(shrinker_nr_max); - defer_size = shrinker_defer_size(shrinker_nr_max); - size = map_size + defer_size; + array_size = shrinker_unit_size(shrinker_nr_max); for_each_node(nid) { - info = kvzalloc_node(sizeof(*info) + size, GFP_KERNEL, nid); - if (!info) { - free_shrinker_info(memcg); - ret = -ENOMEM; - break; - } - info->nr_deferred = (atomic_long_t *)(info + 1); - info->map = (void *)info->nr_deferred + defer_size; + info = kvzalloc_node(sizeof(*info) + array_size, GFP_KERNEL, nid); + if (!info) + goto err; info->map_nr_max = shrinker_nr_max; + if (shrinker_unit_alloc(info, NULL, nid)) + goto err; rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); } up_write(&shrinker_rwsem); return ret; + +err: + free_shrinker_info(memcg); + return -ENOMEM; } static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, @@ -71,15 +106,12 @@ static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, lockdep_is_held(&shrinker_rwsem)); } -static int expand_one_shrinker_info(struct mem_cgroup *memcg, - int map_size, int defer_size, - int old_map_size, int old_defer_size, - int new_nr_max) +static int expand_one_shrinker_info(struct mem_cgroup *memcg, int new_size, + int old_size, int new_nr_max) { struct shrinker_info *new, *old; struct mem_cgroup_per_node *pn; int nid; - int size = map_size + defer_size; for_each_node(nid) { pn = memcg->nodeinfo[nid]; @@ -92,21 +124,17 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, if (new_nr_max <= old->map_nr_max) continue; - new = kvmalloc_node(sizeof(*new) + size, GFP_KERNEL, nid); + new = kvmalloc_node(sizeof(*new) + new_size, GFP_KERNEL, nid); if (!new) return -ENOMEM; - new->nr_deferred = (atomic_long_t *)(new + 1); - new->map = (void *)new->nr_deferred + defer_size; new->map_nr_max = new_nr_max; - /* map: set all old bits, clear all new bits */ - memset(new->map, (int)0xff, old_map_size); - memset((void *)new->map + old_map_size, 0, map_size - old_map_size); - /* nr_deferred: copy old values, clear all new values */ - memcpy(new->nr_deferred, old->nr_deferred, old_defer_size); - memset((void *)new->nr_deferred + old_defer_size, 0, - defer_size - old_defer_size); + memcpy(new->unit, old->unit, old_size); + if (shrinker_unit_alloc(new, old, nid)) { + kvfree(new); + return -ENOMEM; + } rcu_assign_pointer(pn->shrinker_info, new); kvfree_rcu(old, rcu); @@ -118,9 +146,8 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, static int expand_shrinker_info(int new_id) { int ret = 0; - int new_nr_max = round_up(new_id + 1, BITS_PER_LONG); - int map_size, defer_size = 0; - int old_map_size, old_defer_size = 0; + int new_nr_max = round_up(new_id + 1, SHRINKER_UNIT_BITS); + int new_size, old_size = 0; struct mem_cgroup *memcg; if (!root_mem_cgroup) @@ -128,15 +155,12 @@ static int expand_shrinker_info(int new_id) lockdep_assert_held(&shrinker_rwsem); - map_size = shrinker_map_size(new_nr_max); - defer_size = shrinker_defer_size(new_nr_max); - old_map_size = shrinker_map_size(shrinker_nr_max); - old_defer_size = shrinker_defer_size(shrinker_nr_max); + new_size = shrinker_unit_size(new_nr_max); + old_size = shrinker_unit_size(shrinker_nr_max); memcg = mem_cgroup_iter(NULL, NULL, NULL); do { - ret = expand_one_shrinker_info(memcg, map_size, defer_size, - old_map_size, old_defer_size, + ret = expand_one_shrinker_info(memcg, new_size, old_size, new_nr_max); if (ret) { mem_cgroup_iter_break(NULL, memcg); @@ -150,17 +174,34 @@ static int expand_shrinker_info(int new_id) return ret; } +static inline int shrinker_id_to_index(int shrinker_id) +{ + return shrinker_id / SHRINKER_UNIT_BITS; +} + +static inline int shrinker_id_to_offset(int shrinker_id) +{ + return shrinker_id % SHRINKER_UNIT_BITS; +} + +static inline int calc_shrinker_id(int index, int offset) +{ + return index * SHRINKER_UNIT_BITS + offset; +} + void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) { if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) { struct shrinker_info *info; + struct shrinker_info_unit *unit; rcu_read_lock(); info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); + unit = info->unit[shrinker_id_to_index(shrinker_id)]; if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { /* Pairs with smp mb in shrink_slab() */ smp_mb__before_atomic(); - set_bit(shrinker_id, info->map); + set_bit(shrinker_id_to_offset(shrinker_id), unit->map); } rcu_read_unlock(); } @@ -209,26 +250,31 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, struct mem_cgroup *memcg) { struct shrinker_info *info; + struct shrinker_info_unit *unit; info = shrinker_info_protected(memcg, nid); - return atomic_long_xchg(&info->nr_deferred[shrinker->id], 0); + unit = info->unit[shrinker_id_to_index(shrinker->id)]; + return atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(shrinker->id)], 0); } static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, struct mem_cgroup *memcg) { struct shrinker_info *info; + struct shrinker_info_unit *unit; info = shrinker_info_protected(memcg, nid); - return atomic_long_add_return(nr, &info->nr_deferred[shrinker->id]); + unit = info->unit[shrinker_id_to_index(shrinker->id)]; + return atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(shrinker->id)]); } void reparent_shrinker_deferred(struct mem_cgroup *memcg) { - int i, nid; + int nid, index, offset; long nr; struct mem_cgroup *parent; struct shrinker_info *child_info, *parent_info; + struct shrinker_info_unit *child_unit, *parent_unit; parent = parent_mem_cgroup(memcg); if (!parent) @@ -239,9 +285,13 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); - for (i = 0; i < child_info->map_nr_max; i++) { - nr = atomic_long_read(&child_info->nr_deferred[i]); - atomic_long_add(nr, &parent_info->nr_deferred[i]); + for (index = 0; index < shrinker_id_to_index(child_info->map_nr_max); index++) { + child_unit = child_info->unit[index]; + parent_unit = parent_info->unit[index]; + for (offset = 0; offset < SHRINKER_UNIT_BITS; offset++) { + nr = atomic_long_read(&child_unit->nr_deferred[offset]); + atomic_long_add(nr, &parent_unit->nr_deferred[offset]); + } } } up_read(&shrinker_rwsem); @@ -407,7 +457,7 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, { struct shrinker_info *info; unsigned long ret, freed = 0; - int i; + int offset, index = 0; if (!mem_cgroup_online(memcg)) return 0; @@ -419,56 +469,63 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, if (unlikely(!info)) goto unlock; - for_each_set_bit(i, info->map, info->map_nr_max) { - struct shrink_control sc = { - .gfp_mask = gfp_mask, - .nid = nid, - .memcg = memcg, - }; - struct shrinker *shrinker; + for (; index < shrinker_id_to_index(info->map_nr_max); index++) { + struct shrinker_info_unit *unit; - shrinker = idr_find(&shrinker_idr, i); - if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { - if (!shrinker) - clear_bit(i, info->map); - continue; - } + unit = info->unit[index]; - /* Call non-slab shrinkers even though kmem is disabled */ - if (!memcg_kmem_online() && - !(shrinker->flags & SHRINKER_NONSLAB)) - continue; + for_each_set_bit(offset, unit->map, SHRINKER_UNIT_BITS) { + struct shrink_control sc = { + .gfp_mask = gfp_mask, + .nid = nid, + .memcg = memcg, + }; + struct shrinker *shrinker; + int shrinker_id = calc_shrinker_id(index, offset); - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) { - clear_bit(i, info->map); - /* - * After the shrinker reported that it had no objects to - * free, but before we cleared the corresponding bit in - * the memcg shrinker map, a new object might have been - * added. To make sure, we have the bit set in this - * case, we invoke the shrinker one more time and reset - * the bit if it reports that it is not empty anymore. - * The memory barrier here pairs with the barrier in - * set_shrinker_bit(): - * - * list_lru_add() shrink_slab_memcg() - * list_add_tail() clear_bit() - * - * set_bit() do_shrink_slab() - */ - smp_mb__after_atomic(); - ret = do_shrink_slab(&sc, shrinker, priority); - if (ret == SHRINK_EMPTY) - ret = 0; - else - set_shrinker_bit(memcg, nid, i); - } - freed += ret; + shrinker = idr_find(&shrinker_idr, shrinker_id); + if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { + if (!shrinker) + clear_bit(offset, unit->map); + continue; + } - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; + /* Call non-slab shrinkers even though kmem is disabled */ + if (!memcg_kmem_online() && + !(shrinker->flags & SHRINKER_NONSLAB)) + continue; + + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) { + clear_bit(offset, unit->map); + /* + * After the shrinker reported that it had no objects to + * free, but before we cleared the corresponding bit in + * the memcg shrinker map, a new object might have been + * added. To make sure, we have the bit set in this + * case, we invoke the shrinker one more time and reset + * the bit if it reports that it is not empty anymore. + * The memory barrier here pairs with the barrier in + * set_shrinker_bit(): + * + * list_lru_add() shrink_slab_memcg() + * list_add_tail() clear_bit() + * + * set_bit() do_shrink_slab() + */ + smp_mb__after_atomic(); + ret = do_shrink_slab(&sc, shrinker, priority); + if (ret == SHRINK_EMPTY) + ret = 0; + else + set_shrinker_bit(memcg, nid, shrinker_id); + } + freed += ret; + + if (rwsem_is_contended(&shrinker_rwsem)) { + freed = freed ? : 1; + goto unlock; + } } } unlock: From patchwork Mon Sep 11 09:44:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379117 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 BBF5BEE57DF for ; Mon, 11 Sep 2023 09:51:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A76D6B026B; Mon, 11 Sep 2023 05:51:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 458446B026C; Mon, 11 Sep 2023 05:51:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 320146B026D; Mon, 11 Sep 2023 05:51:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 213BF6B026B for ; Mon, 11 Sep 2023 05:51:25 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E6FBC140920 for ; Mon, 11 Sep 2023 09:51:24 +0000 (UTC) X-FDA: 81223848888.16.D2FA528 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf01.hostedemail.com (Postfix) with ESMTP id 2D91040006 for ; Mon, 11 Sep 2023 09:51:22 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=QVsT1bLA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.173 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=1694425883; 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=uv0TBZQkv9+j+cj13JOsDOVxquETdMy4ZuA8JAVbwFY=; b=1h5ZhId7aCCvU79ko0vQlSbbUufNrkR/9djXEIe0h+0Vurjal1FWTKOL7fBrvAeabUj/Cd btioQasBrqRZc7hU/xXd9rYsXZqSQo1u+TeQqaYqHMeOuzdWask1dzI1tM9piL59b3EKJ7 EV3RI4dEn32/PyvRh2JrfW1DjffrDxE= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=QVsT1bLA; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425883; a=rsa-sha256; cv=none; b=3A9xMz8pS8/716P6M2WTeZl/WYD5jTjbk86YBgRsIZgJPQWwhMYjFYtgZYXEXwv4f1H1Ej ikK8B6XhLgu/J+4Apaud+GQmjeuZvSncPQUDTB6xNuGr6JlkrPGcqFdZeek5nw1iVO1E3B 5nuX5kN1ScEy2OXNHmti7jk7lBU+0SM= Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-56f8334f15eso230609a12.1 for ; Mon, 11 Sep 2023 02:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425882; x=1695030682; 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=uv0TBZQkv9+j+cj13JOsDOVxquETdMy4ZuA8JAVbwFY=; b=QVsT1bLArsqVzOxk3Hf4Ig0H6y4klcLex+23rIAVO4IThWwznW8/lkMUf8R5tLEyJz ZyaRopN2zCzbfrXdRfbVL8TjthFVdmpijNhVQHatEu8TGm8XxJvt4KoTSx3QP8uCbB0L hl4NTDKEfC6+sKaVOHJgB4kCZc49FGFZyu0CaR0eXXYyDAnKDqSlIU0ckliodDKoJiEO tn3kkQ5MlRNudmIOD63JTVRpPHiHhGofpKdXmlXjgoaohZ3uelbs4L53bCu93m8jkdrE qokNVOS0qM8jV60W4WXj9xTirAMyj0vKito/gipj4XbIW7+Q8l8eySDDmcVlfb7IgLZR tcNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425882; x=1695030682; 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=uv0TBZQkv9+j+cj13JOsDOVxquETdMy4ZuA8JAVbwFY=; b=H8SSC1IE1cydj/Vm7wIwSH+eaGG6E2SXCwymIzhKGQOvuOkMWIrPtavy1qYy9kAs0p 8mRrRJrNu+4nRVfEiXMkc/XbtaR0FJqS4M8H06WXF70KNgACjM8tizB8cELPtzxJ2DqA 39KoVLwXHkv6nlaS3c8EgOBfmGuCLHarDthHqIZnN6zDWNpT5zr5qCnLupPovd0GoxJs Qw5h0+A80ewDxCVtuv9Eu0HAbN3nT7R92DUbwJYKO0VdkfDaxEFHJqntlN0jO05tZnAc UBUWx63WzpvvIUkF8RnoOnlhFKf+Y31AOyomsq40IrkW92mJ+bczE++RAmwBS0WXynsU p51g== X-Gm-Message-State: AOJu0YxrNy/0odKa+CimrEEHbtrMOIWJHcAR6pZuoUIKmPLMQtFV8QoS LHswABL6bFyF471H09Lo8QFTdzwQSCtTFqu6WEY= X-Google-Smtp-Source: AGHT+IGKTvJsG+anhHgOhq4RXbEUzLj3hzjixmIPwpl+H2L5Yrr+lM0cdITBVAyo+CVp3tsEVeU2xg== X-Received: by 2002:a05:6a20:a10c:b0:13f:9233:58d with SMTP id q12-20020a056a20a10c00b0013f9233058dmr11709606pzk.2.1694425882074; Mon, 11 Sep 2023 02:51:22 -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.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:21 -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 Subject: [PATCH v6 41/45] mm: shrinker: rename {prealloc|unregister}_memcg_shrinker() to shrinker_memcg_{alloc|remove}() Date: Mon, 11 Sep 2023 17:44:40 +0800 Message-Id: <20230911094444.68966-42-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: 2D91040006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: p45qph17d1jzrf44fo57351zahupx4q4 X-HE-Tag: 1694425882-684119 X-HE-Meta: U2FsdGVkX1/Fix7L0/fvOV9uqVKwT9K3WAMAmkE7YkXczyromahc0GSzZFiuzMay4nBC6bldxwykvp555T5kp0YHg/oypS4/JAdLwnDr3mnDipWlgEfypl3HnMaQ/DCtmqibngP+L+8OjYIQNMhbjhOq7uy8jZ5DXmOCFHC5jXp9xEtdh2sPJB63v8EW/guSAC8JR0Wbofg0TrGsX7Rrg8toTuyqMqkackFVucvc540ODvFCvYuA514jbhFwJe2wcTK/9Y61r5GQvHDmxfXkG4unLQTM4XA2QL4CqqtL53vDg9H70gBF+KdIYBWBCFGYuotgDPA3FaI7DoKxqLXWM7zbvmO8QvEVJTXgRUwhJLxV28gh/yK6Jmpr26wIZpN26IqDaYYuBWQe/fNAqIoSz1EQcCK2YOGoEXaILYUil4PXXJB7pDdSShWYnTIMUVsOsp9eItApukHz0EAfP/MKL33h9g7I5dnu6ZAUP/GDs/PkGavow30LIZ+NTA6LOfduH+6/gi7bGV1lBlqAmdsLguerYGo3wNW91cnokzyHyBCrnM890RMgpeLEfveidKJ5pTvtEWVTDgEYYKxl+YuL5kaTRMgLcym8VIgaHQzf1WR+EGuPfZe6ro+cbidfyb8Ys+Mb0gzEsnxVD28aea/sQdKCl3I9UbdNYLwg9UjUpk7b3h8FG3yPXDCotrxCvxW0XTH9TRoplBA288l4iVnq3TIjwp32ISx9CTy4t+ZqOUzvPZU7LQpehTdPEd7zgtE/VHrCM+6YdCEiIhs+W1WN2McOn9aPNzXFJF84or+RAI6j1V7PCfGKzfccL9GAeghzIdQAJtYnH5tCbURF0OHVQ16SwDA5jIGWJQXS6N1Fd05g9O1Tt4gRovh1Ig1ho1u2y5s3plTDbX+jOE+1Uc1fA1RRhuuCo+pDeNHxYkw6qFB1TgOOQM7Yt6joC86ci8kcOxwcmbT59PWaXCL102Q 2qpLzHLt 2FNKOHJHHYdxzNnyNzzPCCneLgZLbi8Wz7uylpuxCjLVx/7TkgX2qIzeGEb9iB8x/2psQqZBOmD1YgsWcAQIwnKN0nkN4vICbMy/yFsIaVrZ2rzCyUKQAhf7N/OQntzpIsPi5LIn2XRuUQdvA9JAVjbY9EPm3otK6YX+/gBdyPWDF5R+v1y5K9PPiCTlrrVWJGihrKfJp2sDlh5FiQqABm9ebU7Q5fmA1RkTcsDG1fpbrfz21dKfCmk1G+13z1DjWx2xb638nbDjCuVPjN71tTnSb7zo2sQiZCd9WsV2HR9wBCBtCGEfn2ivZCILHOaR/u1IL42y576pt+dRVqmtdlGm5fIilGjZI6sDaPiNTizuaS3nutx4b4EHqYsYGnzeJ7THGCjGtQzEiFHaLlEYBjHj3hhVzYbyVzS2gZPLkP+4QeBcUuG9nr3PVYjJzrIm77EOGcKZdstV6cmf6iZb90Cmsbg== 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: With the new shrinker APIs, there is no action such as prealloc, so rename {prealloc|unregister}_memcg_shrinker() to shrinker_memcg_{alloc|remove}(), which corresponds to the idr_{alloc|remove}() inside the function. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/shrinker.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index 6723a8f4228c..0b9a43ce2d6f 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -209,7 +209,7 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) static DEFINE_IDR(shrinker_idr); -static int prealloc_memcg_shrinker(struct shrinker *shrinker) +static int shrinker_memcg_alloc(struct shrinker *shrinker) { int id, ret = -ENOMEM; @@ -235,7 +235,7 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) return ret; } -static void unregister_memcg_shrinker(struct shrinker *shrinker) +static void shrinker_memcg_remove(struct shrinker *shrinker) { int id = shrinker->id; @@ -297,12 +297,12 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) up_read(&shrinker_rwsem); } #else -static int prealloc_memcg_shrinker(struct shrinker *shrinker) +static int shrinker_memcg_alloc(struct shrinker *shrinker) { return -ENOSYS; } -static void unregister_memcg_shrinker(struct shrinker *shrinker) +static void shrinker_memcg_remove(struct shrinker *shrinker) { } @@ -628,7 +628,7 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) shrinker->seeks = DEFAULT_SEEKS; if (flags & SHRINKER_MEMCG_AWARE) { - err = prealloc_memcg_shrinker(shrinker); + err = shrinker_memcg_alloc(shrinker); if (err == -ENOSYS) shrinker->flags &= ~SHRINKER_MEMCG_AWARE; else if (err == 0) @@ -696,7 +696,7 @@ void shrinker_free(struct shrinker *shrinker) } if (shrinker->flags & SHRINKER_MEMCG_AWARE) - unregister_memcg_shrinker(shrinker); + shrinker_memcg_remove(shrinker); up_write(&shrinker_rwsem); if (debugfs_entry) From patchwork Mon Sep 11 09:44:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379118 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 7321CEE7FF4 for ; Mon, 11 Sep 2023 09:51:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14C4D6B026D; Mon, 11 Sep 2023 05:51:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FCBF6B026E; Mon, 11 Sep 2023 05:51:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F06B66B026F; Mon, 11 Sep 2023 05:51:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DDCC36B026D for ; Mon, 11 Sep 2023 05:51:32 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B05AD80943 for ; Mon, 11 Sep 2023 09:51:32 +0000 (UTC) X-FDA: 81223849224.26.6C74228 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf13.hostedemail.com (Postfix) with ESMTP id D33152000C for ; Mon, 11 Sep 2023 09:51:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RFro703F; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425890; a=rsa-sha256; cv=none; b=QkO6I1dTH9MKvWnjxl8U0bryiyKk4va7EOUwalnsGMv2rIKTE8qhsdd6GNBhZjYsXwN1h6 18dQwn/GdcGGt9N/b/0sBYqIbwABkJszfs6rrS9jlvJ+/i7g/20u4dDXlzXboLslJ9YccM mYmyHsM55EFvpBviP6LiEfm/qxV5fHM= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RFro703F; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 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=1694425890; 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=CZ/9E5fVY8FPsUp4wjjHgLtQNfwCba8B+s0lf1gVAsM=; b=QBw2qIRwe6rl5EA4cQiidh0x0CqZ6XnQUgUnj12QWz67B4q5awFsggwuycPp4kVsFSIV5T MKzwWPN8Q0Zc9Ure/o4wAMiYTqkcMYHy0M5fY1wkPftcF3pzgh2PIio4Lb6twsmX2Wp0Hn cnfddYvC+RMqZioE3G7yTqu6PRDXob0= Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1befe39630bso9371355ad.0 for ; Mon, 11 Sep 2023 02:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425890; x=1695030690; 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=CZ/9E5fVY8FPsUp4wjjHgLtQNfwCba8B+s0lf1gVAsM=; b=RFro703FJUUdHHBzTZBCKOnY5DRMMXT07tGFzO8YZigZn+zyQEKFgcYCM1C7m44zz8 nKIbmru5CIeYvrjSTsQUPC6O0mPk5nFrsosx8aZ8JCsnzjQMnb1HoYwcUaoBhbXSvtpq Tm2SfCQiaURZpFXxug4MixqT5Qaq1hqwoq9sLdEsl+bOj81YR8QyNRZS42DRlOeouZR+ D6PxdBiXga53dDIkbrX8jHe3r1LEP+xxj+AnUvB7CX3ahqykNfk/94HizCrQ22Xg24nx 2V00mgqU1dbM5mkvA9tIN6eBZo1ZZ85cIv9LLHQpCMwXqep4vuHS/kWhe0NrryCAMdQb nkOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425890; x=1695030690; 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=CZ/9E5fVY8FPsUp4wjjHgLtQNfwCba8B+s0lf1gVAsM=; b=spBKouRuZBjPuKJ4Yr+JyrtN7x6L2L6KRdivZBFpYm//vJ8Cqy2A15TpQG5iS4Z0MX hAaVlKwx/o5MGm/LcyPxorBmuMhIvYItLR39uUmwIpTHoXA1d3kfVRO649OhIjimIJnu Zh+14gTWFuVoute/jiWiY6wGW8iyvaPdKxsFJ5ZcRXbvsItbrSLh7EEujbHB1bVIk+8M IP2oyNly9R4Oe3U+iisSrofKR/Xe2nmSDSJD9HH8NSvMQm+mlpshKlcKTCwi78h4vOKY 6JjplXaoAGmotp5/QYATGCjZh80i6As5dmMUmGdyb73jg+MVBnqGav9p5dQdQf/mSFQe FBzA== X-Gm-Message-State: AOJu0YyBEtst13NT6OoOmIh8OEqIhBekhIoLMeT50Q53jcJk2ZDnoC1h SFwy5Oa7SwoJnWPahREj6NfcTQ== X-Google-Smtp-Source: AGHT+IHVmg0SPBTxibarM4Nfz7v4+7j0jTley3X4jyAk2nq0f4+4LMApDrslEJNjDGHU4l29lE3i3A== X-Received: by 2002:a17:902:d645:b0:1c3:c687:478a with SMTP id y5-20020a170902d64500b001c3c687478amr334044plh.2.1694425889725; Mon, 11 Sep 2023 02:51:29 -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.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:29 -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 Subject: [PATCH v6 42/45] mm: shrinker: make global slab shrink lockless Date: Mon, 11 Sep 2023 17:44:41 +0800 Message-Id: <20230911094444.68966-43-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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D33152000C X-Stat-Signature: 5oi1jogcdzrr5s4opk7od4tw8xoi9kn6 X-HE-Tag: 1694425890-61547 X-HE-Meta: U2FsdGVkX1/YzIrHW62Oe8xPphao7WAWFtpRqUQ6rFacL19X9xrcEe07NTtHOR88WVbD4YqUMq/iDnN91PeiGq51yHFxIM4Ah4gPdP4nqxnliZENf7iYXhJxwIitu6Ycq8kP8DRH+ISPMWia7Wk5rf8Rl32ORVSXDOmbFb9YJtefOrkIqd1Z05tR/YpBVkIoQRDDdw9cM1EwSEIaSLm/qVKfGOwEyBDkRIrsTVtJ1RQSEWGappVYTOHrBp3DezRl4d/pE4Z2m6M3uWnau2sMyYs3W457hHGwRoXFLBXqmWyw7r97aFnL6UY3BYPuT0T9YJkKXuVRa6/I2ThWlW2CAIKybLHjfJWbKOHO7zSLDXuO2hrf4ddsaKo0GzU6MV61rCWklk7cNVD2sIa5+J6FBgq5E4lp5TNJU0MmtZMxFHJHx+Vgkt20q7Y+QxCUZsd4RTfy2F03l0ZFN64D2vCSkQsuAzEYafwNb2YdVE/VzjIAqiYBQiKYo//jE2cRdHbfH2NTa2qPoq1p+4vuepF4QB0nCHMC4v3PdTk797dLgnURLCDZKd8eyt7CvprwbI3ZOXKsWHlHcP0SsankMI4XqcQjl+F46bcA6TfjFigPkcfSlG/c6XOQo2rQmyR478br7xjpJb946fhT17EImEX2vzt4ZdpstYxfRvQuZ8WM3QY3gONibuwJIPahkJwHZHPKd1yG1mW825coADJCcWTCMSYINHcjAEwlLo3F/U5bFaaXYInyYsHQTJt8KAHN+fKesybmEvESqixI+dx0V+WhRtopOSyZUBbuaQryNKOJcwrk9arnLyQCP9DUldJvdkCMkE1Y2sLOvBro/u98Fc5mkexjSZ8MebniwIB9ANN9PRPWLAQM6S4cqZBLBM8BwNjYQZlnTxulpaMVaG+Z4uMPQLcVc3sO55wXtlu9ewjy8Mvj7ULXTczTlwUrzNM9+uk+r+MLKz2qSEGwda3AP/0 7afZJPeg BE/NTfbPmTLfE1prASd9V33xfighkS6MGhaY6dQGBNl+FVG/vhUpt6i8TkAI57BbNJtiJeXvVxM1tq+kTc5uavWY3UQgaRffLgDqPEX5QWsgea5wuyN9FdzvxkvYMNUCiY4QIUXaF1ORiykHdpck5NXCUVINb6VQUEhIyEcTlEynuZgJ0pZRrj3HuI99h7+iqSluRaXx2L8/ZosaA7YDtFkIeRh7OWr8RzeO2Vc5TTX8lKOIc7CZ90OxFbvnEMYSK8oq8ANwd4LPqGtfnQhwgysN4IsRieqRAxoR1xcbqR98U65o/PYZK4gWyDuhqpDB+X5tscJ3LdEW81WT0fj1I4/iKgNJbZYgeB/TCHi4/bo72tUhtJEvOOWSheGywStH8eVMJmXkWfVORr/FO1qlr1PxFiJdtxA39FvYW1vHdrZCD/sAERROK5UBotsvdnIZYNriBy7iuExYoJKjEUfRq70yWnW0AX0cLhhSF/3xUYvQwra0JbwCEZmUJH/t3kJLmyrramFqOTfoVjvbXPUCupQMY1KyIbXmK76HEv2vjsOJrC1UA2kECuce3tA== 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: The shrinker_rwsem is a global read-write lock in shrinkers subsystem, which protects most operations such as slab shrink, registration and unregistration of shrinkers, etc. This can easily cause problems in the following cases. 1) When the memory pressure is high and there are many filesystems mounted or unmounted at the same time, slab shrink will be affected (down_read_trylock() failed). Such as the real workload mentioned by Kirill Tkhai: ``` One of the real workloads from my experience is start of an overcommitted node containing many starting containers after node crash (or many resuming containers after reboot for kernel update). In these cases memory pressure is huge, and the node goes round in long reclaim. ``` 2) If a shrinker is blocked (such as the case mentioned in [1]) and a writer comes in (such as mount a fs), then this writer will be blocked and cause all subsequent shrinker-related operations to be blocked. Even if there is no competitor when shrinking slab, there may still be a problem. The down_read_trylock() may become a perf hotspot with frequent calls to shrink_slab(). Because of the poor multicore scalability of atomic operations, this can lead to a significant drop in IPC (instructions per cycle). We used to implement the lockless slab shrink with SRCU [2], but then kernel test robot reported -88.8% regression in stress-ng.ramfs.ops_per_sec test case [3], so we reverted it [4]. This commit uses the refcount+RCU method [5] proposed by Dave Chinner to re-implement the lockless global slab shrink. The memcg slab shrink is handled in the subsequent patch. For now, all shrinker instances are converted to dynamically allocated and will be freed by call_rcu(). So we can use rcu_read_{lock,unlock}() to ensure that the shrinker instance is valid. And the shrinker instance will not be run again after unregistration. So the structure that records the pointer of shrinker instance can be safely freed without waiting for the RCU read-side critical section. In this way, while we implement the lockless slab shrink, we don't need to be blocked in unregister_shrinker(). The following are the test results: stress-ng --timeout 60 --times --verify --metrics-brief --ramfs 9 & 1) Before applying this patchset: setting to a 60 second run per stressor dispatching hogs: 9 ramfs stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s (secs) (secs) (secs) (real time) (usr+sys time) ramfs 473062 60.00 8.00 279.13 7884.12 1647.59 for a 60.01s run time: 1440.34s available CPU time 7.99s user time ( 0.55%) 279.13s system time ( 19.38%) 287.12s total time ( 19.93%) load average: 7.12 2.99 1.15 successful run completed in 60.01s (1 min, 0.01 secs) 2) After applying this patchset: setting to a 60 second run per stressor dispatching hogs: 9 ramfs stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s (secs) (secs) (secs) (real time) (usr+sys time) ramfs 477165 60.00 8.13 281.34 7952.55 1648.40 for a 60.01s run time: 1440.33s available CPU time 8.12s user time ( 0.56%) 281.34s system time ( 19.53%) 289.46s total time ( 20.10%) load average: 6.98 3.03 1.19 successful run completed in 60.01s (1 min, 0.01 secs) We can see that the ops/s has hardly changed. [1]. https://lore.kernel.org/lkml/20191129214541.3110-1-ptikhomirov@virtuozzo.com/ [2]. https://lore.kernel.org/lkml/20230313112819.38938-1-zhengqi.arch@bytedance.com/ [3]. https://lore.kernel.org/lkml/202305230837.db2c233f-yujie.liu@intel.com/ [4]. https://lore.kernel.org/all/20230609081518.3039120-1-qi.zheng@linux.dev/ [5]. https://lore.kernel.org/lkml/ZIJhou1d55d4H1s0@dread.disaster.area/ Signed-off-by: Qi Zheng --- include/linux/shrinker.h | 24 +++++++++++ mm/shrinker.c | 89 ++++++++++++++++++++++++++++++---------- 2 files changed, 92 insertions(+), 21 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index eb342994675a..4908109d924f 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -4,6 +4,8 @@ #include #include +#include +#include #define SHRINKER_UNIT_BITS BITS_PER_LONG @@ -87,6 +89,17 @@ struct shrinker { int seeks; /* seeks to recreate an obj */ unsigned flags; + /* + * The reference count of this shrinker. Registered shrinker have an + * initial refcount of 1, then the lookup operations are now allowed + * to use it via shrinker_try_get(). Later in the unregistration step, + * the initial refcount will be discarded, and will free the shrinker + * asynchronously via RCU after its refcount reaches 0. + */ + refcount_t refcount; + struct completion done; /* use to wait for refcount to reach 0 */ + struct rcu_head rcu; + void *private_data; /* These are for internal use */ @@ -120,6 +133,17 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); void shrinker_free(struct shrinker *shrinker); +static inline bool shrinker_try_get(struct shrinker *shrinker) +{ + return refcount_inc_not_zero(&shrinker->refcount); +} + +static inline void shrinker_put(struct shrinker *shrinker) +{ + if (refcount_dec_and_test(&shrinker->refcount)) + complete(&shrinker->done); +} + #ifdef CONFIG_SHRINKER_DEBUG extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...); diff --git a/mm/shrinker.c b/mm/shrinker.c index 0b9a43ce2d6f..82dc61133c5b 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include "internal.h" @@ -576,33 +577,50 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, if (!mem_cgroup_disabled() && !mem_cgroup_is_root(memcg)) return shrink_slab_memcg(gfp_mask, nid, memcg, priority); - if (!down_read_trylock(&shrinker_rwsem)) - goto out; - - list_for_each_entry(shrinker, &shrinker_list, list) { + /* + * lockless algorithm of global shrink. + * + * In the unregistration setp, the shrinker will be freed asynchronously + * via RCU after its refcount reaches 0. So both rcu_read_lock() and + * shrinker_try_get() can be used to ensure the existence of the shrinker. + * + * So in the global shrink: + * step 1: use rcu_read_lock() to guarantee existence of the shrinker + * and the validity of the shrinker_list walk. + * step 2: use shrinker_try_get() to try get the refcount, if successful, + * then the existence of the shrinker can also be guaranteed, + * so we can release the RCU lock to do do_shrink_slab() that + * may sleep. + * step 3: *MUST* to reacquire the RCU lock before calling shrinker_put(), + * which ensures that neither this shrinker nor the next shrinker + * will be freed in the next traversal operation. + * step 4: do shrinker_put() paired with step 2 to put the refcount, + * if the refcount reaches 0, then wake up the waiter in + * shrinker_free() by calling complete(). + */ + rcu_read_lock(); + list_for_each_entry_rcu(shrinker, &shrinker_list, list) { struct shrink_control sc = { .gfp_mask = gfp_mask, .nid = nid, .memcg = memcg, }; + if (!shrinker_try_get(shrinker)) + continue; + + rcu_read_unlock(); + ret = do_shrink_slab(&sc, shrinker, priority); if (ret == SHRINK_EMPTY) ret = 0; freed += ret; - /* - * Bail out if someone want to register a new shrinker to - * prevent the registration from being stalled for long periods - * by parallel ongoing shrinking. - */ - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - break; - } + + rcu_read_lock(); + shrinker_put(shrinker); } - up_read(&shrinker_rwsem); -out: + rcu_read_unlock(); cond_resched(); return freed; } @@ -671,13 +689,29 @@ void shrinker_register(struct shrinker *shrinker) } down_write(&shrinker_rwsem); - list_add_tail(&shrinker->list, &shrinker_list); + list_add_tail_rcu(&shrinker->list, &shrinker_list); shrinker->flags |= SHRINKER_REGISTERED; shrinker_debugfs_add(shrinker); up_write(&shrinker_rwsem); + + init_completion(&shrinker->done); + /* + * Now the shrinker is fully set up, take the first reference to it to + * indicate that lookup operations are now allowed to use it via + * shrinker_try_get(). + */ + refcount_set(&shrinker->refcount, 1); } EXPORT_SYMBOL_GPL(shrinker_register); +static void shrinker_free_rcu_cb(struct rcu_head *head) +{ + struct shrinker *shrinker = container_of(head, struct shrinker, rcu); + + kfree(shrinker->nr_deferred); + kfree(shrinker); +} + void shrinker_free(struct shrinker *shrinker) { struct dentry *debugfs_entry = NULL; @@ -686,9 +720,25 @@ void shrinker_free(struct shrinker *shrinker) if (!shrinker) return; + if (shrinker->flags & SHRINKER_REGISTERED) { + /* drop the initial refcount */ + shrinker_put(shrinker); + /* + * Wait for all lookups of the shrinker to complete, after that, + * no shrinker is running or will run again, then we can safely + * free it asynchronously via RCU and safely free the structure + * where the shrinker is located, such as super_block etc. + */ + wait_for_completion(&shrinker->done); + } + down_write(&shrinker_rwsem); if (shrinker->flags & SHRINKER_REGISTERED) { - list_del(&shrinker->list); + /* + * Now we can safely remove it from the shrinker_list and then + * free it. + */ + list_del_rcu(&shrinker->list); debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); shrinker->flags &= ~SHRINKER_REGISTERED; } else { @@ -702,9 +752,6 @@ void shrinker_free(struct shrinker *shrinker) if (debugfs_entry) shrinker_debugfs_remove(debugfs_entry, debugfs_id); - kfree(shrinker->nr_deferred); - shrinker->nr_deferred = NULL; - - kfree(shrinker); + call_rcu(&shrinker->rcu, shrinker_free_rcu_cb); } EXPORT_SYMBOL_GPL(shrinker_free); From patchwork Mon Sep 11 09:44:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379119 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 DF998EE57DF for ; Mon, 11 Sep 2023 09:51:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67C606B026F; Mon, 11 Sep 2023 05:51:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62D266B0270; Mon, 11 Sep 2023 05:51:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F54C6B0271; Mon, 11 Sep 2023 05:51: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 412DD6B026F for ; Mon, 11 Sep 2023 05:51:41 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1A2C9B3A48 for ; Mon, 11 Sep 2023 09:51:41 +0000 (UTC) X-FDA: 81223849602.07.C2138E1 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf28.hostedemail.com (Postfix) with ESMTP id F21D5C0017 for ; Mon, 11 Sep 2023 09:51:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j6JdpKd6; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 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=1694425899; 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=02oN8W08zjTxUZl21U6+DV55wPZPOOOcomDUkgbjeeM=; b=kq4+DArMuE+eZP3VfAGVreKFA4KskGlISo+sM1ecfyYVJLiBp+THy0HYSA1zppyw6VPrG0 4uVu+dp9JA2vKlhilNNkpIaZXsmJc4O6ggIY60KYa+WDFZw9mlz3PEeanwB3peFy1auvsl WV5J6AL0j4U49WA0ydZadBz3HJRYb+Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425899; a=rsa-sha256; cv=none; b=uVDEABLUBdiRBn+Z/wNZlO9Mn/+unfFqZrQJlHgiKE86FeiqhximT/b1S/gkWzdiKaPHBT pvNSOnSwMz9IkespnCXqdJWMzUyB9nLeN0v0UgLL67vn4fZJViMSxyAeqGVsIlQsUn/u5s FX5gxondMvbJ4Z8IOsMZI+uridIijqc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j6JdpKd6; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-68cc1b70e05so1081910b3a.1 for ; Mon, 11 Sep 2023 02:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425898; x=1695030698; 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=02oN8W08zjTxUZl21U6+DV55wPZPOOOcomDUkgbjeeM=; b=j6JdpKd6UsTI8cDVRs0lYVO+RuBR53yWmwMluSx5s2QGRPIJMkuIylhY5ntBJDkEbA ZN65D7RxNKbVdO/H/gENOpVv2eBefG+i/gqxf3qlHqd1uAgYfaYrmLyiwkK//Kmvn/15 vtJ4Hr3R0tfeM8gxMfDKfIIBWPg9MhgJ6nd5lXsMxH+UhzPuldaP6ddev8T42F24eDnE 6ODTISLL4jrOCgEqGOyTv+BxPklSwkeXEd7aFGuISdNWyMvK+QTJ6XdJJbajSrw0FovZ rLNf/Tn8ka/XgqxWXnECJygjhwOUv6hIS0T3ILcos2mZ2RADAgccnjoJ0kbM/Q3Rz6cS gYIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425898; x=1695030698; 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=02oN8W08zjTxUZl21U6+DV55wPZPOOOcomDUkgbjeeM=; b=jLt1cX9GWWTnnvrhnrUkbcxAfXL+VnbJg2ewqejwldcysSCAXuslLLH996EmMCy9BX BH+t/uZw7cPysfMEjc0h90B4jilOnoaS2LRug3/jyS/V8dlwt0k86J/dtJA+cEVT8b1u tZevbi32KsAs29tVxy99niaZLrMMzwkh4TrjiX1adDK17SB7jQAblnTXCHTcqYVyMdnI k4S4h7rOC7nVPzAxTM9jbYxdFLGPGTxm9jb3+kF7XIQdFNeusVBqdHFF8zzS1cc/XEza 2kfSd7VvFK+qzEOCA02pXR/qVk7WfYCHSJRhwpSsdwfN2nCx2/7rdHdcrTzI94iARb4E PdiQ== X-Gm-Message-State: AOJu0Yx2Ek3xr8slhdREj0MCmtSM8OzzdVuY8YAMNwLKIhyqpFuYyZpy +SwaUA8n/HAEy1791OQeQ9s0wA== X-Google-Smtp-Source: AGHT+IH97cG96KOmpoktz2XA7SklxuW0ceeXqXRZ1DysovZgTlaqQRndvB65TuUAaXsE5amMaJ1n9w== X-Received: by 2002:a05:6a21:6da4:b0:137:3941:17b3 with SMTP id wl36-20020a056a216da400b00137394117b3mr12294593pzb.6.1694425897928; Mon, 11 Sep 2023 02:51:37 -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.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:37 -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 Subject: [PATCH v6 43/45] mm: shrinker: make memcg slab shrink lockless Date: Mon, 11 Sep 2023 17:44:42 +0800 Message-Id: <20230911094444.68966-44-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: F21D5C0017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: u1foz6x3xbzagubewqpjacton9wetdpb X-HE-Tag: 1694425898-886365 X-HE-Meta: U2FsdGVkX18hYZXGoISnIPoIMjrdbzgmeIKspTYxsB1IEht4Nx++DiC7hz2B+VWKTxJ9pQ23DvIcaUBShM++bXz+0zxImdoy8bHezdWD6oGEz3a4AFmZbn4Hxsqy8C4jR/+DSG1L6ESXk1hIMDYe0PVWmuWtns1Dgrgp5mEn5YT4SbczDelV1oft75hKbZMYhkwU4FGMSMC1oG+wMhbD4qfOx8Kh7rFJktiZCJAxWCP6uSmJX1awSErQ/rd+g3OdjVV3YdAM2KQb3HzJkJBLb/8a5wkZLO/TZ0K+L2xJKKnz3tbF16Ft7hxKik7D2nQvb8gpSWvLVdv0MwBGZVVYOUIwpFVZZNZVmNZo/9DtSohLexPpa8bTIxrBslChyVG3Ste34lmfJImlSt+2yuw7yIwUc2IMbZRHb3y/vVUKxq9HHkcj1cXGKvNyWp1un2fovtIVR9yaZTzHcxF4idB9V9ohwXjebTH1Ej+5ZskrpqgC+8y4MciD6Ji7bCr9P3PdLHFpvnbrLJj449ZTu35d5q/Oc5vr6Bmwp/n07hWvLUF9GEu0ahK716S2zsT+7+e6A8BCdfvuKvK341Ea9ygYwJLxd9QA+nB/UKL5q3AArpIzhjpVsVW9U/dZmcA/dcbpv5UD39B5oudaFktvsz3UihZ/vmRrfrcWoveNHkkK0eXGyW9hhr4zIA6VT2f2tSKW1ZJcGhd/81HPu+aeXaWSDQuLC5vw3LnupmyRffQoLCO7ob6graKlQzVCQdh9qT37jhJoyFnfzHN/Hk6hWgq03ghUWqJSmnHcnqqf6uH5ISquWyGa5c+xC/eNyCeRtOfAXan0/Wq0mmQ8+oJy20ulPFz8jGH91iMH0oqe/Sf+rKxGkdAB7ZGv0NJ0sxMtavlgQEHwpfhyDRT1xe9Cf9fsiHKQzlxQRzQ1x4n7qK45mUgCmh1OaYMmeEdFBRjkjd8/Z9g+dEVO4gXHsykScR7 /JK/Usuc Iax+SjNFVFiYzI0J+XIAvB2z1Srtxk2EnrCxr0LaAnCosnP3BNGG8J4Z8RjJR8AmCjH814+Ir9E25nS+DzA/U8zGULp70zUUnd6YYlldQepIV6oCMguRUqj0ZApmtEiETsKuz2gbBDdxTJn0TE9iKcpxmjDKto4aZuwmVy7HqqwNpIIklKGLaLMtx3y3O8D1gPuHpKRBmkG4P+rv9A4is67tHP5cz5UuGpzCjsEwuj3pOzZa6WtTsDg7rd76Q074J3DAR5OGvtQ2QpinD80iuA/yIHlZAI9kPApyA/yCuPPbR3PeTOu3CknZfVmyz0aFrMgwyEt4HnEtkgCrFnr+WNu+jT833alBsLMV6NUbyYraveLP7nStWOe5Jwi26FJyjWKy6l46IrVGYbIZpsfWDXOjpOhNWou3ZnTLk 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: Like global slab shrink, this commit also uses refcount+RCU method to make memcg slab shrink lockless. Use the following script to do slab shrink stress test: ``` DIR="/root/shrinker/memcg/mnt" do_create() { mkdir -p /sys/fs/cgroup/memory/test echo 4G > /sys/fs/cgroup/memory/test/memory.limit_in_bytes for i in `seq 0 $1`; do mkdir -p /sys/fs/cgroup/memory/test/$i; echo $$ > /sys/fs/cgroup/memory/test/$i/cgroup.procs; mkdir -p $DIR/$i; done } do_mount() { for i in `seq $1 $2`; do mount -t tmpfs $i $DIR/$i; done } do_touch() { for i in `seq $1 $2`; do echo $$ > /sys/fs/cgroup/memory/test/$i/cgroup.procs; dd if=/dev/zero of=$DIR/$i/file$i bs=1M count=1 & done } case "$1" in touch) do_touch $2 $3 ;; test) do_create 4000 do_mount 0 4000 do_touch 0 3000 ;; *) exit 1 ;; esac ``` Save the above script, then run test and touch commands. Then we can use the following perf command to view hotspots: perf top -U -F 999 1) Before applying this patchset: 33.15% [kernel] [k] down_read_trylock 25.38% [kernel] [k] shrink_slab 21.75% [kernel] [k] up_read 4.45% [kernel] [k] _find_next_bit 2.27% [kernel] [k] do_shrink_slab 1.80% [kernel] [k] intel_idle_irq 1.79% [kernel] [k] shrink_lruvec 0.67% [kernel] [k] xas_descend 0.41% [kernel] [k] mem_cgroup_iter 0.40% [kernel] [k] shrink_node 0.38% [kernel] [k] list_lru_count_one 2) After applying this patchset: 64.56% [kernel] [k] shrink_slab 12.18% [kernel] [k] do_shrink_slab 3.30% [kernel] [k] __rcu_read_unlock 2.61% [kernel] [k] shrink_lruvec 2.49% [kernel] [k] __rcu_read_lock 1.93% [kernel] [k] intel_idle_irq 0.89% [kernel] [k] shrink_node 0.81% [kernel] [k] mem_cgroup_iter 0.77% [kernel] [k] mem_cgroup_calculate_protection 0.66% [kernel] [k] list_lru_count_one We can see that the first perf hotspot becomes shrink_slab, which is what we expect. Signed-off-by: Qi Zheng --- mm/shrinker.c | 85 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 19 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index 82dc61133c5b..ad64cac5248c 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -218,7 +218,6 @@ static int shrinker_memcg_alloc(struct shrinker *shrinker) return -ENOSYS; down_write(&shrinker_rwsem); - /* This may call shrinker, so it must use down_read_trylock() */ id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); if (id < 0) goto unlock; @@ -252,10 +251,15 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, { struct shrinker_info *info; struct shrinker_info_unit *unit; + long nr_deferred; - info = shrinker_info_protected(memcg, nid); + rcu_read_lock(); + info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); unit = info->unit[shrinker_id_to_index(shrinker->id)]; - return atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(shrinker->id)], 0); + nr_deferred = atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(shrinker->id)], 0); + rcu_read_unlock(); + + return nr_deferred; } static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, @@ -263,10 +267,16 @@ static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, { struct shrinker_info *info; struct shrinker_info_unit *unit; + long nr_deferred; - info = shrinker_info_protected(memcg, nid); + rcu_read_lock(); + info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); unit = info->unit[shrinker_id_to_index(shrinker->id)]; - return atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(shrinker->id)]); + nr_deferred = + atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(shrinker->id)]); + rcu_read_unlock(); + + return nr_deferred; } void reparent_shrinker_deferred(struct mem_cgroup *memcg) @@ -463,18 +473,54 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, if (!mem_cgroup_online(memcg)) return 0; - if (!down_read_trylock(&shrinker_rwsem)) - return 0; - - info = shrinker_info_protected(memcg, nid); + /* + * lockless algorithm of memcg shrink. + * + * The shrinker_info may be freed asynchronously via RCU in the + * expand_one_shrinker_info(), so the rcu_read_lock() needs to be used + * to ensure the existence of the shrinker_info. + * + * The shrinker_info_unit is never freed unless its corresponding memcg + * is destroyed. Here we already hold the refcount of memcg, so the + * memcg will not be destroyed, and of course shrinker_info_unit will + * not be freed. + * + * So in the memcg shrink: + * step 1: use rcu_read_lock() to guarantee existence of the + * shrinker_info. + * step 2: after getting shrinker_info_unit we can safely release the + * RCU lock. + * step 3: traverse the bitmap and calculate shrinker_id + * step 4: use rcu_read_lock() to guarantee existence of the shrinker. + * step 5: use shrinker_id to find the shrinker, then use + * shrinker_try_get() to guarantee existence of the shrinker, + * then we can release the RCU lock to do do_shrink_slab() that + * may sleep. + * step 6: do shrinker_put() paired with step 5 to put the refcount, + * if the refcount reaches 0, then wake up the waiter in + * shrinker_free() by calling complete(). + * Note: here is different from the global shrink, we don't + * need to acquire the RCU lock to guarantee existence of + * the shrinker, because we don't need to use this + * shrinker to traverse the next shrinker in the bitmap. + * step 7: we have already exited the read-side of rcu critical section + * before calling do_shrink_slab(), the shrinker_info may be + * released in expand_one_shrinker_info(), so go back to step 1 + * to reacquire the shrinker_info. + */ +again: + rcu_read_lock(); + info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); if (unlikely(!info)) goto unlock; - for (; index < shrinker_id_to_index(info->map_nr_max); index++) { + if (index < shrinker_id_to_index(info->map_nr_max)) { struct shrinker_info_unit *unit; unit = info->unit[index]; + rcu_read_unlock(); + for_each_set_bit(offset, unit->map, SHRINKER_UNIT_BITS) { struct shrink_control sc = { .gfp_mask = gfp_mask, @@ -484,12 +530,14 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, struct shrinker *shrinker; int shrinker_id = calc_shrinker_id(index, offset); + rcu_read_lock(); shrinker = idr_find(&shrinker_idr, shrinker_id); - if (unlikely(!shrinker || !(shrinker->flags & SHRINKER_REGISTERED))) { - if (!shrinker) - clear_bit(offset, unit->map); + if (unlikely(!shrinker || !shrinker_try_get(shrinker))) { + clear_bit(offset, unit->map); + rcu_read_unlock(); continue; } + rcu_read_unlock(); /* Call non-slab shrinkers even though kmem is disabled */ if (!memcg_kmem_online() && @@ -522,15 +570,14 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, set_shrinker_bit(memcg, nid, shrinker_id); } freed += ret; - - if (rwsem_is_contended(&shrinker_rwsem)) { - freed = freed ? : 1; - goto unlock; - } + shrinker_put(shrinker); } + + index++; + goto again; } unlock: - up_read(&shrinker_rwsem); + rcu_read_unlock(); return freed; } #else /* !CONFIG_MEMCG */ From patchwork Mon Sep 11 09:44:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379120 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 86F3AEE7FF4 for ; Mon, 11 Sep 2023 09:51:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 284DE6B0271; Mon, 11 Sep 2023 05:51:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 234E16B0272; Mon, 11 Sep 2023 05:51:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0FD096B0273; Mon, 11 Sep 2023 05:51:49 -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 F37FF6B0271 for ; Mon, 11 Sep 2023 05:51:48 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AE207C0972 for ; Mon, 11 Sep 2023 09:51:48 +0000 (UTC) X-FDA: 81223849896.10.C42ABDA Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf20.hostedemail.com (Postfix) with ESMTP id D1CD11C000F for ; Mon, 11 Sep 2023 09:51:46 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GxWTlK1z; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 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=1694425906; 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=nsvoU0P27T3SHlAjt1w8muCb9cUYLpaKhV7Wpc+WlY8=; b=cHuHgV4QX+eP4hMtLCnpcj3UhCndnQAd1LZ4scDFGfeIuuw/Dlo7vYIV0C18wMAn2YqNxH w4A1YR7tjO+CAhuUrYKkHYlt67QWEa9LbAKVm1xH+ZS1r1Obljs9SDzxHVyj5nnTK5O+EQ MhHQLFnoKknvfLUSxklW7CFFGVuOEIA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GxWTlK1z; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425906; a=rsa-sha256; cv=none; b=K/vav0JChdvbY0fK/rH/dLfU/cE1Ft07uU55AzIIwOWBZ1Nxz13HyxRqkBJXthJTORWh9W es+ujhMr2C9fPpEvmLPs8C3cN9b4q4UUjy9CRfZMaLNub4tr3TlFaJTBFucp2PDSH2XTST 1Rc82osG4zLFQAnOiEL+sPPpQHlweFo= Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1c3aa44c0faso1789935ad.1 for ; Mon, 11 Sep 2023 02:51:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425906; x=1695030706; 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=nsvoU0P27T3SHlAjt1w8muCb9cUYLpaKhV7Wpc+WlY8=; b=GxWTlK1zupiJaGt1/gyNkuW2tpwVF/SmtA7FQSPWy1Ln9IIjjgUxfrl0mP78OqdVcN hKvKfrC/qOOs8ik3fPAfi46goVEbgVdHK8n35MiXppbjnRZ1q1qYmhBV4qt3bKV2zTWK GvNhijFlKUCabgnHjwBlGXVhCWywNuSlhqA4nYUo3gwK6SKwAqcb2LlKvJwDz16ZBtii //z1g+e3pxjXDozNNx7LX+ByQchYr+Mkd1fLJKBTDFF6HZftUVfJk/NHX6kF5HgFM0kz LjEnZIZHU83nVsLVsQHW5s3zDPc/uUH8rp2MqN+Ow8J10I3f1YVE5CojSE7AKSsBSAOG V/Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425906; x=1695030706; 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=nsvoU0P27T3SHlAjt1w8muCb9cUYLpaKhV7Wpc+WlY8=; b=de5x5OGMCrlNBxgB61j6tMdzaurwCXCZLzMJ2DPgeuVJ8aMozxRMOkXIv4qVFWBFkf lD3ej/CITUxVxEbXzO9XaRHhaRZwZU6/fgANi3Byp2lag7AX7pWHZF9bmOi+hMNIByRm 83P2w/FkD5Uw2WwanXyo70uEz7aFw3d9I9ChUf/LLaPZY+SE2uLEK24r8YJO5bl2mS6x VOvk3Byn+NyA4s/BjNOc2/5p3un/y8VZ2wbAL0GlroxXX7ZDyCucCN9O+u9526aCN6LP EZGbL1s7BDC5TNsC6wNltNuXNuvSVBr2Arq0tkcg5Ac8wZ94nsiEbhG4O0MemDydHsvj 7B2g== X-Gm-Message-State: AOJu0YwXuwVTtHCY+/amhM3pL9jDm//PIm4mt94UhfDVNRo9rhdTGk+7 1WDoFPM8pvWFzsXpT+b7BNPQfw== X-Google-Smtp-Source: AGHT+IFtnlx2HOm/jCSk9ayFrW0ZCh+0jIw0rvxZkQXsUrMha5y88qwb+DelOOMwpsKlazP0cUr2uw== X-Received: by 2002:a17:902:c94e:b0:1c3:4073:bf80 with SMTP id i14-20020a170902c94e00b001c34073bf80mr11732124pla.0.1694425905934; Mon, 11 Sep 2023 02:51:45 -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.51.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:45 -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 Subject: [PATCH v6 44/45] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Mon, 11 Sep 2023 17:44:43 +0800 Message-Id: <20230911094444.68966-45-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: D1CD11C000F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: u9zqare56d7wnqnud6crxxpmbw41ues5 X-HE-Tag: 1694425906-267806 X-HE-Meta: U2FsdGVkX18rbVoBmzmqrQVt6LgMrYvmW4C6psn6lC0pZGQfOYC/9KboYOiSlvLDaVW5g25JHnsR0jkAxZhofwEeiMnrKuHD8RqGQOuwOgBWf/8AdpIgeaQs/vsNlllbHmxZXjDlJNi/192LKSW2lUyU6+aKe2vJmIvREJdqt1g0gQ/wKkRNd5nh4SQ3o+Q2gVEonDbqRNCXE2PUcwoouDT5QJ3Hy+9shGpb5za3FXENAZdWkdoxg1ugg3GyYuNK7nLrISRy5kBiv1PZIUzTFI76/ZeKAke0fy8/2XTSYaRrB/iklfb4LxpO/7+wJNqZ2ybSQ49V7+fWFYXENL5KY+B1adp0kcGLpzwt8UtHVbPl3pyhIMTf1dTDGZTjjbSQFgsr6WwGYwLu2feyxppPlxRoXEgmZeDyBRMeHwzraTW/mLLlU9S2U1816ae5ISPIc9msm0mpbpYvBuEw7gkd9I2HT1+/G0l7RGq5eQGNp1/X+DJluKyJsLNab6TxwF1Sivd8EQjLGwuvd50XbvYGD3mSX99PFS0Cv/Yg/1Lz+ssf5iD7jo5fY8Mlk6kzULk2NsSfQ0JHEK7FHTdk88DX+6FfJBCuEd2/jnBvTRVPJHIKVif2SfdIG+Rejk7FupKT3nTY09MYNSVAe4bWnh0l3xdfTxxMK9qdEewCMzmAgaLcneEtumKV4Ik4e+x7Mf8d3N8SfWkJt25KaL4zPukOHh8Uf4uTc+kJ234IQ+sC/77WEVmE5hFy8QmVUzjlIrXV7Nenc4XWC7wrmX1WCcp9mSvRsPj/B/Cw68jZyXbYWJO9OzpQ2J7O983GscviZgUeD1mK7Wgzn+EQ/Yph3khH+IOY1UQfCNSDs5tM9VzwhHpJMe/SN2SYEjVwMQzONAn2UZarr9PB83xkfcppp+phiJSqh/IybbXnL5J+DIbSQE7KUjirHhVzRAZOfzEuYI5kpTF+QKX6C2/gHFzEqCk VPAn5qC+ XwyEJDaZO6TqgYzOvs/eksvUzIiWqELljKlT6KeCYjzqPRLVIU+iaGQ2i9jCR/du/M1DYGtwjW4P0y1i9g+x3++hFcc2cCF/hgiGqd00mD+wIrY5E3bYMXmoRfxjMQBlLl0ou6DnxbWfede9dA3lz2JMv5I/Ggk44exiTbiIouNqF4jbjKJlBlJyvMM8BTGsXxmFAfXfw5yfcuTQLQ+waTB5wUSFO/Rbs9CkYrfASRh6WiuaeHe8e/vmaCAlj+gkYpB7WkipXdfSnxUlogyin+1oidgdevWa1KtN9AoGsuVLirzFheiWkKU5Kw47K4kYwG13Lww3ffku3xt41B6zxQmQhdQLgpL5ms5eL7gW3FwmV6CLG3OCkBugbMC67cqFBvSkcH0bh5KvNgh8aR53T8qqQjf611ztrdyWTXL4vjVTu5+hHqqlcBiDjDzgmXc1xH3dGeSs7wlL0/JEULmcHuHGjbg== 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: For now, reparent_shrinker_deferred() is the only holder of read lock of shrinker_rwsem. And it already holds the global cgroup_mutex, so it will not be called in parallel. Therefore, in order to convert shrinker_rwsem to shrinker_mutex later, here we change to hold the write lock of shrinker_rwsem to reparent. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/shrinker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index ad64cac5248c..471c07d75c4a 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -292,7 +292,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_read(&shrinker_rwsem); + down_write(&shrinker_rwsem); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -305,7 +305,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_read(&shrinker_rwsem); + up_write(&shrinker_rwsem); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker) From patchwork Mon Sep 11 09:44:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379121 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 0A561EE57DF for ; Mon, 11 Sep 2023 09:51:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4D416B0273; Mon, 11 Sep 2023 05:51:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FDB36B0274; Mon, 11 Sep 2023 05:51:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C6086B0275; Mon, 11 Sep 2023 05:51:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7CEB46B0273 for ; Mon, 11 Sep 2023 05:51:56 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5A7EE80929 for ; Mon, 11 Sep 2023 09:51:56 +0000 (UTC) X-FDA: 81223850232.21.3150767 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf05.hostedemail.com (Postfix) with ESMTP id 7203B10000F for ; Mon, 11 Sep 2023 09:51:54 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KlkaQqyv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 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=1694425914; 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=oLAG3LFr2H9IpWa0Q1CUXr98GG6fWERP+Y/K9cMxF58=; b=PRapz2bPABeFe+RSD/90kEQis6gkt2IXwJ/HmN1T0kEW/MiYRzVS6m1xFVzY92N9tgcDOX Wo7IHOufx/tLtd69E+Nl4khtWEYoG7PH3B6v5TiTttlUzR4CPKkHdLt4oajcI4ZyQGR42c M7ZhDHHUzZZCekNO1sj51D474a5XbnI= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=KlkaQqyv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425914; a=rsa-sha256; cv=none; b=F5frCx/+azTo5sCPhVBQeZfpqdsQ+C7vxSBfLcNU6wZ3J5kWlsJInNb6aSRQdTbREY74uG +LDanx87X4Serls5F/Sej/9XGL72mNdPLW3wHukYHsbYN8Ze3ylL4ECcWRmfQWXITX08FO mRbPcIiSJm0srYUsTjVRXhopziwGRgU= Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1bf7b5e1f06so7715415ad.0 for ; Mon, 11 Sep 2023 02:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425913; x=1695030713; 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=oLAG3LFr2H9IpWa0Q1CUXr98GG6fWERP+Y/K9cMxF58=; b=KlkaQqyv+hHTw+h95qG+qfsn26xqezylPlQY2VNOjmS8vhOVMbrPmDcchklZ4NCL5t QvxOoNgAtz6MeT9h71rFy9G5W3JPHDMsPmPKLXe6/Ew1/Hnf/WBqCcOX7hAYMu1wlOfF ZtniRi5CoDKRySorhudUzJ24Rigz8WLhiQxmHcP/q/G3MApICIw6DPYV68FYLSd6wN5W knEhZP7D5mI0FdLPLsWC7byvRcOPDDdZCYPOuM38cBd2RB7qgP258nOQol857lNd/0In rjaOMKYAviBJLFuoweS51pZTrFPgy3yKBt+gtdCuxB1XKE0gvaw+mrrLRiIpJfshCJdD wkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425913; x=1695030713; 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=oLAG3LFr2H9IpWa0Q1CUXr98GG6fWERP+Y/K9cMxF58=; b=IC5M07UZ1Vtt9ntY/VnXwc0sXGnIQl34obzhJKYLbUunI1BlEe+Tx3qPmXQi1DgX4a TApc0Imb+ajUq3R3kBqFVhPa8fxsRqTordsRx3zanGkwM8Ie8ElivEKop/eTsKUApCfu jkI4DRhbYH0cmIYxnyF/dbCrVEWIIEG4EbrlPbsh4wKzyI6s0E8RukNxuyqTmON5V82O wuYkj8qTQtqj/+JEfyxD/7ESGaCS/LckXTzM1ziZ30Bo3+oYzc60GRlu4hKHJaDCkxtK wcMRzeHb8Z8MewQ4HC4NNcU6ijoiaEQlFu3B2XG9vBuszE257YYbEuEsrpKKbVz+Ud5u N6Aw== X-Gm-Message-State: AOJu0YxnTyrMSluhrYnIK8B7kXQAYtrH3lbVhCia/EXHu//D8aA2vhr5 CBEerDLwYKEYtACRPt1wAJ2m9w== X-Google-Smtp-Source: AGHT+IGwEyIZI7e/UGLTPntdnRUQTR+mAjNl7rxKGC9aX+dD26VCCxP8WJPLnCYFs0FvhQRvA39K8A== X-Received: by 2002:a17:902:f155:b0:1c3:a4f2:7c99 with SMTP id d21-20020a170902f15500b001c3a4f27c99mr5142339plb.4.1694425913461; Mon, 11 Sep 2023 02:51:53 -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.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:51:53 -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 Subject: [PATCH v6 45/45] mm: shrinker: convert shrinker_rwsem to mutex Date: Mon, 11 Sep 2023 17:44:44 +0800 Message-Id: <20230911094444.68966-46-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: 7203B10000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 99y4e5txdzr8uhwop4aforne8e44aqpa X-HE-Tag: 1694425914-90347 X-HE-Meta: U2FsdGVkX1+TlPxcU0TGeUKRr4JwjezdunsgofFr5Sn8ERLnYh5rEF12z5UboUosxBp44HK5JUuFFRd2gWX4yQmLCO7ADMbcniyyfQwAUvHXBeqyK5na4oOatgiRKHItx2jXrBwns4lcOWM3a2IS/QUZjAPeBEhkexxrJCpt6UbXaD3cEtc3nGA8EH6R6q3ezaEvUwmnlgONMpWnvLVtqA9rHwYRsDPRP6A7b/g6WLPlEAvsiaXdxPaY7FZIAWqcZEJbGduFQ4RUbE+SYeEbzyLmrcfUA4W6xC41hN02e+9wkUkuhEsTMWbyhN95sQCdUVGbYjTcMs1SrT9fg6jrGXsBuwN4HOfeAlUlijmBI2vr4Dw9ToA5gHLSBrpW/0O6vu8t0l3dVkUUPlyqs2bD6i7epKpnH/m1X0F5CqvFTcjpQ2M/6/3+nW3YAK0ac7K/3LLxjMGLDs2mZ6UEmEdao/1/XzRkQxQo7hUI2sZpQm9zmwgqWfRi5FLuzqM4Vhyva5gnqR9MW58YnNgioCBgEasfLQ1tSfkGpFNfURGPz9CQWdIbbls1lJVXlCPcdrN3EG84KA7ZaNpcFP7sWPaJC1bEzB2MMInCQmqdwBtmGNCZPuCMKSfnfq+Zf/Dj2MdXe0obiL5UomvwzirkgFOxCwohoxheMEBMrdmn3D3jWui35d7JgTy+PQGQNmFnImXRskdCexdfLq5cQAaaj78nQNER6zaDTBGzRlT3ym1ejDUEjcgSfOYx2zStAorgxvI/kGSWrLvFpfhtiDJr/xousW7/OrJnXtZ4p/vtvJtDz9AikfClk+Z2jnFfFi++1g/MWjzciEy/ozUdvG4jR9PWAUGmLHMWHrAovOsGuickyjslmLQ/e4913rU/lCNyo2+rK1g9UQdzlHysdOGZm2Xai1IwS8NfwRpxPSdcnwzHCIanfCuEur6rmsmOZvmYvZCc8RYMoJhFerpkzv3SdTn TPkk5EIF V19gtmzGTz7E7AjBCAJkT+aRgOjwJ2WEYItNjCxFgiAi8Gr4ZAIjhaYFcLDCYiAuEFsJp5t/rjZHFy8St3mg1z/IX7ma8RQhaQyAfJhBMkDjGFQlrL8R1zDSi5RVbKd0gBk1znL+uAaTaIeF1El9JzB3otlnXUtG5KsPgnC2QguFud8qb3wghR8pySSPclkcxXFY+a6GfJ716nEVwJJw6tEb7lwGSryKmDsAb1cQF8Eh/MS6ItldGB+wxdS3dlgPljwxCUzZs134jVyB9NOcP4vt3x1iSJBangyVXx+Latxu8m8sFXJeFByNGEbBNVGIbRCeEZXnMdgy7AiBp+0KRCLVRz7m+/RTMO8FgY+tmDFaBF3YTHKtulO4zpqNCo3GZWXHPosjNfrwOrhRcr1xMe6DWVLPgrY4f6Qx0/ZYq7vwnIM1RG5ydnEbq1tY67wc4GuPvbepqY8er8iZtG05ZubMHyw== 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: Now there are no readers of shrinker_rwsem, so we can simply replace it with mutex lock. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- drivers/md/dm-cache-metadata.c | 2 +- fs/super.c | 2 +- mm/shrinker.c | 28 ++++++++++++++-------------- mm/shrinker_debug.c | 14 +++++++------- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c index acffed750e3e..9e0c69958587 100644 --- a/drivers/md/dm-cache-metadata.c +++ b/drivers/md/dm-cache-metadata.c @@ -1828,7 +1828,7 @@ int dm_cache_metadata_abort(struct dm_cache_metadata *cmd) * Replacement block manager (new_bm) is created and old_bm destroyed outside of * cmd root_lock to avoid ABBA deadlock that would result (due to life-cycle of * shrinker associated with the block manager's bufio client vs cmd root_lock). - * - must take shrinker_rwsem without holding cmd->root_lock + * - must take shrinker_mutex without holding cmd->root_lock */ new_bm = dm_block_manager_create(cmd->bdev, DM_CACHE_METADATA_BLOCK_SIZE << SECTOR_SHIFT, CACHE_MAX_CONCURRENT_LOCKS); diff --git a/fs/super.c b/fs/super.c index adadf6689611..816a22a5cad1 100644 --- a/fs/super.c +++ b/fs/super.c @@ -178,7 +178,7 @@ static void super_wake(struct super_block *sb, unsigned int flag) * One thing we have to be careful of with a per-sb shrinker is that we don't * drop the last active reference to the superblock from within the shrinker. * If that happens we could trigger unregistering the shrinker from within the - * shrinker path and that leads to deadlock on the shrinker_rwsem. Hence we + * shrinker path and that leads to deadlock on the shrinker_mutex. Hence we * take a passive reference to the superblock to avoid this from occurring. */ static unsigned long super_cache_scan(struct shrinker *shrink, diff --git a/mm/shrinker.c b/mm/shrinker.c index 471c07d75c4a..2c44c3d7afe9 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -8,7 +8,7 @@ #include "internal.h" LIST_HEAD(shrinker_list); -DECLARE_RWSEM(shrinker_rwsem); +DEFINE_MUTEX(shrinker_mutex); #ifdef CONFIG_MEMCG static int shrinker_nr_max; @@ -80,7 +80,7 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) int nid, ret = 0; int array_size = 0; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); array_size = shrinker_unit_size(shrinker_nr_max); for_each_node(nid) { info = kvzalloc_node(sizeof(*info) + array_size, GFP_KERNEL, nid); @@ -91,7 +91,7 @@ int alloc_shrinker_info(struct mem_cgroup *memcg) goto err; rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_info, info); } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; @@ -104,7 +104,7 @@ static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, int nid) { return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, - lockdep_is_held(&shrinker_rwsem)); + lockdep_is_held(&shrinker_mutex)); } static int expand_one_shrinker_info(struct mem_cgroup *memcg, int new_size, @@ -154,7 +154,7 @@ static int expand_shrinker_info(int new_id) if (!root_mem_cgroup) goto out; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); new_size = shrinker_unit_size(new_nr_max); old_size = shrinker_unit_size(shrinker_nr_max); @@ -217,7 +217,7 @@ static int shrinker_memcg_alloc(struct shrinker *shrinker) if (mem_cgroup_disabled()) return -ENOSYS; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); id = idr_alloc(&shrinker_idr, shrinker, 0, 0, GFP_KERNEL); if (id < 0) goto unlock; @@ -231,7 +231,7 @@ static int shrinker_memcg_alloc(struct shrinker *shrinker) shrinker->id = id; ret = 0; unlock: - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; } @@ -241,7 +241,7 @@ static void shrinker_memcg_remove(struct shrinker *shrinker) BUG_ON(id < 0); - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); idr_remove(&shrinker_idr, id); } @@ -292,7 +292,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -305,7 +305,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker) @@ -735,11 +735,11 @@ void shrinker_register(struct shrinker *shrinker) return; } - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); list_add_tail_rcu(&shrinker->list, &shrinker_list); shrinker->flags |= SHRINKER_REGISTERED; shrinker_debugfs_add(shrinker); - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); init_completion(&shrinker->done); /* @@ -779,7 +779,7 @@ void shrinker_free(struct shrinker *shrinker) wait_for_completion(&shrinker->done); } - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); if (shrinker->flags & SHRINKER_REGISTERED) { /* * Now we can safely remove it from the shrinker_list and then @@ -794,7 +794,7 @@ void shrinker_free(struct shrinker *shrinker) if (shrinker->flags & SHRINKER_MEMCG_AWARE) shrinker_memcg_remove(shrinker); - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); if (debugfs_entry) shrinker_debugfs_remove(debugfs_entry, debugfs_id); diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 38452f539f40..c80fd124f605 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -9,7 +9,7 @@ #include "internal.h" /* defined in vmscan.c */ -extern struct rw_semaphore shrinker_rwsem; +extern struct mutex shrinker_mutex; extern struct list_head shrinker_list; static DEFINE_IDA(shrinker_debugfs_ida); @@ -165,7 +165,7 @@ int shrinker_debugfs_add(struct shrinker *shrinker) char buf[128]; int id; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); /* debugfs isn't initialized yet, add debugfs entries later. */ if (!shrinker_debugfs_root) @@ -222,7 +222,7 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) if (!new) return -ENOMEM; - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); old = shrinker->name; shrinker->name = new; @@ -240,7 +240,7 @@ int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) shrinker->debugfs_entry = entry; } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); kfree_const(old); @@ -253,7 +253,7 @@ struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, { struct dentry *entry = shrinker->debugfs_entry; - lockdep_assert_held(&shrinker_rwsem); + lockdep_assert_held(&shrinker_mutex); shrinker_debugfs_name_free(shrinker); @@ -281,14 +281,14 @@ static int __init shrinker_debugfs_init(void) shrinker_debugfs_root = dentry; /* Create debugfs entries for shrinkers registered at boot */ - down_write(&shrinker_rwsem); + mutex_lock(&shrinker_mutex); list_for_each_entry(shrinker, &shrinker_list, list) if (!shrinker->debugfs_entry) { ret = shrinker_debugfs_add(shrinker); if (ret) break; } - up_write(&shrinker_rwsem); + mutex_unlock(&shrinker_mutex); return ret; }