From patchwork Thu Aug 24 03:42: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: 13363434 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 5F5F1C71145 for ; Thu, 24 Aug 2023 03:43:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED2BB28006E; Wed, 23 Aug 2023 23:43:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E832E8E0011; Wed, 23 Aug 2023 23:43:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D244528006E; Wed, 23 Aug 2023 23:43:56 -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 C40E48E0011 for ; Wed, 23 Aug 2023 23:43:56 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8E50AC011C for ; Thu, 24 Aug 2023 03:43:56 +0000 (UTC) X-FDA: 81157604472.24.F9F2B1F Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf02.hostedemail.com (Postfix) with ESMTP id C6B918000A for ; Thu, 24 Aug 2023 03:43:54 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="K/MrBMNf"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 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=1692848634; 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=Q1zZqEjbNGGOVpiYhrZMO0jXiprhVfWuvqN/BJwCVRM=; b=yxGvNHmjOo6bLalpoI5G+fkkGbt6AJpcj5CET4Isxd5klHVbtE11qwuddiBsOns/BhewFR Wq8VyBIygqBHaV6bxJW/wEbodcdZ2dULufj7p2M1+o8UY4oNlqPivPhNNumptYT+CHiVlK 5ETkIYz5xEC3rDzEmx5o6nOcMVLYqms= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="K/MrBMNf"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848634; a=rsa-sha256; cv=none; b=y3mqnnwfZBp0JpT2VeCg/BWiwtd059lQ2vN7plA78csb1G8OM9hKX5wi8l757c1zo/QA4g TAh4ELY24cxSuz58nUSMyFCksKNPGZnB9gRn9fDJgu6FUDg/648FAg45BuCpwTSe9mTIzu oVa0Ud86hggjG2PaeGavlQvkphXhSVQ= Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-57328758a72so31947eaf.1 for ; Wed, 23 Aug 2023 20:43:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848634; x=1693453434; 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=Q1zZqEjbNGGOVpiYhrZMO0jXiprhVfWuvqN/BJwCVRM=; b=K/MrBMNfp7dHdkm63sphyH9kM0px/L/OwegOYmv+g0wSOt5+s0OJOTKyRsMewbZYJO RY+TZU97/c1AaVqyfogCwHjn0zSWG2fDDNLlCze3otFgvG0fyCImBsKayQzpPHyFNUSw NpAgV3jhtF+TT26aC3yUKh97/fYgtxa9ZQ/i5JDWo8gWtDR9QjcpJjnnFW3umkWkEPNs nobjK9HqhQdL1Ao18CUqebOrUdqqb7bSFqkinY2DDt7xLohnwYPBy6YAuF4oRgrdwzP8 eivM6nYnzrcKzYZBshNXlM+helz+tC0kXFonrcMT2I6mkHvCD9FG51AfjLXkV6pV2OkH Mjqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848634; x=1693453434; 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=Q1zZqEjbNGGOVpiYhrZMO0jXiprhVfWuvqN/BJwCVRM=; b=R4TfYo62cexMNboHUdBz+uzXVP2F6M921z+OEQRIepMdR5ncxteZSFFBFD2iCfdySz Oi0jtAfGv2iLOhSF0bBfZaESS21zq/EuSCqAgCAuqXRlAHEhWE/RSfCSqzCh5umeHCD4 3U73Calh9C6VoYWv6Y5196vp0IKfEbSCDcjGEKILJTxFIm+i6N/UxDxINz/cJv70HMR7 he4OwtRWDk4YLLFjmEAS4OTDHVCONYdYjxyYvSB7WsJHWQ6+EgZ6DAvw75MChvstC1wF 2HOilOK5+x+4uLHxtb1Bm5rJWRlJTfJjMw7X+TQV9f/vtm358WcSSjtk/yGioc30xTGn Kpzg== X-Gm-Message-State: AOJu0YwtyjhLCNGaMnOv/UCY9kF5uW40MiJ8Nv4PAa4N9aT5Jih9mK2/ lLkUg+TL+2bp5jHW6vffs7AcBA== X-Google-Smtp-Source: AGHT+IFpwUWWwWOremRYw4t1mi4SxEeMAtG9qVGhInSAaAz7xDSk2nrbI2IvLuKxDeVK1mK2CxIZFw== X-Received: by 2002:a05:6808:1a84:b0:3a6:f8e5:edad with SMTP id bm4-20020a0568081a8400b003a6f8e5edadmr13551708oib.4.1692848633823; Wed, 23 Aug 2023 20:43:53 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:43: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 v5 01/45] mm: shrinker: add infrastructure for dynamically allocating shrinker Date: Thu, 24 Aug 2023 11:42:20 +0800 Message-Id: <20230824034304.37411-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: C6B918000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wr6feppmuwjn6ua9qrkf3nais9kjhqry X-HE-Tag: 1692848634-912691 X-HE-Meta: U2FsdGVkX1+n4IE0O0QLDPDPsYZ306O1SmIFBrvAz9zV12ZZjmUZoVE+xYgTahygESKWEN5mjNoEIiNInjBHlTTrEkp8URR8wlsSoGM8pmEqf56hPvadPtuzSfCF/Z0do9RMQleysSPBeGLClPXHpbr2yt1r/Phr9q1azWnsMQxvgJ3CsBzyyqIdaclu3TMrcIhRmG3AjE0abSxn+3Kb/6pYYBAIo1flUiuPsce4KJI67zKeBU4LBbyhHr4+k9JMGjQBvUYkr3YnsRDDmEEdDSROJeIT2/P5noccVK9hkeFr7V4o91HrV3eYnphG3ruzCJO5Msk/B4lPpkD0KefSVXkxHRZeo4kggOMDBNJcm1Yu0oSZUcMcNsi1tfjRuEraJfkNtDyIHJenbuyWDkcjzUDoL9wo2OMTVqsDykYSupXywHZS+E7Ig6ckq99n1AkljsVmZPhTEbdE59AMkdLf2uEnz4frzuuljcEIwWjIlryuNta1Xf1qMc8xyWvWtCpc1wOrPHC/DJfmorLVMHBb2gDT2/dhVdQ79DKbe6PnIq4NgoD2NRhsyQvl0iQEApIjjxiFruP4C36g/euBfOQnBcHv3f0MEp94HxOM7VDXjBC+wS9MZM+0z9lU/3fkL/I/L1k4idrLRVQ4RrBykzvWITk2637/Bo2Oft5ikfmDObnbelvzovi848urV9Ozok082ozvijaJs9YqGFZnYtGq8sxN+Lje70ha8rK8C4HG8UJQccTY7pIozKMOUcvoxKxmyqEYOiaX2NR576W1CqhIELjoz1e20XPz/96uLLuFPZQD6VqLCDMI/+iM8XF9D1WKw4JrGDAn8FrCs+nnZDfLoUg8oAQy7EyhaihkfebHzi1dyLRGm2VWSicqnvlRsNbKLcS7qu6b5KlKp6WSHZHcpvQQ1NGDD1V1lthMadQeYMMFbVkWJeVgU+HxkH6m+VlWezC2DWAmUQwHsXWrx/s akdxcQIz 9N4A3fqLBtY2bkV0QAjJQg78bhONheMwYNyD+VeNP/XfbQQgJ6mvLochTvXai7ngY7vdr8i7S6xzJzNzUlOxppp0U6+79/Luflkl765oofn2vwMyacyxbsd0IUAz0C59h0zsR3rz2M/SaFtyAr3Q+TWcn33VVu3/JKELs9L/qGHd/jRYsVhmxOXIgLhcQEeakatTugQ0u3sgNzAqkNbKKaoMHvJKCpqLBaq23u3JruOqY40vH+TGwtRJhCprQWUYmVeHvnW6+r8wVri7tYnM/HVAJvhVQfZG0RPlJMVnMmMiOYB44shJtNSLGwAzbD+4QgzdXW1oJonQKCsYPom2RbBLpNk4CFqAq/W5DOGZygs7M6jRx2g2GtCKiDb1uBxrz0o2ao+nZJ768epkrWNnCv1glGay+Q1ZhwYtf 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 --- include/linux/shrinker.h | 7 +++ mm/internal.h | 11 +++++ mm/shrinker.c | 101 +++++++++++++++++++++++++++++++++++++++ mm/shrinker_debug.c | 17 ++++++- 4 files changed, 134 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 5d4697612073..b9a116dce28e 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1162,6 +1162,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, @@ -1171,6 +1174,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..36711c5c01f9 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -550,6 +550,107 @@ 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; + + 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 Thu Aug 24 03:42: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: 13363435 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 7AC7FC71145 for ; Thu, 24 Aug 2023 03:44:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18D7228006F; Wed, 23 Aug 2023 23:44:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13D058E0011; Wed, 23 Aug 2023 23:44:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 004DA28006F; Wed, 23 Aug 2023 23:44:07 -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 E53658E0011 for ; Wed, 23 Aug 2023 23:44:07 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8ED9BA0195 for ; Thu, 24 Aug 2023 03:44:07 +0000 (UTC) X-FDA: 81157604934.07.D1D3EDF Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf01.hostedemail.com (Postfix) with ESMTP id CD79D4000F for ; Thu, 24 Aug 2023 03:44:04 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=OsYjiPgR; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 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=1692848644; 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=5bZcZFXaHuChrX7nBw9iDgTdYuFksNGnDce9dNrUq+rXKDJaGYkYRC0IKQmiSCMEOEARaB 8tiQYz8rkWEPVlXVy9WDdZBlK7taFpFhAIZAumnwwgxYgPv4EMEHqY5EFlsa2ZtShdbwiu 6L0V7G+cOH14MkbmKkfiXjcp/pnkvcA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=OsYjiPgR; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf01.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848644; a=rsa-sha256; cv=none; b=qgQcNLSZrTTzxKtfNuDrs/ouOu1/IRxm6CaYGHb4LzGd1afK0h7JzgZQFPkriI2ZOp0uYk sWG6bJ06Cu9wTGlNPboPLDzEP/svXHHmYY4swubKopad7M1zYyY2O09QEytgCUuyhI7LCO pbepXVKgq8omS0zSiUByPtS1GpwxMr0= Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3a707bc2397so848016b6e.0 for ; Wed, 23 Aug 2023 20:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848644; x=1693453444; 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=OsYjiPgRzrTeETdk6GAchasY+z5fr/eZhmMBlkdIascYBtVVr8yTfuT5MPzgyaDuTX GP27vx5e3ZRKiWmF8godLPx25zsGkXM7WpgRAlINmRy7OtyQBZMd0woJ7eRBd8ABjz0B gg0KXTzJI21aCRCVIqH7SIRY1+q2UC1Eevp1gZIrFwnGhfMs71V461lgE1bLRRacaMrl VvaxQGpwJpwk7Ore7I/VQ0LQeEZ8Yda/FdaKJLsSrCojTzfm74tjEvkxxRIsttzCumIH JYDNB092mTWiwSCXEE9fsozeBAYzex4vsPbHJSxRaP6Kzq97D+z6ONh9Db9HAMNes38c GNwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848644; x=1693453444; 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=C03DASX5Fci0DP366tM3r2Utw702FDdBpZ6nPR2xstFvZ0QhIC+3LFStn64yICcjK9 7RuIe0xVttoxRlCJ4+bgMv13e4uKZzE+DAXk5l/XVW2ydA+FSHilKKXD9t6ZxFjCMro2 Vs1fh/1S3iz9xm8meQuLbYtXo3FVtBBdNhgyLEBFu/PJILDiFWd4QZ/R284ypRZoy53N dGNNTpzpkK1qpuhv+nOTHZ+6Pjx8/OOI5tOtksFzasGXVK2wjxUT++UC1X2h621IWjFE Y9lbFF0JzAAu6scwz6xwqLwFH2AvhFaHsTVcp4SQakw9j69OY5YIXcU2xDtyWLY2iKSW +cpQ== X-Gm-Message-State: AOJu0YzrO1IqHeY6Av3wv/OzB5Rs4ibHevvTINDkXfInl/nGr8SmtCix 7wgcTShklX7tfIg95PWMVCgWVA== X-Google-Smtp-Source: AGHT+IEujkxb/oLvenG0xAi0WFnbnLyYwhJyu7dzjt01VW0xqm24WtRNYpeYKjaTV28dKNThLBHLgg== X-Received: by 2002:a05:6808:152a:b0:3a7:72e2:3262 with SMTP id u42-20020a056808152a00b003a772e23262mr17143493oiw.5.1692848644029; Wed, 23 Aug 2023 20:44:04 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44:03 -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 v5 02/45] kvm: mmu: dynamically allocate the x86-mmu shrinker Date: Thu, 24 Aug 2023 11:42:21 +0800 Message-Id: <20230824034304.37411-3-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CD79D4000F X-Stat-Signature: najunmd464ctjcxty459xgujqs34ujjx X-HE-Tag: 1692848644-647573 X-HE-Meta: U2FsdGVkX1+Wv/HFgXFS61R198ZPFAOmM+kXzXrBe7jR3AJn/2f7v6SLTmdg3C52eRDf7pxdRwQw1ByhWVkRrvr4YlRM8VeqAwBR6PJTPcnXBg2H/C7K+pPPuCbO97WpvUMNMCCbN0bG4H3KZhUI/okilsR4rYSM7G0LGepVXX2zCSkWGfFO2PGAnYLdXRRYH3EADOyTtyurWiyojoLOPCsaLUa4n9lvkgzn/ir2D/ybfTEr53CWqjr4Zb20evv1vJw6A+HoykCvJYMLn6+KkJFe/YReb6bfVSoQOtgYPZX3We6YnSR/65FiZJanEXluoaJYFLUckPJtQk7Jb8JHHh3ZGlB0ehVAJhvnCCLimVIFnegGfPjWNJyjJR+PWalf+8kFJi4/hwcifBTNn0bNQ0cQX9gNy+gect8VbR7IIpr8uYgZModAmhx7FRhnTBGwxta2lUGI5WPCvB5ldrgmbZQLdIcDGPtimWhWmLJPtSViVXXt1wshuRg1hcu1a4VIqWh2gAzvArpZK6v9Y2nKunU6UfZH05GtlQsYZVuoxVxNWn40sc0KEGR/zZ8csKbuC3g5V1NtnctKiBqEMippZtG1t3k9P/+nP39xMd+bdpCR1sCz6ga/T5ngjyNlAHvuF2M/tt/qxHM0JgM9q3/GT0oqx/96jw8jmf+3wpPGqzN0gv9N3R38IydbfXdR1OmRcw16dxsHahVI5d+h81M4ron8eS/RtYSSkGbe4IhonTw1pejP2RmW1tZvsPvDZR34juv2zuYtOrRQvWPPG9mrDPq7BLnoeElFrYL6aPHDjOuWyZF+Ab9WtWMNmSu0bvteJ4PmbIYDhmSUFqJXLZ0wDDUKObLqvEXYwkbdW5ReGjOeL5ASXFjWly20GZnjPSOU0uXXFiS5k2by0LtU+2NnmxMi4HfdLhhQFYH2uYqI8zMWFVSigL+Adlgo8ROSs/1xlMEHWWXDyJRHbylD4py NI9izwKq Rjid1tP12H4pMY0gd4rWoTIbNK2QyqP2o7kYHWOuzFCpRuweDx8aJfCCbaM0vcWTPU2Sd0P/PiIkoH7yV6JeX8zP1h8glMigKwlTNhf02ZR5CDJw5h2sFTB2OkYAYDKMBqqBjdf5QOeXYdbKez63gn6EsqSNlliny8YF9aSpgDEXPpKhJcLpLeHq9QMpuWTXlKGPIWqzL5uvW42cKBdbrmpBm7V7K9/3MytA5M40s9Mwy8PHc5h4HOEtJes2nUQ+1CviNgIwYOCk4tcNIz3kQw8hsPxGm4CumlrFh4LJe8UEo8P1RxzQCZmU7fedE+bcZpfXbD2bxSYYbB2Wb2hO1dRW52Xc84XJQ25HR39JqdKsDINMPJDWpPiGw3MoGGuJ60aot04hkt1rwgY+b9LO1cXd3+ml2llez8q7Vq0GeXvLKUQIg85SrGwVrgy9bwGeehljFEh3ijNrzZS/uPKxxV6QrAC4WpODtDzGtbo9IoF9lDDSHlfY/+RzcemnagBPIDSKuTdNBo4ZImAE= 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 Thu Aug 24 03:42: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: 13363436 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 3B810C3DA6F for ; Thu, 24 Aug 2023 03:44:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD72B280070; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C87288E0011; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4FAA280070; Wed, 23 Aug 2023 23:44:14 -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 A3E748E0011 for ; Wed, 23 Aug 2023 23:44:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7E76E1C9076 for ; Thu, 24 Aug 2023 03:44:14 +0000 (UTC) X-FDA: 81157605228.06.9DADD47 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by imf21.hostedemail.com (Postfix) with ESMTP id 9B1B51C0015 for ; Thu, 24 Aug 2023 03:44:12 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Iz2/0G+S"; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 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=1692848652; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=xSFECfd+Br6KflU5L/t2xi3Lv5peVKFgOrABPtV7L4gnqJa+i13ZW0+1MTHK6J21PWW4WN TNb+P0Gelxem9BXAMPpp28r7hg4ln5Y/kzPLDIQTMdh4AfbIlzRPgUnm/tF7NQkR7pHTN+ WJILDfwGVMv6vqhazJ1jmei/xNfkE3M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848652; a=rsa-sha256; cv=none; b=1eUqjo+yrLYRD6V8GNLVvmg4OChqvUSlzlEgjwtURMA5Gc2PjisoevD35YOfluNMoMFNnZ xvrQqhnKjnYQgBpux+XiNtXo37/2cPkyn2z/rMWrJzhc9UxYwcn6L/Vgqe1c4mRLcHwg2d w2QH/pR3c+q6TkWx7nAnx6e7seeX1A8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Iz2/0G+S"; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5711d5dac14so204179eaf.0 for ; Wed, 23 Aug 2023 20:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848652; x=1693453452; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=Iz2/0G+SOuFIIhaxK3w/LEcD9PS4zKZ/5RcLqJKJdh7uItCmfOpE5/jAV7CTQYQwrv 9LBEDsGb7OQVTT0y75+W3hmVRKD+wPpekmo+U1aWv4VIpRlze67WWzhGK7PvHfv80+Aq 22HTG7tQsAc/n7lxTDb50FgYJVxBohbov3zGbdkxBFRg2+u94qfoy1WCYE/6SjCv6IEm ltAHVGpsm97r2LYMNXe9UbJZYZZt9/2CCg8ESzyBAJkE7r6xfLbBYY9uJptQzOq9AB8z gdd+zPqCkxoqARc/NmfQ31JLb8MZu5Pxd2lkneChOp1kQa9CHtD0HIZqJbsdwGK/j8pA D8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848652; x=1693453452; 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=tDsQ7RYDMLqwy7twIXuFD5p94As+lf02HfuxyLHsCC8=; b=Xrg1QPxpsxHHzA5ZA9sI58kz7lUoeo+ZT+GZqujcB91ZXhJxf/Xncy4qEKseDt1m4E LfxBgVTmnI2zjn0C33jjYIN5WTiLUstNcsBwpZ/ns0FSEgf+A1CDeRz8F8bVzRUj7l5L msl3Ey7RcRB56ulF44ZwYifQIghtmf5pOtnCP9QOQANCYX3Vvu01TxFEpnbUekgmPRrU RZq7ZxHX+GcqLXrtO9U8ap0qAmBQp70EJHKv44I/rDISHygCWSMtbKgRYsbHXCG/vEkh N/13Y1zPaEDLLgm9F+2NlIifmfCfiiMCrqPN0bGLvY+L/ALRc5WC4o/3lAXELMrcJv2A 7deg== X-Gm-Message-State: AOJu0YxdiyiAA/cQn0YqarbHrnxW5jeeouG3rsVuojEiXy68Tc9lWjpc xDEReIaRXmY6do1wueetuMUcuw== X-Google-Smtp-Source: AGHT+IEM8N+jMmp+ItOCDi7GhGIbRWYtk0R7RyKurKUW+QPYSbNbY2W9LIX4qInIQ/vDJIM/8yTcQQ== X-Received: by 2002:a05:6808:1a84:b0:3a6:f8e5:edad with SMTP id bm4-20020a0568081a8400b003a6f8e5edadmr13552232oib.4.1692848651831; Wed, 23 Aug 2023 20:44:11 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44: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 , Muchun Song , Carlos Llamas Subject: [PATCH v5 03/45] binder: dynamically allocate the android-binder shrinker Date: Thu, 24 Aug 2023 11:42:22 +0800 Message-Id: <20230824034304.37411-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: 34wyip5r1333q55zw711atb3w6hfui6g X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9B1B51C0015 X-Rspam-User: X-HE-Tag: 1692848652-465452 X-HE-Meta: U2FsdGVkX19Zj3b+nyumsOGWXGwrapj2VeuGmytKJ5103/TcfuWXz6HHg+5mATwkKSotwp6KoLH8odG69MID1/Hz5iBZfWlRTJmeyrvgGuVkEOB9cB5PRQfZs9Kav//YkjoBLExDTUQ/2ZNXvEfTEe9ea0/71iDnBOzQpSgFNcXwO55mA5DMWg4Z1o0uhe2AEQN0DCPLwkfGwLn7YWkYtcOJz8zST4gTB0Q2yOJzshFkd5rbKKZl8QPxP44KwqG3XpQ7+aOlR8JD8R1UhE0+VgC7qAg5FASX4DbO1JJmjldTrO62uG/+WDE72QAdEqJymQ4g7GQzjqAJpv10VHfo9kL7tJmQr5Di8hQ+mg4jxFoJYSFz4SlPnAiZc0PLH2QHS+on1C35Ii286RSy1JbkNHJvnPoqoH69vs7GjctKez56BI5LvxqniObzAlzrn8rngdwYYRNFKPRlhjrgLyY0fkuEZw5J7p/o+Ax6qgkuNThMi2jI2Z5i0o3S0Kaqqjxez/XD4adQqlL6rfP6j8I9DACZAcxtiCPqPFA9PzhFaaaapNaO6UEEXxir+ZaFflr5DPbUJnhodKnp/73NnimU9s6OYUuAUM093zvGMkk1A1r2VLHbCkKGXappUXzi8tXSb5ISlg/WH254pL29eTN/5p9D7wZI+mz6rJ/pA1LTffICWDGZhqzJRvI7CMjqFMFNu3qWLk0y/cZQvSvUg54Gg1CHKpcTy8stHS7EDOV/ilVOTe+bS4a8Ku9WHnwOmW3cbQNo/RDeiiIneJ46ON843m+BhthruLUxOyd802WcjSShlrGomb51mg2ZU+hoT87cv42Q2u+/WqFKiqvLt8pIMB+HYgHzhPd978GhN7UOfea091+Ev049oSSYCXMDTN2j0vCboEc5cm3Tjv0RjrOufKVqZOSOmvKcp2qF0LSXvjTi9tVbV+hRDAdGDKYNKkBkPIuG85X4haarGjHE/tL jLfRWJQq bNwm3i+Jjz2EzcUiGhtXYECNlNDHHmb6rgiQ2LaT18ObG9nfc8YSRgCM/GHi6gj8TNp1TcNbFzjS/FiG39zYreecw8u8mexFD9e9raS96u+2fP47C8UiLO73BeU71vRXAwnny+uivwt1iPwjZxsu+5im0Tr9RRPoWqZ0Uycp0X3+tw0CNdGPZt64UyZ+3Ti5TtzbhM6/3tHKr0AWLX/2qoG2qFeAYgJz2nidTn+eqha7mtCKprmJ47NP5Ur9HsfXOAXbFhjvMdWvv3WqdaxqU+2WwIY4IPUprQwTh7MB/UrYNGvpCiZod9R3TKgiGTnezFDKcrBS1qGlzNREnGrHaIfTQHM5TbK3byw83Sm4y4Gm4WMnvK1YIeRd43UOZoDbZuRExWYj89BtG7DkT9hpqAlWyGyPmb6rnzguf2GgWA/1ukvY5zxHppiZ0wboAq0QpPwj3XxZ5Dc59Bd4kq5PDmGXNiQFm2k87Woc/Ed6Vx4buwBX0+Tb21pBPig== 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 CC: Greg Kroah-Hartman CC: Carlos Llamas Acked-by: Carlos Llamas --- drivers/android/binder_alloc.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e3db8297095a..62675cedd38e 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,30 @@ 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; + binder_shrinker->seeks = DEFAULT_SEEKS; + + 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 Thu Aug 24 03:42: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: 13363437 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 4A8BAC3DA6F for ; Thu, 24 Aug 2023 03:44:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE876280071; Wed, 23 Aug 2023 23:44:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D98CB8E0011; Wed, 23 Aug 2023 23:44:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C39C7280071; Wed, 23 Aug 2023 23:44: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 B2CDE8E0011 for ; Wed, 23 Aug 2023 23:44:23 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92C07C0145 for ; Thu, 24 Aug 2023 03:44:23 +0000 (UTC) X-FDA: 81157605606.28.31DC0C3 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf24.hostedemail.com (Postfix) with ESMTP id C462B180012 for ; Thu, 24 Aug 2023 03:44:21 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=F7mx7Z2S; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1692848661; 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=iKFCQuC6rvhDz+4J4ZRz+5k//Ugm3cNSHikZ8eTe9hSRcgRmnZkmrHK5E2zw3jMmmrnPYr J4DZAuPVPl6unbKx1QTnAnzS2D0X69vjyc9ytV8tmA/RO386n3n74Zs6yWtTxGQU6UCoUk Pg7MZTdNxQlu/wR9vw1dMlAWiRBECzs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848661; a=rsa-sha256; cv=none; b=2v0hRDr8SdGNywpH8KV8aTUPkWmN2l7z2605JQUSuqaEhsqqwIZOAakoOdzKr5v3EIRNQ+ DatLab7xu1dR4GmcSe3TxI5Z32PfHvTqpB+2LKUg+GDJ1Tfy4kUicMSZbK7Jpscj3El/VH T5yhTjpgEUlGOvnglBte34rIpK6tPqg= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=F7mx7Z2S; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so755701b3a.0 for ; Wed, 23 Aug 2023 20:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848661; x=1693453461; 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=F7mx7Z2SATT/Tw8oqVu7LGCwIgOY9q6nNnmh5/ganhwLW8GaQrL8dhMzkQme16OyB1 4ZcrhSW1iVS/oXJkAxqcqvYnRC8V6z5f0tnKQYSO6HG2Ws1pP37Xuc1otxDqi5KUNw9T WVRuI/U+MbwSKZhcaJBbRNgA7W3KFvvzyeKOBXeWATvONSpA9TS02B13yxyrYGxzzveW u5fhQzEptjlMGS36OjAsEf17/AFamZ+U3xOMpKlF84KqegOgtZie0MuXeEOyLRhKQDjM 0P+76n+lplLjw7rWWL6ybRhAGOOQQQlRJmwWoHvL9CcCs2DRS/s36iNm5swp9kdFbKCI NE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848661; x=1693453461; 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=FEN6BWzPLnRkLGNe/ochbTzxx09D4F+TRjb1Lxihr5Cf+MsuPfa2t9oplTLNTEOYRe 6XcYjZqNnHI9rJHKWkMH5og2fLzp3mTmf35YV+A+tpdrjPvfAOaqt2Ss5sC4XC9Dh0BQ nxOUh59rv4E2M6JAlT1XyS+tIe5AipLjfc3TpOKGJQWhzjJ/akrNUo1bq1LoQIPEeJNC zls/+6xu8ZL/WnNR6h7uP3vY4afo50kuwBfd0UbCk2cUK9ZCZUa8Zj4Ivh7hiYj5O4Kp cuygFoo+SUueLAkd8tzNr1qrs4+/G7wR312n+7O7L08TfaMHMsA6zDs3lxonAZDJRw12 3XgA== X-Gm-Message-State: AOJu0Ywa15wv3rpbBDdk4uLbMsTTBeBcOprKXU3Rvrs/gkz+co1FK9Ie p7xY384VtTprtDBN+hVbOlx3ZA== X-Google-Smtp-Source: AGHT+IGMOB5tWYNyEDyo5eiTNUNcN0ymONSI8d47WEA6VQz24qAk45RADJx4EG80WGrowCiJNhDryQ== X-Received: by 2002:a05:6a20:3941:b0:137:4fd0:e2e6 with SMTP id r1-20020a056a20394100b001374fd0e2e6mr17386821pzg.6.1692848660762; Wed, 23 Aug 2023 20:44:20 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44: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 , Christian Koenig , Huang Rui , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v5 04/45] drm/ttm: dynamically allocate the drm-ttm_pool shrinker Date: Thu, 24 Aug 2023 11:42:23 +0800 Message-Id: <20230824034304.37411-5-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: fy89jtojqp63udk1wgtj1eqrejx3u5ia X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C462B180012 X-Rspam-User: X-HE-Tag: 1692848661-584331 X-HE-Meta: U2FsdGVkX1+VqxB83xvIH6+jTzcuxdvSo66a7rvczcaYVVrtr+y25/JVT3WkfG95XCwgPEC6uBVFhcUauYPMnh2h08JkPxqJ5Ow2QbAoeXQ91nhkANO23p+kgMRD57bHvQHpvW9gdfQJURF+KJuVyGeHt+F95nt4NgoL5vfGvQG/HcTre+dPq5cmG7sPAguMrCDyL6WKTTZWA26B0AZCuv2ENVNqk6/+zfAJYTEjhS8jh7A4AmMV+XkC7cg4WrlLgUkN39AIzSENWK8VoINKgwfpKnRbKVcPWBLYEuDeDfAVFkvlHzrkLsY+1klPr0wfCGbiMn0eJKyTz/lC90kIKSS8EK6Lsa8lgS3QYRcWsK3qzsg9cD8RIQAovUDdKfCqUaFeMc+KuAG/S7DeyXNI+Hppk4iR9mQPMUm6XrA5GxPZ8A3C/WkTfQCKX4YQfli7OuAADamZxvSxAahpXU8P492+PoKLUIkNceoTKkg42mXs5iTEaah9ebTYBJa6Ba6bRRt+pUQ2O7WxuNXrCnqaAyc2GLKhvNcctNNZbrbkbxLsR6TP6si1ehnU+q9BSfEvt5BH/d3p7iRF+qRv+0nY4MmDJha5IBkfeLFDiaYnzDkqeUKhE2DPzA5Udf9kHCHFLxDG02fpRqLUu1FPiZz2buy0/jM1iE2PFH9CTO20YpOk1GUzZYYpx2kdberR4eop/NG2nWlixZhGLMK+ZcgdWSx8aSCNYiy8iIQbd4SmfJpCQYHx69M1C9gjF5xusQCutrkqtYX7r2rAj4m/w70955dOZ/0gpO5IrQnAkPdz4mcDBzsomktJClF5e+ZetSSliHlVJuCXR0MjPujCdnt6NmFNNximdx9F8Plvp7aU40eXxbCGcEuRhE9S2qSHt0Ikh+1ZR3mPcLMq2ine+3H/XXOCFkDTSn8kUB0FXhiHMGzP7qjIuA3lrQTvuXgZ5iyspkm9+U9CkSfJYsF29Kf CWYOuUA7 sVQLO/+R6EqmrJOMOs/EFzDBkSYDcOGWumnYXS5HbS7jB5691lRdNbCWtf6gK1szEokR/Vm3YfEZpVjfZIKrZWiOycLjm8E0R37L7G00bAC4Pm8PC+pZC2kxfhmn0z/0xYlDMc1WRdIT+JX3IhuGtaVYYGYM3caOIfGNXUDTZ4nLZLeGNVfslCrUeRvsTMC4UNUscV5ogZAD+v0ReKF7csbmkhauU1Vt/mKmyTpJfhiI7lfe34hFlari/gljs+uZYauwIeFFu/EOcyiuTUOVas//jkP5qDiz/DOfpJGqwwWQ+jREP1em1AXr/jI7ysbRv8chERzXXV6DWB9QSax+7EalahPiBDZqvmPrBUXjpJI4mqIwDGNYJeY33TQCgXFnlPPINzmBwLWyfwdAyRqknsEg25gy2ELi6zetqMSyDTbnuchM1XRZ4jbeI/GNhCt90ongqrpxuucu7KSnkzaSfVxvaXvdGELJLjFAUkP0eBJzDuyJoPA5gAMbtlR8dx/FRdEY1i+7mqD7dIAZJy7VlmediedE1B8nfYggw/S9+DmChxGwJVK2vy+k2rrpOpmjoGHP/ 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 Thu Aug 24 03:42: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: 13363438 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 A4251C3DA6F for ; Thu, 24 Aug 2023 03:44:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44BA5280072; Wed, 23 Aug 2023 23:44:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3FCAA8E0011; Wed, 23 Aug 2023 23:44:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C40D280072; Wed, 23 Aug 2023 23:44:34 -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 1D1188E0011 for ; Wed, 23 Aug 2023 23:44:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F41AA1C902C for ; Thu, 24 Aug 2023 03:44:33 +0000 (UTC) X-FDA: 81157606026.23.438BBFA Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf22.hostedemail.com (Postfix) with ESMTP id 3C7A6C0007 for ; Thu, 24 Aug 2023 03:44:32 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bY9LD4tg; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 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=1692848672; 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=fL9UzNFH9xRc40ovijxQr7+deLFTeJc0QRJlNk7UAJE=; b=CdGUL/JkGww49LwI7uaMAF92jA2Eu3ADLqLVJphF5Nrds8IBUywV7LdDpjeXZrYOwcMMtu mAYOx73NojgT7keLEEK4GfNyLJ9BRNh0zmzyDLbaq+pRQwhbZ9HyzGdTXNAX18IoDc6dkB Xtmg/DB7+Lybe96CKBh0MgnTyL3E4Is= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848672; a=rsa-sha256; cv=none; b=liWxE9b47KwjuOUPa3sNlPB0QaPRLKFkwjkOXbaAm0q2XlYZuMmAdBI1jeCFzuCN/oQrBn PKx5AhNpfea2+Ys2jX6vG2MmPXBVxOYO8iZClv3egDLo7IqSqt+kLvlxi/za7zQRDLpUlX QOOWjrfed0OcVUi2OT52Q/WQIum8dKc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bY9LD4tg; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so755737b3a.0 for ; Wed, 23 Aug 2023 20:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848671; x=1693453471; 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=fL9UzNFH9xRc40ovijxQr7+deLFTeJc0QRJlNk7UAJE=; b=bY9LD4tgkqWxkQKKd/RDOoX5W8qpuGAecHeEhLMfDjHuJUY0svZZBxoximm9J6Y19i IqrrH7xW9H7peP2arsnyh17grC5SQNfshLtri8kPslLmcIm+7WgUocRo8Yx/4Tfw2jXR c3uYDXcSM/kuK3tPVglakJG9pBHZK8VSYZiPXSkCgitJGmj1bNL4q/waTdyTfhOKwshR aTWnSB7OVezKYHSxHn7x3sc27R1ATOK+S6Og+iQUPKgoVWwop02aWHbGt7Gzi+eH1aCx GxgOchcaZoRBNIXtV5nUG7kDq0z3sxxuYYxZNhstl4e05qGO/BrwD9AQR8U5OepcAJBK FutQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848671; x=1693453471; 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=fL9UzNFH9xRc40ovijxQr7+deLFTeJc0QRJlNk7UAJE=; b=AVr6RkaDcXtbk88QLErTVTIE2QfZoKAO77Hz2U0s9bwwM681GSWn9mbjaZrnACE+ox wHkQiirqSYIPgMeBfkTSi29CNE7ZKUTa1pkxdvWJUx/14sF3yV8smFZl6kge9UL+4Flu wgUG9Qtnlx8kFhA7ZwWhjlUiMjmFHBdqjwCOrlXbbH74o5DzXbAzVk+hMNkTHYTifvfV IcIfw23mZIfbPrGsS0cfLJGYwA/DdBJZu2NPy0ZW3yID02J/L9p6jZ43SqewqGzSAb4Q gyML+uGzLf61lq0yhDvkd0Lph9QtAIUkhXTw/gIYts3usfHzIbM3aqFbyiHXjglyd7gl B7RQ== X-Gm-Message-State: AOJu0YyYQnvGLFGdVp5VuVQw3DnWBBe3micQtaFPAIa0T4B8FyFH563v lUitrcaelcPpcU8LJl249THdfA== X-Google-Smtp-Source: AGHT+IF9XwmI1K/7s22ZAfh1q1VXcTL8c0ROJkv/uTQnOzzzUix0h5W4i5ROCPEGbt2KzyOxEQAr3A== X-Received: by 2002:a05:6a20:938d:b0:13c:bda3:79c3 with SMTP id x13-20020a056a20938d00b0013cbda379c3mr17551017pzh.4.1692848671217; Wed, 23 Aug 2023 20:44:31 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44: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 , Muchun Song , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , xen-devel@lists.xenproject.org Subject: [PATCH v5 05/45] xenbus/backend: dynamically allocate the xen-backend shrinker Date: Thu, 24 Aug 2023 11:42:24 +0800 Message-Id: <20230824034304.37411-6-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3C7A6C0007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: dnbaqqwqfmixpm7j5n4gp1mis358k4dp X-HE-Tag: 1692848672-443766 X-HE-Meta: U2FsdGVkX18assiMUz2MH48S4ouA0rWXDvtl2zvU4O1vmn+xL+Sv9ZHZ2RDymmUo5DmdjXg7JtNFkNh+ae7iHHNWCZkaQn0kl//RES143OZo/H3MUOvAX70iK6F6Jr/BD9E5G+xVQklcqBzrdt2SyK7O1jv1HCa+LtE3fN5G2qVWc4fZ65CpbsHN/jaNQV3QtDU5OQ1eJIs1pxU3OkFYtfQXveSP0veBlzLeEn8E643ICNrlh617kd7yipiN2scpxQ9MOM/0JzQpuJRPSwKOSYBMzNMNWaP1aVOhNnBK9ljNfa01ySyJQUEKQ1FCgFDBPo34Via5Y7tT9DHZuCEdFpuniJSn6KBMRiXoFMRaHfRU5+BVmtA9+bKHadgM3aaRIQnErbpjecgMNSKnk015bq4Y+l7tnrtOMh8JOPQWCEg+SJIQBTmBwO39+d8RfG94ZVc3QOgh96yGiUOTce6v+ybgOZJ3AJg1xDcC+Crjfjmhfqm2eaTWln9V+luC5iEwVQsGRG6EtnOnr0Q62q6dN5wnPpYWRg1xFED8EsbSkDJYDHrL9n5mhX9U4QtW5/r+zqJwjEU4y2guRY36W7gMg9ls6hD38NfCWh+wkw0I9ySkeMKXoAIFzIKqk7q4wHtqNBsXKv2e3HWnOc2irCqAKJ/IyF7aKbZKYUBV1rmbepHHU7xQ/0ZqYolFShBtRvZnh8cyEieTbuiWUXAPFwpuY/nkbfBbSQL/lM7Iyw+oD7BCoCurK+ecYWSMaq6AImsW+87fBZPXvG/PJxvVGYqK2pwEPxPpx3QRQOdNXT2NH3wXta8YCrXClGW4TOJCvF9+Q9V6uIPWhby3kgP95A8tG7zsOoYj+jgb0IdBhPvuShmU6roiwp9zkVPfZ1NsDtr7y9MUAatxq8Hj+eL4aXRbbQcy7JuKDPBDVTQO3+8BDoF5TK7NH/Wf7w3L4LmJCSXDYvghapTkqfDHRPHpWMt mvHfCTS4 vzjvDojH5JQ73REMIrO4poexQA+jz3z2whJ2rLHJnGSaWb4gdpHVXQ0M85PtIELgNjyN4CBDk0fpY6Nhi3lCe72Q9uuJsuAEr06rQDpgIXoq7UhjBydEM5umlu0ze13Jq6DxOazwMIPLdS8gbHJammvj/oSy2ECb317XsNE6+oblm3KSaf7CHD3WQZ8YWQvU/1QGpmPnww00f4KZPhRdaWMXPi0S63WzOTahD7HQBI0AK7R2ab5lvQGMtw/zjTp91kK/GiDQXNjgYCnCtj1K8m7pKHX6NZKqYaHNyjNNeFaDl6FHviAZah4UPKvoVRfu4jFgmdM3whw2XjuIPJ3be1fzlsBFuQAaH4t6Gut2O/u7NfplEGQe5PaL3FcVXzzWQzXOeYOaNJepQMYnFPJwQ4xZOf4XnrXDY9BGd4rdVZcL2NRq2Aa62cL/g9uXnNPm7TC9UdfcnoSqY+nxvGqFnbYF/1KmZEXbgGwhgNv45I9FC1m14p8hzhlaKndpuZn91S3s5N9XCQNhJw2SZe3c0Ep1GixUd/VAO//JJWuDHYggy+kswfhtIJadvDQvil8mSUqM1TNd3igsQEykMdCAHSJyRkcBIrQ7wJWYL7ONRIlS3GLxlmopHw+x54TkBODwePonQWGWR3pSll9gR2PkSQnY+/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 xen-backend shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Juergen Gross CC: Stefano Stabellini CC: Oleksandr Tyshchenko CC: xen-devel@lists.xenproject.org Acked-by: Juergen Gross --- drivers/xen/xenbus/xenbus_probe_backend.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c index da96c260e26b..929c41a5ccee 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,16 @@ 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; + backend_memory_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(backend_memory_shrinker); return 0; } From patchwork Thu Aug 24 03:42: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: 13363439 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 36451C71145 for ; Thu, 24 Aug 2023 03:44:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C630F280075; Wed, 23 Aug 2023 23:44:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C12DE8E0011; Wed, 23 Aug 2023 23:44:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADA9B280075; Wed, 23 Aug 2023 23:44:43 -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 9DF9E8E0011 for ; Wed, 23 Aug 2023 23:44:43 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 717A680167 for ; Thu, 24 Aug 2023 03:44:43 +0000 (UTC) X-FDA: 81157606446.16.E6AF29F Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by imf25.hostedemail.com (Postfix) with ESMTP id AFC84A0010 for ; Thu, 24 Aug 2023 03:44:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=gHtaEy0l; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848681; 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=lY6Vi/2E/8aKoDMoFhdgeDuzJGEBhcHcwJKxLN5aRm4=; b=8U7KAN98cTbRpT+8k/PUL7Ncve2JI8NjBVFCRlt4JbeHxY37SGh7I6Tm+WIQmrn310t/zX owW6rq3BZXzUoj+pX72EUTVBPkJYm6+H2JJtAKXWf5nN9oZ3ElKaROmwGMuTco1cl+GOLN I67h9YLpbJvaSHChPBn16QRW5KHptCY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=gHtaEy0l; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.177 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848681; a=rsa-sha256; cv=none; b=HimEMgmKP3x5sXRS7xTQ1St1tAFO1cDovOqJtwumUM+83IMCT1ZPr+vjMIpRLkJA4uskVC 8y/fV222y6AkevxbZCxS/wNbO5QqQn0OSf9z2tGxnhH52IZv2GeVEiBel1HFZzO8CpYk2U 9n+KEGIWQwTYXkg8MQcu4POoTdkg3kE= Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3a86b1114ceso349113b6e.1 for ; Wed, 23 Aug 2023 20:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848681; x=1693453481; 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=lY6Vi/2E/8aKoDMoFhdgeDuzJGEBhcHcwJKxLN5aRm4=; b=gHtaEy0lF74Ntkso7g4C6I/YE4P2dpDs+7amPy7WakPzh2kjSvMiiaFri5oP5OIPtC BfsgxJG3dolAaeJ2n+Yhq2chgoukBpNASEoJSTjbYwJljlwjXrNh9kx520+RsCMTFI9a cZRaUUBTw/fsxlcCpVpRSbHKngHy3yg6ERr+RLU72xkk0Hn+mGlF4r5SkkNhy/H1qmC/ 4YbOWxnFhSSxA3RyOpAdhS6L/9ifNoZvavLY3HZvYg4yrEZzgzD6jn7exa/rpKElUHVR rTIHwS9nbuifcIi3X9sduJyAWlvrWQdqWxFvFKFyC4rdXuEY8eTaAP0iyvcMIEJFSAPS QpDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848681; x=1693453481; 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=lY6Vi/2E/8aKoDMoFhdgeDuzJGEBhcHcwJKxLN5aRm4=; b=NeZVZyvZwfQsJhL6uFOyLNxv/YBPG3yQI1AL2AM1g22P76K9KQWOL0geGzP9ZeCBVm 4UppGhh9zK2lLfjrVsFKH0/3ifpN5JwwoOfIRrqME6FfxT/Onfy53r2WEDTHGS08M4Uf u1qwfGqkj5IF6Mz+FF5V1uog2cHSMk0EE+eR+FBNSfKP6f5maZTeraNv0yGOr0MDinSG vJn4FdNuOiEuhrGHdtfoPBpTYhVcDMLPO2zOBBtREjQU9mvxRs834sX/K+Q2NtUGag4E Ogkkn1kv2ndQnnbyaPAiiW0Q34ihsqyeY1C6p+R/esp11bB4EZ8bBVtn6wwr3sd2V90e M/Dw== X-Gm-Message-State: AOJu0YzRLUjwNZ99aqyUNnHLA7DFL9vXJa737o0j6LqSJhPU9jKkU9Sd JBQhQ1k3ekY2FIhRucdRrO6AtA== X-Google-Smtp-Source: AGHT+IGSn8aXVXktFOZZa/BcVGbtb8f6zEZDLrwOYj68DXtiQe8FLStK6m/pgQCqQbi7Z2XDHrDQOQ== X-Received: by 2002:a05:6808:30a7:b0:3a7:2eb4:ce04 with SMTP id bl39-20020a05680830a700b003a72eb4ce04mr17475307oib.5.1692848680931; Wed, 23 Aug 2023 20:44:40 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44:40 -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 , Gao Xiang , Chao Yu , Yue Hu , Jeffle Xu , linux-erofs@lists.ozlabs.org Subject: [PATCH v5 06/45] erofs: dynamically allocate the erofs-shrinker Date: Thu, 24 Aug 2023 11:42:25 +0800 Message-Id: <20230824034304.37411-7-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: ys4iduiixjiynb6zn3935h5oz6t3ssdr X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: AFC84A0010 X-HE-Tag: 1692848681-321835 X-HE-Meta: U2FsdGVkX1/aJKPu4EAi/JQkSIvSRv8HY+tyJtmGKjkreGKIlD7SsPMSkByzawPFj9OGD2Qi6ol9dEyPZiNWmTMJOeeH1XmelVAAfRuU3K7LCRtJrE9S3NgV44bDByTzRJuzK15noHqY/LKhZiesUb10JxktYmszvATbG1W8esZl/7d/cmwzxNhehPQesw8TQdcnlkkb2fwh3NitHYZC5k+CqWR4SQc0gop2cLb12F2r462P/Y/8adk2FiW9XUb6zX40I7z5Y0BxVp1k3KwGu3Q5YJTyWbSSmHkKb6p6o2x/HkzNCjmSWIGYhouoW+P7ZMVyJItI67DJi2rSkgIXbv7G6BnFThCWAQHCF2ea8ZebBJp4XGBNS6LWezIsGR6IzpmWAnKQJUQd08ehBslHePlgedqCdzDipg6M8I3DyIEAM4fve4d0WYjfCIHB5Sn5LMn842E4w/zhUuvUzLneQtHQP/ypOzVdu5aKgP3d2pPD27cciLZgddFUg3qvkpkjGU/Y5HOOzw47JYgaU0Xb7ZlJC4dlrMcmxCJ9ErCk6A9vfVeM7kUOGHMnScb7P8TdtrgCA9JTzntnyoipDSeto+Sn+FOHPuA8Q+NVm5auE28pEUevk+aV6KllRO2nuH+KMx2BQzld34E4fyju8mxDkM5t4hFUBEGU0KNtEIMIUhT84oKTi4A+UBqRmYk9NZBRV3jHPVTE05HeSdPfoSx1bs8xpujLQoRjIINF1oM9Z/RnrqqqCvj905Jmlbijzz7xIw2aQtlemRMWigtNLcg6KBKtKdCATFbB00qPZJ+5lmm7FBra4LQRVS0NmKR9zHoEdA03qJ3wn6+rHqy1s/HsDdbjnH5KfVBs3HcIB7Hz7f1U+VK7KqVgVE9rCsWjMp9BC3FQE2P6XZCkAfKeTTXzerB12CTBAs5qV6k2an1azNR39QOOZV8Wqn+LRjJc7WN+JgAyCgCxwEedLRuWuyW PB74l0MN o/k4ew/FEq2hZk/ndssic7Fi2+JNmc2NVE2qMI4c0w4CPTgfDtelSjnwSwWn9IccKEhDVhqZ6ohnoHK239+PcuQH16SbRohbbZ7CTWXoO6dwvE1ooBkmExAWs0/PZT2KwlMuTE4hi93EqHfNEaMzBWCHK65KZ7u2ncqcs/K4Y7MQhJ6984myVLLrRuJ95qzblqhYjL/Kx0zLd2+K2VcrJI0BBeELzKa6bnSMF+go9jSGx8SDDQL+DNJ4FkF2SldJcgShd15mesZWyFf1hIOuMrjFJNjW/e3OB316Fj+Nf9zSxHv28sqfEBI4NhbZFYnYq4PYCpFv3f5toR64eoKo0IU6/Fj4eZHW5KowkYKBSbTSd5HK6O+JkjCkK5+RZeCDQNI9VMGglEkKu6UQ3AVeHDCGm7O8QulS9tYv98NNxfeDzGkDGgfeDAWeC8Y679klGxSs3ec+G0fprWy+X3DX8/aeCs8XpNr9XsaQoiQKnB2cv+tZ1edGFwZriT897fh0A+lbUGhpt1Ru96lsUDOvWFEv/hyeo17nkwWyuK/frJY3PaURpg+DnD3jKnVbrCzaCGFZZ82/ZugGX+I5OG0hA4OHZbpSph3p0wrgxozoqgNAfU2c= 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 CC: Gao Xiang CC: Chao Yu CC: Yue Hu CC: Jeffle Xu CC: linux-erofs@lists.ozlabs.org Reviewed-by: Chao Yu Reviewed-by: Gao Xiang --- fs/erofs/utils.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/erofs/utils.c b/fs/erofs/utils.c index cc6fb9e98899..6e1a828e6ca3 100644 --- a/fs/erofs/utils.c +++ b/fs/erofs/utils.c @@ -270,19 +270,25 @@ 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; + erofs_shrinker_info->seeks = DEFAULT_SEEKS; + + 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 Thu Aug 24 03:42: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: 13363440 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 DB695C71145 for ; Thu, 24 Aug 2023 03:44:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81C83280076; Wed, 23 Aug 2023 23:44:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CD028E0011; Wed, 23 Aug 2023 23:44:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69505280076; Wed, 23 Aug 2023 23:44:53 -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 581038E0011 for ; Wed, 23 Aug 2023 23:44:53 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 302F9B19D8 for ; Thu, 24 Aug 2023 03:44:53 +0000 (UTC) X-FDA: 81157606866.01.D23C1E0 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf06.hostedemail.com (Postfix) with ESMTP id 5F50B180028 for ; Thu, 24 Aug 2023 03:44:51 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L5s18IvP; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848691; a=rsa-sha256; cv=none; b=VAVwJ3seNp2ml2Xu9lXR4MpW7TtfbbVHjb9OReQ+9xVrdMMN+ChRwwoY2tRuQ4jr3p2fw5 ldes4mW/BE5q6TptjpOoh+YzmF+717x245TTF5JVmII7J5/efkOZPsTVYvDcDqNnf8o68g yjzU+EolkzQHv461gLAvbCYSSL97Thw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L5s18IvP; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848691; 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=RH+UWxgsfED4SOG31SRsciPnOVwoHjCv5sMnfhtq6Bc=; b=pI+RFaBriKiQv9Ios2JZ+FO/bZ5Ji7k9u5TVEYjjv265ZFGZHxsyEFKWrU6cCR91t6ocP2 YIgcBdJMKZNAf4yHn1RjIVrxGM7+ArPnlNuyiUsnKn5o30mDxcG3gaqIZzqz034KG+XL7U elo7uOXSa5t53QempiO65NYvMspfojQ= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-68a4dab8172so654882b3a.0 for ; Wed, 23 Aug 2023 20:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848690; x=1693453490; 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=RH+UWxgsfED4SOG31SRsciPnOVwoHjCv5sMnfhtq6Bc=; b=L5s18IvPmkO1Yi1aX8xoUBVbVs+NYj2wes5Iop5itsw/50mmjZRe3mo5xjdm+YoYr+ LilfHyHML7A/wtK+y3tmj6oJnO9F477J4r8ASwXsJMy1GqlaxC/IRlgArGQhd91MGOHK 3A/nIh3uIHjjesEmVDhRjQQGnpOSt+ZUZIXZCdxBGM+Ld1QW0fUX6EUASA/OZvpRDifX PZxVf/aQ+feX6zs1fU4hK4chLezuy6pKGNDjYDnCsIRpGw/8fLGUh1PWhw7uWepXLMd7 7iamIzVc5Mglw5KEkqKNqjKvoDX13NmQ/PUea91yy3q87XQGMlCFJxJ4OLm3P8rzsoMA cazw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848690; x=1693453490; 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=RH+UWxgsfED4SOG31SRsciPnOVwoHjCv5sMnfhtq6Bc=; b=Rf11julAD0UTRI8KnD4pZe9qfFobnHyTDn1zOWtty8LA6mEL1KRtHPAxj1ohQOcUU6 n99ZIayP3nwiL/lRu+ICRMIJtBY6FfU8zS6steZBqxNL8pvKqlsmZ46tdWOs/HmxPm+S v8xGQu08vEs+IWkRrFBun6XJEzHuLNMC2F7Acfrnx32UkmAdTUUbfy9vdndCeWXK3kER /sTu5KdBmxVw0FDYhL+iE9+Y9Ljw3SwE1k2o4o7y5oxj+a4dUnO9IDkrnATwOOEC57J+ FsZfdxjK3uj7GMdoe7iJxPdfOvYaKPosf76y53ROirl/tZIDlQnF3CnEEUuFkAntIwlg olWw== X-Gm-Message-State: AOJu0Ywzm11pbTFCV758Qg4yj0szDpO1iWwBPwtIGiWHC8bVKPiVu6FV aVH+wVnJlMq2kyBjoD+K9d+xwQ== X-Google-Smtp-Source: AGHT+IGADDIb7FS/BEzlD2NDaSR5lL9y4k3FkTUBZvyAz9qvN4bXZycSD4+PZlpH8/QgOFEsYt18oQ== X-Received: by 2002:a05:6a00:1d85:b0:68a:6cec:e538 with SMTP id z5-20020a056a001d8500b0068a6cece538mr7248281pfw.3.1692848690333; Wed, 23 Aug 2023 20:44:50 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44:49 -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 , Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH v5 07/45] f2fs: dynamically allocate the f2fs-shrinker Date: Thu, 24 Aug 2023 11:42:26 +0800 Message-Id: <20230824034304.37411-8-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5F50B180028 X-Stat-Signature: c5czofj1q7enpmr1j8hbdcchccro176b X-Rspam-User: X-HE-Tag: 1692848691-162720 X-HE-Meta: U2FsdGVkX19BTGebOYiSQGToGY2fPplt34iFSBnzs/0PVMVMoJqAaRrD4WkJnUu77OcuaTPt9wqu3+QIcWaZAlTyagEgAK2QcEjYM9s/J17P2XwBnXR1AypPw38YPL/LGV60EDqsCsZHz/BJE7TGXxNLOpTpyA+LTtx+oX1D6Mcklfihcs8JvdK/+Qm6GmtjOhf1p5g7V5ra2ipGefKB1HPNzkt9PGyj9zB4Zc9AZy3FvBoU0xAqkfo5V7SZumH850NlgKDKTe89AeLAKNSCZtTsT3nU7Y2w68+UDXOnDC+MPWDCNLuQRCOq3+fySDMlUMZhtWgqM+JmtxdeZEhzIBtovb6WApFbvNwm2lkGw2Mw7aPZzbW2VMPmCRAU6UbxF/XEDakZ41Xqpy8W6w84aOTY5ZIRcykhHEkZzDAAcL4F2OmfUDnWSSvAqBTYHd1OhRp5EdHq4PwbEceMj6zfhBWitsZD7AAUJqpEmHSPB/t6a4kAq/BNexsd5l0VE4ZnVaPws3f/R2dcyqDmHBIblEHwpxlsTccSURuLQazOtYpM8yp5CzfvvbO1JDKn52BwBjZAxbC9T4dYH0RvIeMr+tKj9ABCX6mL8FgH2scROUg03kdwcWIsvH0XXwXfGeDccoZnjPmTEqaEWbqRuFItB99rIjbv1PLRyKdcuGa2a9lDxgmnZDSnhT4EC3t/I8HRIfN/7tYvJdi9MWQpD29z57/O+qZU+RxQgW0ihZu7qGYDm+i0GnC6Ei/h6KZX776qoEIA64F7wW3ur/3NRPE6HTUCPhaRdDweDhxSLoKLJq+ThUj4o6SuaMy7ANvgdwHRULYoQ5CMbkWbU7miYudJzbYZJDjWz4gfGa86VkMZKgUWwOBfHa/xX5f7pLsiaqvlOiy5rOTRwXeLEyrSHJ7XgkGyGmwS2uvDuTxUdxwTuO4Rea1hiFg8dajRQ9x9d148LG3aGFcZ1kc86nP+/iZ pQx25Crm mdMV5mxIOHALQCHFPsHUP4fGKK3Nh+XVHUblHQqw9M3dkszeo6+r9jAwSFKpQMLEtcfiBAYa6b1nBnXJM1kRMB/nH7ka/nBYbaxqJx/uuab4f7VDOSR6fTGTYpUjxPT6auQaxzuVvQr7IlyXogUmWw9eRu1hursgmUgRkBESWuVb8YQGEaq1nQsgHKmJ0KmUftGEri1eMQhUK27ZmyWF4UXM1nRqy6GLx4MoZWQpxyon28OxmeJ+3qYI5g8lXdRA53ZSVWVqrPrzWPkptzRoZvKoE0kfC1EqzI9RsX2Mq+x6Frb5RMwaG7+R5GX8uwNFboOo7gVEqxPw8tmhU5Ch1xKLyyDKmCA6eyrx9kjqkSK2o0h6gw4Xi5Xh4YhHTKH2raa38d6I+R/o8yce+vrfv9hDwiPIr/BhC56Jrc4hysdurEOQSd2GfRZQTjzBRk8F+98+AtYDrDzrwzFkDhQc02Bf5Y2nUO6keMD7/6W6MypPkLbswiMxBq0qoUQ== 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 CC: Jaegeuk Kim CC: Chao Yu CC: linux-f2fs-devel@lists.sourceforge.net Reviewed-by: Chao Yu --- fs/f2fs/super.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 050f4f8ee8f5..86047da85856 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -83,11 +83,27 @@ 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; + f2fs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(f2fs_shrinker_info); + + return 0; +} + +static void f2fs_exit_shrinker(void) +{ + shrinker_free(f2fs_shrinker_info); +} enum { Opt_gc_background, @@ -4944,7 +4960,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 +5005,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 +5037,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 Thu Aug 24 03:42: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: 13363441 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 3B4AFC71145 for ; Thu, 24 Aug 2023 03:45:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D259328007E; Wed, 23 Aug 2023 23:45:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD62F8E0011; Wed, 23 Aug 2023 23:45:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9EB228007E; Wed, 23 Aug 2023 23:45:01 -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 A8A838E0011 for ; Wed, 23 Aug 2023 23:45:01 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7B17812011A for ; Thu, 24 Aug 2023 03:45:01 +0000 (UTC) X-FDA: 81157607202.27.2D68BD3 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf19.hostedemail.com (Postfix) with ESMTP id B000C1A0006 for ; Thu, 24 Aug 2023 03:44:59 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dip4qEmJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848699; a=rsa-sha256; cv=none; b=rw+tUrCoDF/MrbARoO6mEtjCJDruOielIXfLgEL5KQmNSGsfgfbpmEN1Umnn5C4pTmGu71 qs8KMLOGcKMPmFAlCW6F75fJcRLXMXgdZ5mwdHBSLolo7Z6rMoixa1xZ0CIYo9ZmJ/d/im MtFA5K73lOoTc7u0L4mHxfkm6SgieeY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=dip4qEmJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848699; 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=B+a4BSDzIy5bpWMN+1YxNCRarQu4di8i3ZJob6D5Dd8=; b=e2mw1bV2VztJ+kdkFKo6vKrLKrgiZzcn5hDCCDcZou0jtZhaRXCU7F+Rx+Kxd/C2C2OMFj m44f7yfLlMZRYAoUs/uheXUU1OrjtO3GV+ODGq2ioFHnJBxzpOIb9yxHNOtNH/u0XG2OZ6 8/17tOJVLbi32Vo7FZRihWMmdk3bCGY= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so755816b3a.0 for ; Wed, 23 Aug 2023 20:44:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848698; x=1693453498; 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=B+a4BSDzIy5bpWMN+1YxNCRarQu4di8i3ZJob6D5Dd8=; b=dip4qEmJiV1YNzGzxlEI74Wryfunkc8c3rSYglaB3JIKEkT5lZ/foyX7YEMfkNEKng HkgCgh4ht64H1EmOCjuIJTFBRAsb5UPGfDPvHtEFoWm7IryKNuuIyQz573mu4imLgEgA aFipiNvgqdW+K2LFlZceFlek6WrMXBYl6UIjo1y2zHTRkONxxfYLHLcu7IEd1W2Qv/On OeO1Efs6M3t8mkmnGIM2HduzmF5Xd1srOyi16pQbX/gdcxkk4XFZqGf05Tj9UAofohDb p/FHyqijf69R6qxp9cnyWtD8AgdVX5kMyPGP2MC/1Hoaixy4uFYdTFI6vmbCaIqCJVfQ UAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848698; x=1693453498; 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=B+a4BSDzIy5bpWMN+1YxNCRarQu4di8i3ZJob6D5Dd8=; b=Efm+GKYCKTMZU8xRO5Z7PqCzoijnRdxkwoPt5yL2hy9MWwl0iBUDBgOtG64okVYcNh NBvl4ofG1JX07u6zSJdzafMEi8Aa6uJs8fu9Z+HZspfuSYKcL9SFQ6fkLyMv24uZDCEX 59bPOeXQ7gLbC1St42+zdu0zXJI0e/MuNpukuE1Kjhc8US+mWbVc3FqLsWyHOT/5+Yfa uji8wSnnLJWCSCGz/ceqIV0g7FxO+RdJlvR4o95LNMM1GPNxED9F9FGeVT6Dm3r9YL0X +tBYyyUmcLi3ea9sDVxVuih7hHo1KAnwuN7/LRTw4UR18OuFmI0Zi746vDdscPAs29Mw X67w== X-Gm-Message-State: AOJu0YxdHU414aW/41NPfFl2PKX5R8UHS+MtJ1hTM2peVdV37yIC+Y83 jzLRCX1ZuZVgAWl1cwxcmyYm4A== X-Google-Smtp-Source: AGHT+IEW17bvrtndnX5u4ZO2vRUQ/qIdWra1p6sHngI8edmpBrVuX9kD1hLdFF/eUVbriCdR0TGMjA== X-Received: by 2002:a05:6a20:3941:b0:137:4fd0:e2e6 with SMTP id r1-20020a056a20394100b001374fd0e2e6mr17388012pzg.6.1692848698719; Wed, 23 Aug 2023 20:44:58 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:44: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 , Bob Peterson , Andreas Gruenbacher , cluster-devel@redhat.com Subject: [PATCH v5 08/45] gfs2: dynamically allocate the gfs2-glock shrinker Date: Thu, 24 Aug 2023 11:42:27 +0800 Message-Id: <20230824034304.37411-9-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B000C1A0006 X-Stat-Signature: qp8tosfo4mjhkczyj1zbas88tp76pbk7 X-HE-Tag: 1692848699-472778 X-HE-Meta: U2FsdGVkX1/cuU78lpQTpt3jGkkD8EPp+T/04ukom/xOr2Zh/8P7mNw6JCnXwuQp6r/BPonYYa4oqVSQk8etfCJxcuifwN/D8UFPTwLfGgkaOPkESg3ZRxsaoTuJ8clb6P2blklvLHR3+eaXyCP44g7jMKfDekZ9zRsF2r3HVgApKgqko6Fi0f+bEp+QM34Zu8JjzQYtZ4vrSbDqoOyeUTfxs9KAmB5fOK6oFmh9kpWvVwuKBa6HNfXuqlspXktRFNJYXUCo8cxR1Gp/lfk2VgHsr8CDuBEBCXLgJx6UzwKPLg3ypG0T4ma49k7UX6nF2N5AYNcViNQLWAC73VOJmvxD5pI2dIjr9/drEaontixMDXk+OBlGggoyeTF09FqL+4Q2ZBxuNGv5mvXQpbCfu86xLhKjX9b0sZ2MWElp05Bn2VlVX1edwc/IQDSgpQnkoEbjQH1AIyyGuRwCiQHOtt9MFY3VFxvqHqow8eblFm1dCxhHcNjPeZsbiHplPT3ocqwpgkYUf4YfWaA8A34iBKjIcSScKn/lOD4OAvcPdQMfkk+4AtT+0ht4pUw9YIn00+HElZ6w27LxHT3mpRUnFsC/z/R7o1I9UJF8+BWhZ/bf84ARlKxoJFr4OWELpWrjV60ozVE5FxICr/97E6Atb0LShb72mcMwwJB7RtreRPy//3yhi1OaLcB1YgQTdev29qn0nb0LxtzElDZj1EF5s0tzBbXPtUFDygK7/LDdIq+JcNanJXHhjV+e9dhOXmkmpE0Hogtr94Yr74b52XKMHAhnOR7YQ6pLAolyR8rV7dIE8PqZoulQK1g4+atB5ca2NxQUibTDwuL8yGbc8xYI3a+uAvKRA5hOmikmmwBWMVrQfRIUMa6wYonJm1x544FEiL5f3u31J5miRNcayZXsVC73JTnIcsaM99GNFrICOlcGW+h/Dt1yhtMAckO3rGIRlWEXyd37+eGaJP194n8 bElsi+kh zUZGHmPebhTCbaIKnJAytZs57MTOoBk317kX53LitA9gUQx16QMSyH3DtQcJ0QK5QuvUWjw0D51j/MAY/uPvDwoE9jJFSflFX9bKsrxhqKneLUrwmFMHwBic5YT+WcwvwMehaMkkbQCuKlpZ1nQrskAI5M2BQRNsA2RUma3/tZFUtUJF0634zvURfmCOAZ5URf6tTSil/waEMhgrUvSp4ILVYBko2G3Ed8wuRofhABSpGF4Jxpvc6hmMhdQM4RF+Df64erg1GRc22WQQgXfBqu0CaNv1ftTfBSI6hJZxtHQMz/u3M1eHKQumCEddAk7BZ9AEbunlrpYJoYvuea1WKFVIbpNXGm2J265dISv5/Vdq1mEJW3dJ3H3XlSw0Oew8tagKjFhYyC8iWuqRBVfHQR3/HiUPvUY+Jcg2qOMlBpJrmas4MsXfhRHIbVA== 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 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c index 675bfec77706..fd3eba1856a5 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,19 @@ 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; + glock_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(glock_shrinker); + for (i = 0; i < GLOCK_WAIT_TABLE_SIZE; i++) init_waitqueue_head(glock_wait_table + i); @@ -2478,7 +2480,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 Thu Aug 24 03:42: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: 13363442 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 00D06C3DA6F for ; Thu, 24 Aug 2023 03:45:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97C9628007F; Wed, 23 Aug 2023 23:45:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92D0C8E0011; Wed, 23 Aug 2023 23:45:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81C0B28007F; Wed, 23 Aug 2023 23:45: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 7473D8E0011 for ; Wed, 23 Aug 2023 23:45:11 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 56365B1A57 for ; Thu, 24 Aug 2023 03:45:11 +0000 (UTC) X-FDA: 81157607622.11.DA11DB5 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf12.hostedemail.com (Postfix) with ESMTP id 8C57F40003 for ; Thu, 24 Aug 2023 03:45:09 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IiEm4cdY; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.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=1692848709; a=rsa-sha256; cv=none; b=P4CrhdBRHYObha+ePGJdFP3N4UxamKpnQkkj2WoX0yB+0rtDt+DZA0Rz8njdFtzuN4Cwgd iTV8coFzkhqEfQRKEH6m156l006hY0yfI7Ysna7wojwPP6YKXDxdPrMcw6ZwvYeSnmUbxg PnANaKf7R06fv4CzWK9Gjq/pbFRqjWo= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IiEm4cdY; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf12.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=1692848709; 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=AX/b0fq/KloogCdhJk2fCq89e0mYWJitbZSZYRv9394=; b=XR5U//aC39t0m5AYV/CbOZoi5813hcMnToy/sGCh2iLAT3BeGgtMCgfYicniecno4CsrZQ hDz/pvp0KhWSkHAovA6hJWfCzVKNvR7us3iPsxpkehlnSmxbefH148/3cz0jg8u7YIxA0X l+PyvHfyQsrXHGUfLXLacD1RafF66vA= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062220b3a.1 for ; Wed, 23 Aug 2023 20:45:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848708; x=1693453508; 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=AX/b0fq/KloogCdhJk2fCq89e0mYWJitbZSZYRv9394=; b=IiEm4cdYuBivqLOCo7pCSLosVlnAGQWoBGclNzHv7BpQ3OzgSJ6UP4ciJP7iR8S74O XmYza0RDh78lZAcwAaqw2to1tsj0TaujHZHQwmxkxk/F3bIzysr4eF5XZvIJl9wqFyyf O6ysyVR9xv1/6F1REkzOzqeOlgu+28GZxr7XpPwdj5lxv9K6Yjv5vyAD6My5Zz/yS1l2 1ON40NeUd05shQKFTyeSlPIlli77/svXJDTpzHCfBpTOxANAmdMspbGRHm6IDisLwvvI YS0OaQDIkS/HVg8tNe5hal/7Lbr++jwwGavZV15cYsWQbTbOnv1CzLzV/bnEh7jVvMln 1gow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848708; x=1693453508; 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=AX/b0fq/KloogCdhJk2fCq89e0mYWJitbZSZYRv9394=; b=gDgm1Es4brmfiEKF7gdOGCqyMMPyDQxxwJEeyFBDqm4yyIfLgKwkCZ1jU56cjk91xa X5u3xlEeuT03daKsWzEPetYNydDCXszoVLnnrHRnmiZEE0vza4eI/QRmNBlEd/5UuBQx STUU6Xjxc2lWJs5yTeBVkhnUbmg7o+XLjMYzmDvCOdDWtgYEAwjTfuz8E2Wx4hH7PXyb 9Uh7BXuXDriVPVFcNiy6aFG3Gjh8J7ghCKxFCySybx1V+7q90Pk05ivtCo+Hu2Ew98P0 Fzhvz0/n0EVQDXuTKa7XYDYr/OGidMB5SiWOlBdVR4+MOhDG+aMeIpCMpr8ERCCsUqaJ 4FKQ== X-Gm-Message-State: AOJu0YzcQp7k1P32TD+UVG2qYlGJOp1j5TFfGP/LDnIGSqpJ9p8meGri GN7P6IVU9p2RGmU7hkAYo03UyQ== X-Google-Smtp-Source: AGHT+IH9o7SMs2SAPemrTlzGr+mXhW0/++sBcfKyWnxJ+hyFE+5KtkGkdBjg/9E4utbduecqtJoPbQ== X-Received: by 2002:a05:6a21:6da5:b0:137:3eba:b81f with SMTP id wl37-20020a056a216da500b001373ebab81fmr18793963pzb.3.1692848708610; Wed, 23 Aug 2023 20:45:08 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45: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 , Bob Peterson , Andreas Gruenbacher , cluster-devel@redhat.com Subject: [PATCH v5 09/45] gfs2: dynamically allocate the gfs2-qd shrinker Date: Thu, 24 Aug 2023 11:42:28 +0800 Message-Id: <20230824034304.37411-10-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8C57F40003 X-Stat-Signature: 9etpd9gwmp69hnoipwfqjjfcdhjs7dss X-HE-Tag: 1692848709-521172 X-HE-Meta: U2FsdGVkX1/yhLMZvh3q6gPPMjqE49bOtWUo6mc/JzN//ThCLf1FAGoAkpWa+6qmdm+/L4Rk34B/kvggQiZMZrcBl6SCFzw4Xf2m1RI8efud2WlPOKOL8i4tQpBQGhim/Z9iSW9QZqUzTVeGO4wMQFraaiPUMM4hId7oyF2MQVHfBomgpbLIzkoijIqhLoQk4GZ5HV4QzrdVtLH6wmMy5pKYFIAtsIgSBlzfcKO6WhsZvfMs5c+NKmCucsAEzAy7QGuStsRVu1BBD3YUa2jOwRPV2vYxadsJbFdLWKA9tjaCAeFm/l6SOBoqPHda1CmGnjeqoJWmFAV+eCVwdlviwGVtYK2H2QTKevE7uCpq9tU+RquyvEEwB7I4YhKQ3YWHiaZTOev9q3/ZeEh2Vj4dyZjH/DAFeI2Bc5ybushzl1apu3FCy/IF3uqXKoS5MFpjY00v+Dwx7ZLxdMP/P15qCH4e4p3yM5acRhzJmmdkW84h961A+MjXSpBKCmIauQDr3xbKxRCFhPziw6vF/d+U/PGe6ZWWf7hqiR2ck3eKXhhX3JHvtnzfgyYjJbDoUlv1kP5TSwf767ZKQnsHBKUY8sJjpK+tmwrzB2FRv6bMBcNaVXQcMT8LJmI1kNrPM4b0bAn+y8czQe9dwq26GjndndxbovcVDEY2nUOzL+jC5kgBEF3K9qy3RtQE1/g1KdHFIP85YGkhu2UKJDEXD/bqiE4eFLFs5+Ma3PfW+oDBxUXCMKMDcPUNEgwpXmZClGakt/btdrwmBP3MQMqNFOKhR+NbPkOdhy8sR03sqnfxu47zaQzAbjBsR5mJatyyscI0LDKsh5eFIKzXU/TfSBSEM8STTl7ukIc/APi6XyHB+bIPujprMdrQr1L8SywFzI+6elmJFDaIxNEaLtZrbHGUEBrWnck0kNm8qzLrTPj/NpuawX9ezF/RUvzl/wDjyAu/nTkG91OwBWYuxljLyih FMeh9y5g IXInQFqLpjjCZM1B5M8IuykP7bqM6v9yJ3FapTiNspisFKTCqguxZGXasZbGDTAGKFb63hHY6AePxcJyF8hHUiDZNJexSggVfJfApyvNCg15pTe+qmRrXWBnBCAAonBL3dwaPBjxSZmhJUeDqAWrs1wuqws/UVwUv1CvOV4uSMssoUPdZwAongO5RAA/hMhp5SmwBWtquZS5Jcjhr6wflvQeF0dYAwuq2my7h9xb9I9rFdE00WjpGrwxeMZelSjHFZe3+0KO+NXq/9PaawYMMiPg4LafCGsVGrckipCNw1WPlZM8RlO2UUips4izABESAslsUkfLUiYOor6dZHBALojFL0uvVYXGd2rfL4jOUc9LXcwyh+W3SidndBs0/XY3Fp5zijAugCNT5zZXBgum1YEf8GXRUL7i3OlqL3Uw+thrgAC/wtIOwhAnSg6UuWcaUrqvblxbSfTvpI6rg7ZNG7k8tTV23/qe56ZdyrqJmlIR6ZOM= 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 | 26 ++++++++++++++++++++------ fs/gfs2/quota.h | 3 ++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index afcb32854f14..e47b1cc79f59 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(gfs_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 632806c5ed67..d1e4d8ab8fa1 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -186,13 +186,27 @@ 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; + gfs2_qd_shrinker->seeks = DEFAULT_SEEKS; + + 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 Thu Aug 24 03:42: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: 13363443 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 23E0CC71145 for ; Thu, 24 Aug 2023 03:45:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BED60280080; Wed, 23 Aug 2023 23:45:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B9E1D8E0011; Wed, 23 Aug 2023 23:45:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3EA6280080; Wed, 23 Aug 2023 23:45:19 -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 9658B8E0011 for ; Wed, 23 Aug 2023 23:45:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6B2A68018D for ; Thu, 24 Aug 2023 03:45:19 +0000 (UTC) X-FDA: 81157607958.12.B236048 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) by imf11.hostedemail.com (Postfix) with ESMTP id AA0AC4000E for ; Thu, 24 Aug 2023 03:45:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="O1jFqs/8"; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848717; 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=tlOt64o1Hg+FvIWEhYsu87y3uoyIDwq8jmzb9+sNzkiQvSHmHsQWJOweWsVJk8hVKH0j4T 4ZZYzDV2YxyitCxm5AxVykOtxFIK40cj1W2Xscd7cFMba64jh8gzalv98tz5sXDIJX/QCq NEIzHiGwk3oMjYLA5E5epSGD1NVAmbI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848717; a=rsa-sha256; cv=none; b=niFMM8ZSDvsM2gOyLcqC96V0wm4RPIySiWza1QFzVNSHq/pCB3q7IJlreOjNAFEDZGRTFR HKW8NhXPwg5ovz7sLkJrghJ/P8nOPtBbe6qoik4MKEQdDEFA+zZztp/LBHmcwDTkpyjqep KmQLj/07F3ZtoOUle/hwUqZVTsW1h28= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="O1jFqs/8"; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-3a751bd3372so714114b6e.0 for ; Wed, 23 Aug 2023 20:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848717; x=1693453517; 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=O1jFqs/8oc1Zkuuh+RreIT00SzE0RITyrrR0tfPQWf0F03mOW3C+kR183ZUZbV19fg 1njT0pQF3MiRhEhbmKFe4hB4nORH/DqQUPz83nIj/BcfeWcOQTDvl3XWmeJPiDdxxNCj aSM8Wiu56btqgYfw8FalFa6mxnERxpSyhXdr0cY8BCFqcfkHplZglvPzfqSpSX5vNiS1 5kgWXHBkRzg/0siYnFHX8pUt3JbjLp78Al19cln4RC11Rnj2a0ej4lpfuA1lfNaC1BkD tGwbgv8uKluiKTT9ikc6KjEs76P7r8QiIzHs9sjQ/D2bIVhILICDiu7qdUt3X+KwvMRN y3RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848717; x=1693453517; 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=I6P+LoH8vBnj3VUogHf9tWUzXZm9eZE0rNewobko8etF/qGnS3+OTOi+bkGoDHiX3V n09k1ZU91Am2JSWvDzyWKmF5rHPFMJHPNYMjh7X/9TH6+o3MLZqnqphLX+2FeeL/Gevy oPCs7TKm8ptyWwFtEDjSI2qeCgPWNCaRtuSpHIR47XelwbfZUfSMuI0hPC82AviEDzva sTQ9/JqJnf6k6+dlEvFGUDoGeeR7g2u2sUGjr9+gicV9PSsCNYqjA5XNdpM8dBl2xqhb VidfMDTgPigSzqO92xlvnbLOGPRdL18V9LmASMjCWKoy9vE+RQMBQpwCkMV0h9E+4XY3 WnUw== X-Gm-Message-State: AOJu0YykorHS3SQRs5HZXii4nBEFQ56AcJzoVbp5uQiEVXn2cPIjXxzI 6vfooDE0W/p2mt/10MwuHktbLw== X-Google-Smtp-Source: AGHT+IECsy2xziAStlM4iQiBzrpyBsCTGG8fF9NVbEM0k1w/3hIKlU5v5nC6tO+zngn9Mp6S5RbEgA== X-Received: by 2002:a05:6808:2e93:b0:3a7:7366:7523 with SMTP id gt19-20020a0568082e9300b003a773667523mr16881965oib.3.1692848716943; Wed, 23 Aug 2023 20:45:16 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45:16 -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 v5 10/45] NFSv4.2: dynamically allocate the nfs-xattr shrinkers Date: Thu, 24 Aug 2023 11:42:29 +0800 Message-Id: <20230824034304.37411-11-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AA0AC4000E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: j954roozunw3sxmf5izsd41hn3e8hodh X-HE-Tag: 1692848717-806084 X-HE-Meta: U2FsdGVkX18voYcCY+j/DtZTTIFWfDcbI30fnyTDUelKp5zywpUPt7oniIyq6lpsFCV1HwQ+GpwchHwkkmcI6ZjZiN7VSEJK/mnMHHaBYLStW1CxbHLZgTnZfztebtDqMmsW93RiNQ/YzIgqJ21YoxkvQ+aOi+KghrBJG8k1PmYP06LQiL+nIjFAz08PP6WdmmNTA/sOd0G5EMj4m9hyJt3YBW83PIuP21Sn/TnvufXLqnzW1x8A9BcytjGV+5kFsJZNc4UpmBbFV6gUQWZesPJ7t/GVa7JgGRsmirQAjKQfi28MVjy6zs18NtPbtwsuBpFF1q/itldueEJC2LmBATW7b1uQEkzrT/yi6at6P4fcg5ekGKBNIIfWIJ5eC0922L5+0OSAM/sjSylL8HP5If0PzF2itX4qldkLF9wMKR5YR0d4+bWIzz1/zLZvQVoiG7C3lbuoOxuB3+A8mKwAYRPHx9R1mpxQUOsnRarOTmFT5CuECUP8CpT6oih4yLEQ0z2tFGln6MRtKxfdjt+RVLN6YamwhQGk0dc2783y/wZfHEmaZupbxzMLa+VD89791ajE9KWM2nKEXry8zicJkN3qWxz5wKSabnX8Ev9HD7F/OotQvsAE7FBoXZCB/McBNvGztnKJjBN/A+Z+hM5Gaetz7DW7H4jbWWgET4pcTgnDGN89wEq2fIzVR0vtUKPzT1vgqmKkVd1SB0WGwrs6pBRuhQGo44R4e+1vfg+QngffkYZku09J4ZL+dNNYoaYiB77TmRavwZXQaTXuHD1vTEvFf19lbyEZ4D3630DKvL/80YgpA5NUDEV8QDCp5AILu3EtojBNTDTZ+Ed+0o9IYqLJJf5yrM0nA0kuZmMjTbDD024kj2uf8fWbd+GQbiFi/FxRRxBrpIT7ZeDPkNLU5UH9IVWufuelFccOcYFvh5fuc/Den6jYW8zAUvmPGRmYYsJspCCA14sUHx85TO6 ZXUdDhnx ZbsJOww3JPSBL0NXfVLXPOGCbLkJkOfo3w30IuZgcDadgN+UkUJWiHoYcvF5uUtMFa2Da5k42unZx/tq6IYX5SPfiEGhZroPp8JWsMPOdugca2VYFT5w+dxlgLlbX3oSOmSDSEEUkYHNY0Lr6EtNacRevWRCLiODRoi5cVgMYOmAEHO72vsK5U03k6S8MFEAGNcMDFPac9vxifE0U+CXy18D/IW3N4N1Qz/i5ObtwA25gpV7YhdMb76VNUB8ycBj57A3fT3e5AybieKmTL8OCVQv5WDA6s00dXZnAIU6+ux3khgZPwcQfTYIuO83BTi3rnm7CvVt0CvMOTeULv3sSyECGLxTfCF/TQyO3KsWsX19UmlByrLPDy/hyEXh6/FRlf7xfXKjrfiMMBnT5/+JVZSBnXwTBPuz2Cy1FaPr/EuWPTlagGiDwLU/huktcEAkbpyKkl/OcGFA9pQ+9Oe8mdsCWzLvo7tCIn+9H4KOjTvovWOFTsMK4fyXg7K7mqWUnBV5wEBKIU0NZnSwL+L1kaSO9wTglbMoaNUxU 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 Thu Aug 24 03:42: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: 13363444 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 74406C88CB2 for ; Thu, 24 Aug 2023 03:45:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 054C6280083; Wed, 23 Aug 2023 23:45:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 004FB8E0011; Wed, 23 Aug 2023 23:45:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3689280083; Wed, 23 Aug 2023 23:45:27 -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 D7E428E0011 for ; Wed, 23 Aug 2023 23:45:27 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B8D2BB1918 for ; Thu, 24 Aug 2023 03:45:27 +0000 (UTC) X-FDA: 81157608294.10.76A2B49 Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by imf08.hostedemail.com (Postfix) with ESMTP id 08BF7160019 for ; Thu, 24 Aug 2023 03:45:25 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jj5EOkZd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.46 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=1692848726; 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=zhxSeDRYp3v7ieIpIfFPT9sZqK0EZ/0i4DDRxkd6a3g=; b=pZibhoq/jwLzY/eoLYpok00FThqcgl/CI0l2IDNZTZzc7UiGhQcxlwamNVzEST0smXlAhC tHuSJ1wuwNX38op/LPfnJv+3gvGaKcr277fQShHnFQrSBaUJZXoKINqhd7XiYN1ifS62oD 7umFu5IYOKCmzeiHFODj3gtyMMi9Jl8= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=jj5EOkZd; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.46 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848726; a=rsa-sha256; cv=none; b=wZIhp1wBv1x1U4Ie5CdReW3vaq3q8KjNYxde/yEZ/vvspx2hHvVV5z8gieic1Ep9eCp6S1 9qxVHisPqP1I4njF9Uj382OnXxh+PQx9iLRW5QdZ5hmMB8pjPaNOE6yCGj+i8dPr4plGcR pjGyYUkQ3hfo/Rxo4UAWxepm6nkNARY= Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5711d5dac14so204414eaf.0 for ; Wed, 23 Aug 2023 20:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848725; x=1693453525; 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=zhxSeDRYp3v7ieIpIfFPT9sZqK0EZ/0i4DDRxkd6a3g=; b=jj5EOkZd/1Viu3LIpqnqm+9TO83RfQntyjhfpth1xwPMMqC6IeHfbX02lMDFBj9m4i HwTZWXHIfgHNzPBXU+/GXlcEpfMhfZy5bJLefmYCesJViC/+68iG6xd5KwRidLyWJo2c eEBhhIGT0YiGdHQSzZe+BuRB0tQmPb1ArPNTjRXRpv6rdjsXFFFVPCyMT9LQb0O6vhjO X14FAywAN7vHefaxoyfwydq29V8F/tb3M5k7yl3IMC1b/p7T/xlSVAzbSclwGGOZcBEi 2UDep6iaZVsbDk0TcVqBKtj26LS1xCeJgHZxHJ9kz4PrRpNyq14TADCeaJlpJuB1QGAS NXUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848725; x=1693453525; 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=zhxSeDRYp3v7ieIpIfFPT9sZqK0EZ/0i4DDRxkd6a3g=; b=ZPFMAs5a+uqxzAFs9b7RTOgy2SR0J8U2n+2hLMOxOT8DWzOnm3ugcWi6hZG3nIjEG4 l+u8jv8CFvqbdbjHpgocJPvCiAqCkNY+/CiIsghu/qbylZruEl9oud5vGq1yj9XswQf4 vovTKl+7UiEt4iBWiO2Bvy5t8IwAm3SNHkCoYch1TShyeAR9gKm949zBE6HH27bzoBYX B5cUSNcqiVrn754cuft35fPIT3xlhsujQf5fOVLaPk7/HfTr9pfOzyKnrLQOQIxISuKn gPV7b5nIS69Fyl2NX1iI9hTa1oHczpj7+9AifSyFhKtPFBXX7a3hGkx4zX43BrlYCIVf WR5A== X-Gm-Message-State: AOJu0Yxeaqy10jJU1kxbD1Xn6k1liUgnuUpFRquUrspwROInFHUPZOrb ZhsKnC0uBKjhwqU834DQqnLQAA== X-Google-Smtp-Source: AGHT+IFTBK/u0iko9Ps2VqzIjicgN2FMlf6qk5M/LKmT2/X3Ry0MSCtC++/3ldoynFepLPPQv6yobQ== X-Received: by 2002:a05:6808:152a:b0:3a7:72e2:3262 with SMTP id u42-20020a056808152a00b003a772e23262mr17146531oiw.5.1692848725311; Wed, 23 Aug 2023 20:45:25 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45:24 -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 v5 11/45] nfs: dynamically allocate the nfs-acl shrinker Date: Thu, 24 Aug 2023 11:42:30 +0800 Message-Id: <20230824034304.37411-12-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 08BF7160019 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jhn7c59jqrchnzz8xohcc4oors9mihs8 X-HE-Tag: 1692848725-649449 X-HE-Meta: U2FsdGVkX19g1QV/NmfihPYlQBFrVcGCIFrCj4ZKxZrVj7ap7fB6vKxveoExCFIyZJWvwWUQze+XrAGSAVIIG5wucgYK7YzquHzkdeCS8Sz7T/T4XDv340IzUhngvzaVa6JdM2I09p/cD6C2dyNgubgpLFp5GbF50pFiQ7xeDCIizx7Ao2G15md4ng5LFwnUzWskc9OkzHs+SRN7uS/n/MOI3POqPYdJnjmRsl3Osmuq4AHmPBtWtu2vy4g+a0vjR1iUAZRrmbtUVSzGKK0YTt6IxkibZCPoN7PHg+Ob/dvm6Hj3ie6/4Rj+ue6OLJTE4/QiCgb9FxQ7lZ0KDRHQS5XtN8Y3DhtmSxjjI1+/I4pX8vwjn9aq/V8SNZ3aSCWSlHz/qkxYGc7ecGNhhieaN2P2YihMMCsllJ9OuIv1NEnkiNJmET4T2DdwHCcaFkeUva2FgpEcZbNIlNBsVuylx/6HH0N0queVvW/QZsL2D9FNvafwjZ7uJFRL8XZxG+Z0v3yaLKrCtCGPasdQ9BB9XHqTOIVHrpyujl1EZEP2+Kqw8XklixUerqBnMh08Vok7KVs4ltizjbfDp5CZy4UhqDaxXyrs3yYI2wSdXSYT46Djh9EuQHfMq3SiVyz/zl+aE4Me97LgvTDcc5GRGwD7aMGDA5grpc6K/0Q7/Mr0QF4Lqy84Gv6KINYWIOZNsjYTnh5dgFqjnAJ8BTXugH0mmeltpwEIr0tR/N8VuFRmbMk5awDK7Dt42CJEYM8onsM52a+rcpc7KjkSPhy5xBlZlA+Yxe5nbC0wzq3ktq8vcvghj+5NrFJF8kYjLFtvRehq9x6HWJcCqZvj9DHSRhqCZKV9ESPFQgc0Jzd5YmBYG6qNlDoJc66we6f2Y/pqXm5D4OmvqsN3K8I17qLrDQIxdXkUCM3AWdZSRZX4DPctRzac2tuEQ0CfmQcCw8sqUd2EI4Oj9+hL9FINXuOzUuS hU6Z79lP 7kcxyN0TOIjz1si4TUkcHB6Asfd3aEsYuauW9J5CtpiHrUJJ714RtAed7TzV/Hwe9tFEet6HkrjINcLDydy00tqs4qR7R5S569pRqkmhsNn3GsQuiLH8/5AYHAKs8amc/FDS0q967IBPO+8xPzKV4inbuDVc00QwntLOj4KSmIMQXT0ujo2TgkLuPsvu37Ms640VrEqbflBH9wY0C8shji5cqwgK5DrGbmMd3JF3zGdPEtP8bVJzBjtutWb45Jre/rDoVoY4Gtv5zB7/qBGc2Tu0dQ/CSXfaoCBgD/FEdTN+kEQ9FO1n17Hb/zlYx2JOEFwuXnQFUkgZO01OdqcF1kJ5ZiSUbZYj1hBKt9ThJ6hDMscmcvUc4t58gkUnINKx9RhZhHI4iWA47LgvM6MqovQZ5RjRD7kHH7jywuSU8iLFWrGqmMM3jBXcyfinxYWTB0UmZNZMxXs9WpdTIP1h5lToIIUPso3AtjbCk094SN6gnGDnoAyQ+7ylqNLgxDyjQkTxilT8oGlDmKVRNhKOTCFsjEw== 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 | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/fs/nfs/super.c b/fs/nfs/super.c index 2284f749d892..1b5cd0444dda 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,19 @@ 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; + acl_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(acl_shrinker); + #ifdef CONFIG_NFS_V4_2 nfs_ssc_register_ops(); #endif @@ -175,7 +181,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 Thu Aug 24 03:42: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: 13363445 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 C3885C71145 for ; Thu, 24 Aug 2023 03:45:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62284280084; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F88C8E0011; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C091280084; Wed, 23 Aug 2023 23:45:39 -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 3A42D8E0011 for ; Wed, 23 Aug 2023 23:45:39 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0D98C1401B0 for ; Thu, 24 Aug 2023 03:45:39 +0000 (UTC) X-FDA: 81157608798.24.42BFE8F Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf07.hostedemail.com (Postfix) with ESMTP id 45FD84000D for ; Thu, 24 Aug 2023 03:45:36 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lVZZLnG2; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848736; 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=Qd0iHVO25uGmovEBLEr8BFLIGm+5Rg8i4U5LS+PLE/gb1sNQlRAZPFX5W79+8HScNClpP1 2hz+lrP/yl61uV9CD352ZBlznY9i38a0BtCY5I5mCLaRQBxaZqid+E5po8pJgfQlGsbjZU MpWQ1gRBZx4/3dHZBagJ5iiYWNpPyRo= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lVZZLnG2; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf07.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848736; a=rsa-sha256; cv=none; b=GyFhUx/L4xmBXYSeoFcWlwS8++d+DubvLHNaWb2QP7DTMZ5mWMmxNjyJemy6haepMs+cbL wCLjaZmUsjrOBapDNqaEJ9EKnV+EfnsHUDs7oeWn0biTiEizLiBcUY2Q5jmNUDWRl1HhcM joileA4pD1M89Wei4Hy5TLersvbQ+wo= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-68bbd45d0d5so331100b3a.1 for ; Wed, 23 Aug 2023 20:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848735; x=1693453535; 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=lVZZLnG2RsmN3a+zFL72bWnUGygaFgRp6akXzveK4gtMYRg/HADgJCRGx9wFYaUoSg pEwNRignomWbz0X2VtgkM5yh9ie22cmsn86JDSYo62UxX8AhnRWbtnxk7vsHU1TuklPr KYYlYgONHvsGMaxaPlnlctmdwx2t9FyKc/SGaBRFpkSfmwi4o4a4q0TloaM6lWreTy6+ dPqCqOkffPtxMYCMP0/9PFQmib97nVH3a2mDDsK9c1A1a3EU6i+rHDrFQYI3QbsVHTke t5Tgrl6fQSk6/O0l5wli/mgVVJqfFqz816vNoxt1a6BOYzzKWcqQBOWmo+92YHRVIkpP 4QiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848735; x=1693453535; 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=Ze7o4vB5UiXOEIutHFu/l4KNwrvEOVMkwkE7zd4DqNjp/fAppoE8Mx0ArtHJNwryJ/ N5NmbC+xZpa1v7J+YSd/y8veblHvvASA/FTEZM01XPQM2M6ZB8Gu1UH+uvGpavWuLeNM GB52T2fuceLPambTBnvY4SU4gbGlYbGOFmu1ZWMQ8X9K9mO0MX00ZE8A2k0eZYIXZ/ir VuIUqTKBtb1RNSLac5mcbQFu8YtAwYzOcS4eJMTSDsWUTnnzlSo6H7OSeOtV4fukvF4e 3hz3F1Ls5CswP57hBHDnlAjzjRi/IOen3RHQ7bpQwNO5eSdbWMPIJzK2oF1scOk18G5M eNEg== X-Gm-Message-State: AOJu0YzYsSlu3Tcv6Q/A4Bi2toY+6bQVpXhpHWEjwo0P/QZ23IN3I/i3 TsEeoFcOI1WubVV5/eUmIHE4mw== X-Google-Smtp-Source: AGHT+IFDQmZdqE5+8g4xA8xE/nPvKPpbbUoiPsHTkmpATNJSbjrISgWKtS3Mjf4jrwQTFGPcO7csaQ== X-Received: by 2002:a05:6a00:1f89:b0:68a:33fc:a091 with SMTP id bg9-20020a056a001f8900b0068a33fca091mr13891213pfb.3.1692848735214; Wed, 23 Aug 2023 20:45:35 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45: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 , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , linux-nfs@vger.kernel.org Subject: [PATCH v5 12/45] nfsd: dynamically allocate the nfsd-filecache shrinker Date: Thu, 24 Aug 2023 11:42:31 +0800 Message-Id: <20230824034304.37411-13-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 45FD84000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: gpqiy7pccc6ehtc41gm9co4eir5iz47j X-HE-Tag: 1692848736-198019 X-HE-Meta: U2FsdGVkX18iqSDA7AEvHsbBxGbAX1H6rbIU9ijEwd/j7OhDE/o1alt8zYUHKEGzMErVwiMKOf1x1Z3fdq2iW3XnIVs8IhI2gR0j3Cb3XWjNbjgjz55THOrUm4xoe7pzUn5VBJ2i31SpjNHpZ5ckNXLUrruqwtvb3enAwix3G6PaVQWoBOUQgVOaD19JSnKCQHT+3qe/z9w1WqMUgNlaXnMyJ4ax8oyEmF04h1lVd8XO/0YxtdTcoMQqEs2IUJB+SOz73ycX0j44ISTiRidszedtspXnG4a3jwAy3yHV4cCDCs8uqqQ5juMpQvQiL6aI1gGFY8gQ0PZa0iRRlagueWJZLXMcNzWCKSyqfxXHnmshnevrhi7fzOivag59lsDeo5nQo7Kwytswxj7/iT/lCFGkCdOrMXDOyVRnvS2YMVsYClJ8t7WVbEJCESzUETIVgsAzrl3xrnTxAlPFWbmRUrph/A8uJuMoEwBxLNjyRVrEuwu9l/27PeBsdrqz9H4EB2qhh0wTjHuOHPAEe2/4N34GdcxpP7KSkyN8ecnt26cTkr6UE4ol1iyuOZf8eM1WJ5VC6Fi6sWKIT4oD6fwZyYXRGeKg4xDPrdHXzcveqrrtkK0Tw16a/BOl1PRoex/vYXaLPnnv4uTwBS+aZVBulDJZdQ1/DtsXiVw936OQdkZzguD3u7mpyPduPp99OKwoReRO4nCS+sg6sS3pNcjOdNXCL1uHt4ASs0HAGl3AGbxsgq327v3CTHoTyxpQAl/O7hQmfHHj3xjgXP7VD2yXCev2FJXiPv8QAJYRbDOj8W+MYxR+TQ8Cz4KOXTH7TlYj1HWCGO5gRZ9YsG8atSTXijFt9woxejQ91+owBzV8agU1W1drlDUZTUu56s9phwTLu8HlDTO8Pc+tM5ZuZpia/2YZthkl3UcPwbIL7x5Urer7y3GwyKssU5rkfO750uQMUTPUGi5fZlykYata2Iz i6LtnJ78 iGUYTUdVRL9Z57MWcbnZdMnM+1kvu4W8IDSXBEW3fagqIB1UfsoYtDbhvdT0zXFSPT45XHetZhSTykkdkRl0ydED9TWElEDikh9ynHTS59cRoytzbQP+WzsfQ5AX2CIpdoBr53qmdJr71kwBP2rcZIUBZfZOqyG2HzGKpJzXSo6JJEytxwje0vaDfCGB22wHbhfgepf5dM36vDftAK5WAvXW+2cIkJl80/WyVuxKK8p0mHvAQgGQ3CeJXwuhUmOo0SQNsDqUmFitZuTNBeqxwlrGLbqdIzUwBmtvSMNS0EqN2tuQoELEYjMVvTliGLuciH+imfAyCMbRc/seg/Z4ZBVF83RrFo7wS1deIIaW40FXIQnjI+0d3AQNhJX/JdiMZE+SJMbevz84NXGp/xa9o/SVG/mwfF6VPaBDkry0BqFcGl7qDIe168XZe+upxKfxKC8GYWJLCudlMgUwgF04DSHNK+bLqEwJgxhKaZi0EVbFxkKTXqsQSu+w4BI1Q7tcoJgpvmXm1rY1ym9hbNSsfYPcFC07inFP2YRoM/NUdPxD6XI07GQNFANxudYUS0HoiEQx9CIK6/mIhhnp/wT9cCgAYWHWV8G7/12xPe2CehlAUgYw= 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 Thu Aug 24 03:42: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: 13363446 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 CCC6CC71145 for ; Thu, 24 Aug 2023 03:45:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6964A280085; Wed, 23 Aug 2023 23:45:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6471F8E0011; Wed, 23 Aug 2023 23:45:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 50F19280085; Wed, 23 Aug 2023 23:45:46 -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 407A38E0011 for ; Wed, 23 Aug 2023 23:45:46 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 19191A01AB for ; Thu, 24 Aug 2023 03:45:46 +0000 (UTC) X-FDA: 81157609092.25.47C7973 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf10.hostedemail.com (Postfix) with ESMTP id 434C6C0006 for ; Thu, 24 Aug 2023 03:45:44 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LgRdO1Fr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848744; 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=jemklUFFCXuSkFimtib823G6Ct+c21vKLbvuJ2OztTU=; b=v2Ayt7B9Jd7X3KYSvzxBOKr/uVC9HDHmtx5DkcAXJS75LzbmW3pT7hMZJ7zxCkciKU+AO0 6lS5+nHjrtbIzcn1CWgSwL8Xv6Q6DIIta9hYS0AAO4SnvZZJKbhqFfzH4p83eBYOioUHqf QegvoD6q2qJ4iIGlYeb5xup4cLza0mA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LgRdO1Fr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848744; a=rsa-sha256; cv=none; b=CuLKR+85FGko8mElfK0lWEPaKXwDayKgi2yGMO3Mde/ADGlkap/1AR80r7l/72SXi69oLz FlCvJKGe8UEGaUo4SDtOn93MUcMEgCGzgxFxTpOfpvtVTPXjZ6Zfy8JbauCjvEl483n9Om Lll4QNVQDRTqp4hOjD2DF8vUidDJAr8= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-68824a0e747so1237998b3a.1 for ; Wed, 23 Aug 2023 20:45:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848743; x=1693453543; 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=jemklUFFCXuSkFimtib823G6Ct+c21vKLbvuJ2OztTU=; b=LgRdO1FrpQYjfdqKgY7kw9rvoqVC5S1JSj2Ky2tibLl0UkGXBa01sM6tJJtw+HUSpw vVOTPvHxNt/AqID6/gQaE/EJ2lmfNE/O2FmAZf55yMpKB3nOPksaDOXPjXEx/JrJ/a0H 7gzGX2I8Vak7oBpce2JEArh1Aby2I+koavv0vi78GW6RbE0dsrPp96+DvKW7HORmZPSO 5Q5/QNviG9nWkifZ6ozu08jFzQCHMGjACqD/YSaShhiFDDnoKbe9ZymHxmhZSz5LBYKL CQ08NNQGQGVLqg6/kIhSxdlHIrjFXLf/hUuCrGaitNQv+hunrwi58eG4NHlJ6VOTyQNH ZNLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848743; x=1693453543; 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=jemklUFFCXuSkFimtib823G6Ct+c21vKLbvuJ2OztTU=; b=IsHcuO6cpanUi9D0hG7Fqtt+qdZof6+bcSyN4zmIjxM8Ms2E1rd5BbYjxMUSLzLKlK SzLvxDWPS9GH4RIZbiBV6I5bHOknGYyqfHFffrMZVgHqdEq0m/KBGF8Av1HsfqXQn/Ot NHBLvzXedTAAj59vjIYfltS+tBQ3caMfNiBXyavwdfrAWWfud5Vibkc4vraImuId9vjo 8XR67mnwJRmctDUREEqgYuvdKErdc4A5VRsWNsE8SBHTuUfsBWoQqTjigW48Cu34u3Gx d7F1pT2kPDiZwUy3IwQr/onbIya3KSqqDqHpfr01J2pQAMWF+F+1rOdw9Zef4VWjZWwO jO4Q== X-Gm-Message-State: AOJu0YydXWjJsPG0/12jAI7fNRD8a6+erOI/K1uCSTw+uRynsVjtAUCI nEZoJGDi0EXM7LvqZynMH9hsSA== X-Google-Smtp-Source: AGHT+IH5OwQqnaWM1iDwEtDztgpiT/vGMc3PO1GrsFb4dQKDl+nnRio//nIXOrYlRi+zRRJZJd2wxA== X-Received: by 2002:a05:6a20:a10c:b0:13e:1d49:7249 with SMTP id q12-20020a056a20a10c00b0013e1d497249mr15190972pzk.2.1692848743163; Wed, 23 Aug 2023 20:45:43 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20: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 , Jan Kara Subject: [PATCH v5 13/45] quota: dynamically allocate the dquota-cache shrinker Date: Thu, 24 Aug 2023 11:42:32 +0800 Message-Id: <20230824034304.37411-14-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: wbrzspb1xkwo7ruhfgsm1qbi5fmtssid X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 434C6C0006 X-HE-Tag: 1692848744-180219 X-HE-Meta: U2FsdGVkX1/+UrR57xdMsufFA/q3yD6Pos+hQ8MJKp+YKuYGqhR+LHGXnfS8cBW0twOmWcfGM3lNziYGJWMHlivYPlkqNUlb57ambas8ODgcSHTNwzkK1qa/GRstvEAGKb8maDY7c0lMDvkQhJDnLVVX/3I2bXoC8vXIvrO8b3gWdbZbY8H+3AQprmknI9g03e4TBqaIayUlie/gFEVuRnjp6fhGZV7dHd6D6I0te5kX/54ohxBC8T5TS8RG450aEoMseCgdJoqnXkFI73c27wKSwlGXkAeFHncqSOeELuPLjqiEWeL8Yrda97y7wdRXh5B7uh/3rfZMQ9TAHla4rSzd1AVYpdUl/K489777aF8v+EcqoSer3P1CHw8PamJoeHhwVnOQh6Pu1O8Sm3JitpX+tmQfTmXQgeKxjfaKmgiCqIBN6NzjrbiRNfoXlRqTG0/83Mciu0ELGeRWvN8rPS9h4Pz2Y/Xb6FPF9T2do5wQDR/V4uTAuQfYV9BzY+M8UMwQhPgxzNOUgoF0tby1ahGQth1Who2ONbt3S8LRjTf4P4AiU+1boJIxDAWkDsxP+VPHHlwMVnh2vCs592izTfZWiTkILN6oE3CtI34hLBfA9yGdYdzhZlcWvZ4FedK1LYvsWKwwuHq4Aza9Y1gTiBFh/7gjYTLaezUlLNCZFYTRkXa47OlpshNYSmrI9s2M0vXCAv1+bU3budTWZMXpehZzB8xMAFsYRDiBg/hTbWlqLbyq4OJjDiieVVX+dH7OR7qgHB2XXSHUuhPPLa7j3gNnbIao1Vn6jBCM6wx9WZbx6yd0u/K7eeCn5dm1fMI1yyikbd2qr+NX5ox8YxYDd49eTKRoB1SusCrG0dKplbUsN2+Li/0PcZ+OT/Lw45e3AI1ndgSw3iggTHaDBtPC9N1iX7zi0DJSmfEZrFyLyIGYrnX3KT0ObFudsOEMVmKNfZsAYE/lQYJr4Tg590t V9otyyn4 bs6u7hwi4P+D/PxbESmTw9Fd4kC2SXFPjOHOPWNv83vw0yj7en5UtRDGxXeZ24gIKNB8gbYCNszH2tp4q8j3AxhglXI5ee7EevUwcK8O1XUpPZsWD9XKsntw9R2z4HY8rxiaT0ZVWWwAfTugZWAP+ZVpZnCggZ7zSYpD2u9feK43+X0wJa83J6NFYaY/zuhYDd1zk2f0zZcv4Q+f5AvoLQy9BOW8mG/roAyC4g04KNbtkSsfLvZxEpfORw6Cm5OCMPahh5iMEyZuzYErEYsO8CjO2ucC6/eQMp5e3Kd2/2aj6zUKfCa+6XKSlYacEQl2L2NqwZeqT/OspIAWvwvnUm+bXCJs10cMTr1G78dLiWKSuIcGJe/34d0l2HGUm6ml/qutja8QAcdd53JdNc+6pPZLAeT4uTIItrki8ZkPbyV76tJuZoUSo6Q/OaB64FSkBd1XMfMFAXZVo1uyJ+AhZyIS291fUjQ38k2gi 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 CC: Jan Kara Acked-by: Jan Kara --- fs/quota/dquot.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index 9e72bfe8bbad..c303cffdf433 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,15 @@ 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; + dqcache_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(dqcache_shrinker); return 0; } From patchwork Thu Aug 24 03:42: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: 13363447 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 9F73EC71145 for ; Thu, 24 Aug 2023 03:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B0F1280086; Wed, 23 Aug 2023 23:45:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 360A98E0011; Wed, 23 Aug 2023 23:45:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 228BF280086; Wed, 23 Aug 2023 23:45:54 -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 11AAC8E0011 for ; Wed, 23 Aug 2023 23:45:54 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DE7BF1201A1 for ; Thu, 24 Aug 2023 03:45:53 +0000 (UTC) X-FDA: 81157609386.18.836A723 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf16.hostedemail.com (Postfix) with ESMTP id 0BD0518000F for ; Thu, 24 Aug 2023 03:45:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=f2vdVUxr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848752; 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=txor78tbBDUbFlDeMsr+ZFPB/YYvYFMci1CkfHTVP5Y=; b=WMXDKQe6RGpJc3givkvgY1ayxQ/cHnPOO/jfXpmN+WcTToPLale13VG9oHybsIBme383eh MY6i9lVycyHAtLZDgysrPXWCLT/344TAq/VfoHoqvbHfnJsNfpCmZ7pjd4EENY0RX9nhFD r+1ijD0qq9hpAx9vXIAZRwdo4bhO1ek= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=f2vdVUxr; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848752; a=rsa-sha256; cv=none; b=Ll7mVihwSf7O7NMO32H7SUyhDpKfWum5or/0SB2dKuGyEP6qepoE5UTuF08mtIFbr+eKAg OJC3NVCeWLKHC5bSEkkS3T+f5jPstq0kZEJRAJaDdXHv4ggum30h69NPyyD2IPqUxh5oP9 QDhZVknzfyfNCvOI9t+J2EMCQuiUvPY= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062317b3a.1 for ; Wed, 23 Aug 2023 20:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848751; x=1693453551; 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=txor78tbBDUbFlDeMsr+ZFPB/YYvYFMci1CkfHTVP5Y=; b=f2vdVUxrd53niqhHN3lu7O/qQCjl9NcyQMCaxNn5T6viuJuL5MKYfAonmu/gm5BijH nC5Wpi4a7PWBB7q8tUPiP0oHBb2PXMLT03b/6gYrtmaZCnd6Mt+uzRWvKmEXemtjQCQG ZqOtchTpFwMV/kb2DFtC6mLoj+uRINLATigvC/sQxB1HuNKMTQhQNfDZaNKW7QuCPmlO ar3szccuZEbmvlHzXFE8IKU2droLxg3xvWMPq6hPvSFYUp81Eg8+xfvSTACAFhtcNIz4 psn56S58o40IpPO+R5N36OuNZcU3R6vH+0jY7JcoeFkHzXkKohk/Mg5hsgTkh16avUea DzSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848751; x=1693453551; 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=txor78tbBDUbFlDeMsr+ZFPB/YYvYFMci1CkfHTVP5Y=; b=DFt4BZF8Gr8RC0BwjoJazctvZchgz6QSTZbl+ww0cnjoikL59Q3kMrE34M5OjpO33r Hd+SB8I8Ut23pOjDbqBPdY/AXIB4dwK3kisDS/NW43T6PZU+EFoyTzTuFEGhinvNVOcd ox9Ojxn4MHp2R2C0S9mDOAi8Lifnb6R+J3yNWq9KfeA7CLDoJAuCZNW5jEK6KApNroo7 v9UjaJU6oNOe1V9ivZqly0w/lo70zOckw89AuvjlcTsJvXkbS/5Yh9GLidSjEiOz69vx v8gjuFag/dREk190qN7dr/e1MPXMb8Ivr2bqQ8E8To0D7H+tn/RMLgOWnq1TIgcsNwZ6 H5Jw== X-Gm-Message-State: AOJu0YzyP9PuyVXpnNQDnu9UWIqxynprq81QDTlXKYJ08URAUFD3cv1n gMU2WY28bJzR6kmqGA+HsEzYBw== X-Google-Smtp-Source: AGHT+IEvg2+/eMxtzAUOdXGTx3O6wsmWYf8GYszkDdU34p+/e066zZfZMwabjJVp+KFh4Fxn8XPDyg== X-Received: by 2002:a05:6a00:1d87:b0:67f:8ef5:2643 with SMTP id z7-20020a056a001d8700b0067f8ef52643mr15497296pfw.2.1692848751025; Wed, 23 Aug 2023 20:45:51 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45: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 , Richard Weinberger , linux-mtd@lists.infradead.org Subject: [PATCH v5 14/45] ubifs: dynamically allocate the ubifs-slab shrinker Date: Thu, 24 Aug 2023 11:42:33 +0800 Message-Id: <20230824034304.37411-15-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0BD0518000F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 1wiefzbrga6znjzfkbintatbj8pr867m X-HE-Tag: 1692848751-476031 X-HE-Meta: U2FsdGVkX19TK/DeImZ+P9URxYN1W7q80OBiu1XIXwUToPYYWx4z/Zzo5XNCXDZSjrGsoaXiNc/ew2+QGoN4FCdFsGWJ4kkGsE9jsfDK17spzlWVOA5WCyDXZmSTGd0YPPlFMWfIK4YAiRp5UzDEbaeGj+CU61UvkoRvObdUU9z3q3+SajbVqctOd/drL3pyW1ysyExp6EmKw0GeGSjG31Oah/Zusl9f8A4+CTXsvnmXpWi/CmJllV8iT5Co9oVzXrn0zo2CkD8CGQ514alE60a7xuTv7tiAM195QGW0ZhyXtcc/dRzGdp2qDffZdsTt7dbETc7J4M1fRcvpeNtLmyyWOKtzo3/EF6lS4GFv8d0i9k+i3de4a4kbIRDDIFscEq8q+Kq/IX0ciVrCMMQUC9or9bN9Jen83D3fUs0spI1au/50pqqYobThv9vBQ8rUq4KNDllRqRgveb/qugMD1zaEO4zekgMm9AJ4cd0526x7hqT9Nv1n0q0X3FY2psheqaU0cGHDiCOr3Pn/ORCq5oNYuYQbzkCU2EvwC9WgHcMeMb5S908GX3ROPWF/HIEVqv+0OjuFocCXWKOfLIAw0sreBFepgeodGwtK+VRKqEgRJsYOrER34tcZDO/YwFQdDBgrOcFEOMX5zwU4oP/M3XqsDEpPK3Sxe7GR2ct63/tPUfTtkOXoMlO76bwpknq4rcJwCEbPywnQcPsZC03zpmeyHV3GKynSHBz9EM8ztzIFBBEUgAyw0WQOqQkTBPDIeskp2QSJhQLuNxUywPDqvaE//xoMgYAj4IyuSzjk9h/oYngMMlenKkc4xbz+F0zCtr8ELzuvENks7MU2uipegi5aPWUab4QgZYnIVIc6F5xFKCZCgBozyv7AtMDxrtJEzdx40RR1s12rbeBjGAg3AfwhxZyqxXII3Az9xj4zm6hC6nBL7hZBjoNmXLcosuVguaxdY+l+cufPV02v1o9 ABNQvpfl uCvSYRLK4gybppWXYbYfqtA3YPNvWZIR5z7/UOVsBkRl+I5oAJVrbIoILJ2vyzURl2DbwhPV6/vXM0zgHZgauuEd2U7y5UqRNGSRsHJz8a8wBNVBOjjvfsr4pvcdTPQB5AFpxgI9PPL4VF9m4q+A1nnR2YGraFgAt5sMBwa7GpOGkQopj54SA9MKPBptIzzgyECEB/+3HTZVqpABUwzL2wjLYxgd2I7UUAOjXDKzjULwQRmJtNG2I5qrBExZ1BkR64+c+FsHQXIW1JvCbHa6IQJvZJQ9k7Bei2eVSdv+zjmd2dGmtwgFGcekovs3l7Pu4HzJ2dd8+a3NT+Q4jubR6iLxW1FoG1yp8BUncr6Bn+furQpeV6qiR78Wq0FCGKSHjx0g/bo/wWJa/Ad3fySujwA+jlTOO3Q9y465+db8Syo+AHFqJ+/6Rhg8DJOk/0DMRasgJM++HU27IXoifCH//ZBh8Uq3p42oI1xrA 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 | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c index b08fb28d16b5..c690782388a8 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,16 @@ 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; + ubifs_shrinker_info->seeks = DEFAULT_SEEKS; + + shrinker_register(ubifs_shrinker_info); + err = ubifs_compressors_init(); if (err) goto out_shrinker; @@ -2467,7 +2469,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 +2485,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 Thu Aug 24 03:42: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: 13363448 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 5C6DDC71145 for ; Thu, 24 Aug 2023 03:46:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFB9E28008C; Wed, 23 Aug 2023 23:46:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EABA28E0011; Wed, 23 Aug 2023 23:46:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D740828008C; Wed, 23 Aug 2023 23:46:01 -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 C8ABB8E0011 for ; Wed, 23 Aug 2023 23:46:01 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A0B3D40195 for ; Thu, 24 Aug 2023 03:46:01 +0000 (UTC) X-FDA: 81157609722.16.2C2A4B3 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf21.hostedemail.com (Postfix) with ESMTP id D3DC31C0015 for ; Thu, 24 Aug 2023 03:45:59 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cbb6YHTI; spf=pass (imf21.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=1692848759; 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=slvH5erABEtW2nvv6nNGvvoe5mGFS1H1V89UwcERxi4=; b=sjv+yWlyaFxq71B6JPDufnRJ6LsfBrr6s8b+p2b14VXciQxuLPqnqjg87cw+6G8fOUHMJB Ih/Xt9BRfxBYVikdWDxeFihlmAA/wr9HxgDRkUw1Faa2Kmq0x7RK+qruDTsdNdem5zUFMi nr/uyQZ5a3udqeCJ84ztb/lbndV6tro= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=cbb6YHTI; spf=pass (imf21.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848759; a=rsa-sha256; cv=none; b=UWR6/7g61Mq5/AssV5SNthydCZWvkIOZM4xxTmnuH9ldgBSio69+aB+qjcscCHXQfmFUDk 51A0J5IxVD52V+o34LjPgdAxb8AI3uoc82dTzD39AT8uI9Pv7hZh8/sk7nMP8IakJCEtS0 MVlVXT4PZXBSFOvrgjcVsOQRDBVuSJo= Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5657ca46a56so832885a12.0 for ; Wed, 23 Aug 2023 20:45:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848759; x=1693453559; 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=slvH5erABEtW2nvv6nNGvvoe5mGFS1H1V89UwcERxi4=; b=cbb6YHTIFEQj4yQfjGUpRvykeBzedoRrcnJeHycSN6zpLxRKFd2K1sA1PClUDZpn4T KK49F+aIpE3Kw/cuZzQabHYGj+DcL5bEjWjkQ+qi7ft3Ev2JbxUbeVYCETHKaq602P+Y Q7oloE3/wd+SPkhUMg/xXEsiNT4bfTZky090yFESMFjiMV9iGF50YTAJEOHOG/FFlYOk wZOQ2hXf37apCQIv1XImuzja1cULLKP8EH8AUaPzctKv1kopSAYqQMUxWCHyKDVoFD4O R+sSI8aAT4VztFaIxvs+T3hnulNn+bEQZ9zTNyY0CnFLm+zjLyVeoOaFF/qATgaNLyIK PIcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848759; x=1693453559; 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=slvH5erABEtW2nvv6nNGvvoe5mGFS1H1V89UwcERxi4=; b=k24DVNLiWIovJt9bCZkeHQdJV1gAxL8tJxDQETI/a1nzbtnGdc6bIy4YvwkMxTeomK tBfsy+jXuxyI5RvwqhTpHDLuSghGxUhIHEblhBVilJM9MZEJkA4SoZXvXxfdf1iljXhd brJfUuatiwxcKfthaXhNvbfjWrabor45eLQ/IiREEjS9/0UPmVG9+57RntK9niBOBTMX RbUVeXK6kV8fapdDsSP8+ZbG97CyZqTQFLGkeLOhAOTBQzlSbD9IFMXr/esjLk3tjCCs zSsFZaRdvI5EVK9c+UR//3stjfoQcSvQmaPUkqrdGl0ULOVX9+e8KThZYYwldAXAy9M5 9buw== X-Gm-Message-State: AOJu0Yy01yXvcZZVRfavj3FL939aiR9CAdm8kRjkVXsOz0U/vnvZUmHw Q7afMqUE6ve4CDvbrQygbMszKg== X-Google-Smtp-Source: AGHT+IE20y+zxkxvqCK4atfI05RSclhW6cQ/eTGKWMSl83j87LaqFIyfEPTvaL3BQlf4vLg1/yn0UQ== X-Received: by 2002:a05:6a00:1f89:b0:68a:33fc:a091 with SMTP id bg9-20020a056a001f8900b0068a33fca091mr13891773pfb.3.1692848758726; Wed, 23 Aug 2023 20:45:58 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:45: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 , Joel Fernandes , rcu@vger.kernel.org Subject: [PATCH v5 15/45] rcu: dynamically allocate the rcu-lazy shrinker Date: Thu, 24 Aug 2023 11:42:34 +0800 Message-Id: <20230824034304.37411-16-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: D3DC31C0015 X-Rspam-User: X-Stat-Signature: to3przhu4tsg93z6hoq4tdx8yrntqr3k X-Rspamd-Server: rspam01 X-HE-Tag: 1692848759-261117 X-HE-Meta: U2FsdGVkX1+1Qph+pxwt+vDN4gicggw4tz6DbngRgFt2R6cPvW8briuyPz091tXqe1cJ6++9mnORrPG/V1JUe04c3NtKk6qSIcEazLSNrP5MAzIKMVfv3INudDihehic5DJlknNTUCemfsD0h+Ragu0T+3b7EzomeLZzrlARgKOwc7gS5SIArBB7Jvntig+XupPfB1ODOdkvThKLxGTqPkV2bzMsECnhqi7LfO1obGH5bSYA/wYuqdBjSKEo6AItmMMgMVUOiZQiOmTDwMRik9dMkYWqCuArr3LxGe+qzHxjWw2K3yHk0zsoCcZQ17JuHMUTaGOrMEJuQGCB/127Jw4BoyVln3eN9xbMoKSxO93JEYKQqRoLabvnQs29yYAMCil57s3Hb+qBlI6zPfAcAzxYzjW/Fwu6d+Vi/NAXX7GZs3hX4FJM90KNLWYccoFxqSBeXGaWUfAJXCFSsDE5lTOALofu5Z79+opdgth3N7ugqP+jipik+Psyy5L6YSu8nb4mezUGl+ITeoKatDCSMvT4H9vc3vrhQ86VUWGscacT5acHQCWseA5w4ZI+Hgey8/mIzupeX3su8GLMnlqJITRj5CYJJJAAY7E/lLgWhqN7Pz+P5rUObIp5D/5pGfijkIPg8Hk7oodLP/u9UUxM8BwPrUP0PZva8wdc7L1evqROhqVfDzsWRx7dQz8ms9LxvUv+JrlyuSMwwJMxlunEN5/9X4tfFY98NfAFYIvtERypQWOzwoDslQujHGHTVDuxYLafXghM8k5I44LYGhHtLP91OqAYYh7xz3NfJpS44xJm4j/Z/1BwvHzBnczKx0wmtpJa4buYAOV5zTidSn2dynscbi/wYAPW688zOMFYZIpGmFld/HGTxL1WlW5CQUPcvr5W+/uClIzXldDt2nr175nUYBimS/PJBAyRxTHhwXOJxkpGXHzThUZLbxoDP7R9XxYa4UYlmSc/VGHIJ6D lANmDmvy ugTb7PfCiTggBEJx3Sxi9+RMKzgmXg1uFooBy7HQR+PxTT9GU0Qy8D7zs2YiYjR7+aSg+totkr4TR8oHPnWRNOPLRVq63SsJxIPOwSVbt+C9Gnu0i2togRlCxP4uq0S9AmVSYC/oqKu0R74Jj1Cba10qLxUi5pYnp7huE0wT9eoxHWlOMcWfKOyyN+dozam4YkkarN4nwG9HJUbJeI7JJmf70Bfwro6C4WyrpTwUluXCtJTA25VBJh/e4vWK3Q00PjaywV1Cp79gic+EvWTqQVVOZCUIE699khTUu3AhJuPNHVFCWdGZ8/yuagfrTSLdBSD4/alApHoQIl3+fhczBAmPhK+/l4HC7vnuYRaGGKqlwsRy4l3HlcdBAkBmVWJbE/hTIztNW+6K6SLFXUGDdvOEIl1lNC4/ojBodNTVwB6GNMiKJXvRvRraQa4aVBlTURLaLg+goZFNfFqz33CsStEnGEq+F/loWDXdxKXXEHSJMTf+eI2XRSXGFoouekjrOG0TC+C/GP72ByLYrCs30ES6MQQ== 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 --- kernel/rcu/tree_nocb.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h index 5598212d1f27..e1c59c33738a 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,16 @@ 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; + lazy_rcu_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(lazy_rcu_shrinker); + } #endif // #ifdef CONFIG_RCU_LAZY if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) { From patchwork Thu Aug 24 03:42: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: 13363449 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 99B21C3DA6F for ; Thu, 24 Aug 2023 03:46:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22B8828008D; Wed, 23 Aug 2023 23:46:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DA908E0011; Wed, 23 Aug 2023 23:46:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A3B128008D; Wed, 23 Aug 2023 23:46:10 -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 EBF1F8E0011 for ; Wed, 23 Aug 2023 23:46:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C40461601A0 for ; Thu, 24 Aug 2023 03:46:09 +0000 (UTC) X-FDA: 81157610058.08.061F61C Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by imf15.hostedemail.com (Postfix) with ESMTP id 090D1A000F for ; Thu, 24 Aug 2023 03:46:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="IiUiN/bj"; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.46 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=1692848768; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=1uOv89bXY0ztS89HwYM/VkEy2azSar5NNcEbjdq9FrzlGprfYIOSOiu0eNowwQQ3t4PhK1 47hgfO1LywBHYgDBvmeGNcuv3Y1xAF7FV5tY2hcsKODoGR15Z3kfVmsjb7SpwetHGNFmvF Vu1P3tG1rfeq3Ree+71dDCAkh8foNcE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848768; a=rsa-sha256; cv=none; b=dfss6X3B3aIMRzP7LzxJt9rwk7PVebMco1JjHNR0Bo4hESkxZqE932huZIiYU207oCNXXK imxstSdOO7ppOe2ab911uFezQQJuJiodQtl3tWBl67EAEScAWs4UpFK8Narfte3dPM6dwM etfdvzuEi8H7Ks6PKvTyAGZOPgau3CI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="IiUiN/bj"; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6b9cd6876bbso1576339a34.1 for ; Wed, 23 Aug 2023 20:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848767; x=1693453567; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=IiUiN/bjqiAul2GXQb13RT5me6vau/bBJzSckp9JXiUe4upPQ4em6kTToIKAFTll3V Od3tGDJwfVOeeuoD7X2EdAVfF3HPWTlZ379KPWAjglBaydKVz0P1Hs1lgLWTBOah8eGj 9W2J0Tg6X9lao7+B7pf3NZT+M+RtKhGRzRyIYKpYq+oH9zZ4ysBCEvJaRnJQ2l+lgMQs g+fM8GGLrltVPCbIHCYmgNFEuprUMghQsdUn/H1ZL0iRuqXsb6LQO6t51GfVcUhEB3FE pFTkHgfMldahqqgP2ReV92FlLRtEuIRBNLkFkh+gLZcEWEOsxcxLNSMAqfjCgA5BXPG+ TcTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848767; x=1693453567; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=TvEqWHfTpJ+S8bF/3PG5GJfmRbc89gi9jeLdKONEuh2JhyywZdau/6E7tAVrTao5Mm Q21vpctKJXHpDEdaNQO0nTkSkJxKOFYw3b2dA9q0T0cMQIbytzeR1Oa82we9U3Bjl6VO OBXMduQGyB13HjE1IFJncqFlfqZr7wSLfDt9aqc4JjbeQnFJQpGrV+V/DancvrbFyEfx 2nzyggS09jUPBB7rvZo44rYiGRhMZlXPq91pe8Y2t+FGqcVkqBB3tNs3gFivyoC9TxlO vVll+7Fc5TMgnmxnBcaJ+jD7DrQ47JGol6j5scFwa4FZuWBSUyWvop4n9u4iiFzOmGq+ ifWQ== X-Gm-Message-State: AOJu0Yx3XKwVVJEfweWacgUEhtPpdNS2TD9dqzJnAngIV70JjNRFkoJ0 Q/q6U60jijJiDvaKwR0FMLoEhQ== X-Google-Smtp-Source: AGHT+IElYmAgq8IBCNiz5zLW6QeFhOfwrpP1ZIem3nvpFvdyyt2pB6ZEtNpkzev9+iVdtus0IhkeTA== X-Received: by 2002:a05:6830:65cb:b0:6b9:db20:4d25 with SMTP id co11-20020a05683065cb00b006b9db204d25mr16409143otb.1.1692848767184; Wed, 23 Aug 2023 20:46:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 , Joel Fernandes , Muchun Song , rcu@vger.kernel.org Subject: [PATCH v5 16/45] rcu: dynamically allocate the rcu-kfree shrinker Date: Thu, 24 Aug 2023 11:42:35 +0800 Message-Id: <20230824034304.37411-17-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 090D1A000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5ejcsb3uctcuz9sz5z1mpyhwa4ypmt9g X-HE-Tag: 1692848767-229021 X-HE-Meta: U2FsdGVkX1+ZqOMkFw87qtX8ccRRmcWZKG16w8F0C53JnBArOEZxPG79bfLY94a/iTDFJzsV1/jQXgKibVrK2sXC/ioQFO1qifKN/MD6oS48tE5aiHskEkwvldLrr0Xl8USg9k1zjda1pUQXj8pfXg4+uKEXjXhLrTNPkB66pPF2B3G/xIvT9vxoREW+UJ1EuaeAtsHJS7s44H8rRMHXqGhyRFnXhT+TE805NZOmsQlgarLbEFMfGQn05vTQpC2iROF6Mkcv8pFlKuSAVInHqg1uTokv6UNG8wwwKds3b9ZH1tDZlVX57hGOfew1VeovHCZd/RSBMJDB4kKvH5ms9NxSmV3h03fS1BHcJ8STLEEnGOgZ7RPjBiUZP8+7NkALt7cwaXewxL0OeppT/MlAQ/la14ROtj1LMRI7rQ9H279uz5dsZE+ermOwS7N+jdmC0jGSpm9pCvgiPJJ45Cmat5iay3TnwdJHaBWsAeXWbuApPLgAzpq8VBjJmVZ362vaWt+rCYB5MB9/8XblI/4Let50c3Wr/7ZXUVb845J2ZDfvF9dvTdhjCQUi1idyW6TymKm3hq0IPQdEZoz9p+OsUDA6bKciMJOHnMtRl6u21F0Ksrzhd9BE7aKKv/OWJ2/yEgtmK+32AI4HJL670EJRU+NTWCDqEZn0VOLfq3OKEYfHngzUzcs6zH6gvQKVSGG1UUxkiVD9F5bgh7b36YzAgJvZVorVtdKWEzXG2NfVxbY6jYkFZknXzy7AwYYUO0dcaWZIfLF/iaUwp1NVeCP0Ex2XVC/vMYYq0KGP7BGQjboDMgYfxR4RXR2I40uw3pr6FeU0tFF2j2RVBZ2sGkxFqnWbFiPFlZY/mSsBuhlP9t4/prNKBPV7k4YTL+Gl6jaygppBDvaDCYFamxdFrtadCEQi+8z075FJl2jOz1EypnA98uMTQDXMNah5WhO8Y4iML72cHvL+Bf0J3JTJwOX FkY9MfWt /heL1zh5XBXBXoUEJnmXq2pa5Yxbs510TqRiKLWeQFRUuIG/PVMqg8Lx5dzmAn/z0JoYvRIUqAfPMf22iFddyDDgA6JpXTFXrsGlhBkLDUSR1FJIhvwx+934gWrHCiGXYzD4YoUHxb6zyWrvnuH7+cRUR7olSNnw/QMJomQNR4oEK8K29ZNAhAuiNNZ9TZ4wQi+cOJaa5+pZ323vnfh6rpT8GaXWWjNIYy8u8QQNIfiJLTLviHCCIPTPp6uNISgZn49b7c1NsNephqldDAe2JnXgvi3MaPUlgEZ+izmTMp6lSfeF5DRknHTvt/aKl5Dcfuyctq9CST08wH4UcM+XdmNo+hDRgIcRLfDkBjbRBzIdLQvHPn6Ih1NO5hluKoqD5LVLVcIkNOZGVd+L12Yeo4E2TuDLzCjNYcGzH+XHV03IJT5SeC5OsIkRe8gTlWiryZFZGReQXi882Exj5a2y6bHLWLjY/4C8wf2+XAVK6KA64lGmiU/ZX++PDje0z0yb5kW3h/uEtDv+VqivLFrT/OuB4gQ== 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 --- kernel/rcu/tree.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..6d2f82f79c65 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,18 @@ 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; + kfree_rcu_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(kfree_rcu_shrinker); } void __init rcu_init(void) From patchwork Thu Aug 24 03:42: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: 13363450 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 02CDAC71145 for ; Thu, 24 Aug 2023 03:46:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CB1428008E; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 97BE88E0011; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8437B28008E; Wed, 23 Aug 2023 23:46:18 -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 72A9D8E0011 for ; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4AE49401B4 for ; Thu, 24 Aug 2023 03:46:18 +0000 (UTC) X-FDA: 81157610436.11.ADFB8F9 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf10.hostedemail.com (Postfix) with ESMTP id 54DF3C000B for ; Thu, 24 Aug 2023 03:46:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Q+jrV/hG"; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.219.48 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=1692848775; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=XmvOZsmpwEy3DNzeB+rDGAjT535gc+gfeMiS9DNB0dNDLBZtmcE5Euxv/Zx4eKC5BuGRVf LoGwvs82oj+roFnQ1ayX5/V+i9Jb+1Db4R3KnO87zPLlNq6385ydGWHq07kzerOWvpm6uD XxPdmn3qIgXyEE161ClWYz0eWhieBaM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848775; a=rsa-sha256; cv=none; b=iC8Yjocfy45k6WLhfM/TN2pKp6r40P2HPHfCW2CPKBBopIGdMjMMjsrN2l1/xQpYa5wCDN BFJbFUyLDCH6/J4xrRLHj1ptcRzAppsuwHDO0jFrMIhmv3LFCMlPsJUFDEJdtUlELNT8I+ 3k0q/Jy9tbGKaQDRO7Z+wB0dI4J6Owk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Q+jrV/hG"; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-64ad88fb05fso13533086d6.1 for ; Wed, 23 Aug 2023 20:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848774; x=1693453574; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=Q+jrV/hGwdEttsGppUy814f7YoNw7WLWERgtsHAz86kQBKxj+TwydnndBa3fx5Mojy ECKGkzHYTccZTk/ju/rx6/0rBO0AWUyJrxTf4tLFtE0NCnjpFETXw7W6EA4c5z8dmmI5 Mzd1L79nvDcVnmA/mp+Mr5AM+IOB8WlP1Md/ZoMBn6KxpJSqr2P0bUsWrRAqdA3HaOVb rXZNiWvWtEzgAe28hRTsBN8wfqOr+4cyoG8c4tVvfgtjY+g8QdJJrjn4Sd/SAgoEdw5l Pg6JoFXmZC6Y4NP7c/E9oJrpfxykw6pyY7UCaE+cUQY/aKOjEPVGg7IEt5P1HJPUslAL g5PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848774; x=1693453574; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=c3zc+aRGR1/V/aBi+iBUROFuwExFy6mlRlB86SrIkSInSFWavXlhQHgGfaEArUL0DC YYilB5Paa070rcF9Ws1mOx6U2Urow+DIXKIGI1g36xsYLbj9kdcnKTHA4JahSMArL7PF lIp3ItAT6Io9jlMz4+gWqyozhpGOwiwLXqT+fcoP24BUHXS6t8yuuGYHO341bhzj4srX MIBiQUwVNAdaM/34Ft+/mAq7YNzKwAjm6H6pQD8dC1f7UExFQg9QItDrtEPf2aDh82mx mXpvfJyzHZpS62dynSvUXQNyf3uwvjgrbFCB7OrQMHDurPOS8FPV2wwBJZwPUjfEhlFN 8rJA== X-Gm-Message-State: AOJu0YwOLLCmd0ZfjlFj1kVXUslniC1aOSU/qRdFbp/nHtxhZpikQTTY lZO/3hvBSVxj1c4AzxhsW+TV8A== X-Google-Smtp-Source: AGHT+IH/giC2LTn0MvvTP7+hN9g6irIUBPRUUI2oOCQCQVh9on93KM4yAzkZ9PUzh/cWTAn10rsxmg== X-Received: by 2002:a05:6214:501b:b0:635:e528:521a with SMTP id jo27-20020a056214501b00b00635e528521amr16845477qvb.5.1692848774439; Wed, 23 Aug 2023 20:46:14 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 Subject: [PATCH v5 17/45] mm: thp: dynamically allocate the thp-related shrinkers Date: Thu, 24 Aug 2023 11:42:36 +0800 Message-Id: <20230824034304.37411-18-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 54DF3C000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6c3o95i8ua5k1558w5r4h1guz17gmcac X-HE-Tag: 1692848775-357020 X-HE-Meta: U2FsdGVkX1/0osaC02chZ4L+MgSvC6GfbyBZIl0GCcb6HZZb088Aotc5LNU1l/FMC4htwlLb+eoDK4K6SSq8+zQtWJ9Ug6o2LjPtiynlSh5qmPJwYWQ+S12sNFVOtbMJRRhnLs2m6lVP7QovceHTcgkKDrOiLmXkg3+1AIdhgzMmmxfMga1VAmGT+Fm9oAJASy4N+I8c4ir52ltOGNAWdCEIP+CMXqymYHNZIVsFLW5VhC8UVuKzJIJRwdkPzYS234jkDPJLbJOpgCyYEMp8smFuL9asyxyBy5QwtnuDmiGShAZ5M+mKksrmPUQHoYdloPesDR2jqWc8V7DG6P9udbgs4CI3aUli1Go6yzN0V8/6OpMmFO1q6kl5pTVavWuqXUbw6n/HZSJFV9YLnBjJ4iA+f7CM/C+woknA+uhRDYxqmjfrHa7dTUFXPHHq10nymIEPpLfJRvcqzLU4FnnfMo8uvO85hsp4x5G0upy18ix4pdGiFvojrd6Mb9Q0OU2OiFY6yXp4Qwc2SJ/VBuddC7mh+6Lr8+L++fyILBKGljhj0Ifts5mWwEgvMUuanyc52Bx2Z4Z3Mf7BeAvZfp4pQqIU/iTCuN1qJIbTC9mIsdXcS/KVRHbb2/KQRPr8y52KEGdrw9UXnm2bhyBGM5ujVtqrfst0elvT9mdIXstPncUL8fd8WaIuxom7e53+OjqJjWa4MJ6zvllUI5SCPZ9qI83hsLzU24FwkRJHd0nSudZLCw+hTMop+YDBsAiCECTE12x/sOu+0jwIpnhSnQRsm1gpe6+TjjEChw+54Z5m/i2rJ5PEMC4bjpSsZQAkZcZOiCpfNMOybCTXzC18jjNPdovTvgVEWHrEV1JPoZJxF2CPH+15SljIn3nlZjiUp7JY6U5R/1Zykpp9DBoFcjx42TPCLe4OoQX+RbhP4arWGp9rVy6zhmvXNXkTcGiA0nAWc/TkoE7xUElTH1fJ0Tw uRjq0wil YeA6GyUG6jUdo6O+WnSZELk5cJqRuEDm9vXHU9TF6lrMTuTVWDO9r/U94Gj9/gtoFa9ePfYrxXZnsfuNe4P+xk3DUl2fjgLs7/z5ud7EZEmvn/1v9o2VXxQP5vBGOtiJEn/jNURojUufXs9kAMfAW4lWVaem7WRROufr4Gn6KWQ5vQE2WgDxuk1Zfwk/l1w5wRx1/3l6O4SiFVyTdzn2yJPMHXbX7ZyI8+F0jj4d/lkV5MOLqDx4Cvsv7ZDJU5tCDLS6Bi6UGK2O075EBRzgKfX+Iqi/g6W7q7eHuvY9Xmh4BDxtSyKioXJGa7gTHMRXvzLPgu7OPOgc9PjEMhKMlLsxgm5nq/q6jeK2j/R9TilwatvfScjXqHOfkruL914ftaYlul2CA2ykYRBGx52920MzaDUO5QKvtIpvF 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 | 69 +++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3e9443082035..3c9c692e3376 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; + huge_zero_page_shrinker->seeks = DEFAULT_SEEKS; + shrinker_register(huge_zero_page_shrinker); + + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + deferred_split_shrinker->seeks = DEFAULT_SEEKS; + 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 +516,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 +536,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 +2857,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 +2931,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 Thu Aug 24 03:42: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: 13363451 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 76935C71153 for ; Thu, 24 Aug 2023 03:46:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B5D928008F; Wed, 23 Aug 2023 23:46:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 18D0D8E0011; Wed, 23 Aug 2023 23:46:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07BEC28008F; Wed, 23 Aug 2023 23:46:31 -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 EE5648E0011 for ; Wed, 23 Aug 2023 23:46:30 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id D131F4016E for ; Thu, 24 Aug 2023 03:46:30 +0000 (UTC) X-FDA: 81157610940.27.3D8464A Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf10.hostedemail.com (Postfix) with ESMTP id 4068EC0007 for ; Thu, 24 Aug 2023 03:46:27 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N0bEBg41; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.182 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=1692848788; 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=YqY1sW48iQ+/RBGCoAIbrC2fRJNneg9gualmoKm4Jhk=; b=1hbfI7gErZ2T9MU/2oHs4FXEdcSzpy2dYtLRdQ1yGTJaZ/2SXbk4hq30ULgyF2RQb2ONgn MPICU3ZW/m6OyYErKvGQJHDs140w2Mgad0jBybyRKboiyp3zhO0txUYPD1U6xpEfjmWiH4 SKVXl7cbDNuLDNhQn3Hl1/k5YW5TbV8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848788; a=rsa-sha256; cv=none; b=IEbOyOBxpEj4KvfWJMpBz0Ajypl5NjRIWUsxSL6lPw3p7Sf9jZFMLAUwVeU3VmL5Y1eMJb Y0GBmiDQycjYe9vGw0/BDm4Ld6ZKm5s+jzhU+ha6EILzNGMdtAmW/90HOnJT5gFab80DrD miU8b6T7z287FOwn+hkOF6ODX0oJtPg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N0bEBg41; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3a86b1114ceso349327b6e.1 for ; Wed, 23 Aug 2023 20:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848786; x=1693453586; 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=YqY1sW48iQ+/RBGCoAIbrC2fRJNneg9gualmoKm4Jhk=; b=N0bEBg41B2iY9D35KYwN2/tcoHlZC6rvdfxQ8MjWAAVsJrbSe5QQ1AloOksBp+VCG5 ovzTjRjVhwYuCbijaYbBr/NoEX2DBF86HPD3n/LRoilc3AMqFdIYMudsb9GeM0FF8+WD vfzr6oFXwaOrFRMP37o0w+E2VaPjRYmk8vIEBd08PbPCV3/5qCp0ZssMbZGvzPANUGFF l6D1M4RhmrFVV9Agr9KolhbMLgXrKCLvdCdLgkrxKJwEQ6ETcv90MZzzfe8Jv4mnChvc gVqnqZEKx20VOlCNLIRQDT+wJCga0Y5MKoKyPRqMPQvG3t3uAT+WeS34pYjowcn6IWJ/ hSaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848786; x=1693453586; 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=YqY1sW48iQ+/RBGCoAIbrC2fRJNneg9gualmoKm4Jhk=; b=QwvzTCDRSxdK1jpM1lC9Vj1bGXoVPOKkbpJJr8Os80ikv0Q6x2CACKGsYQRFE0/rGD N+EzuCfmKvdRyUKyioVUqrW9E14R7WovezfXgY5S89jEvOwg3y/aabEDeA2hEQfRhzZF p/deGlMKnJInMk0RH7j+hInt+9ya4Ok5iKSWYYObggDlAz+kqJgkqKPzo1x8/5X6DB7A 9nTsaaHgKEGL2/fRZmHpYMAaNWsqyVDINS2JTrmJddxyGZY/L58r5ohOLe3iyNU7qqJj /z/VP7kFZNXcgJIElOMSl4zMGTBZLgdtk/6Y3POMTfrliq0OnCMdvDYZA9QRciIV5dsy 7c6g== X-Gm-Message-State: AOJu0YwwuI20Lp6i5fO+grekoa2EM5cEklljFKdGc9ZxKtaMPEfwU4+V dn+pVeTTMfW7Zg5vTCZM2uDsYA== X-Google-Smtp-Source: AGHT+IFDAy5Zu8VOU9YTeKJefKe6vLUB7EXbKU3yEeM/VZ53vwtmd2t8ca1mHqoiwq14ODWnet2Fmw== X-Received: by 2002:a05:6808:180a:b0:3a7:8e1b:9d4f with SMTP id bh10-20020a056808180a00b003a78e1b9d4fmr16975412oib.3.1692848786259; Wed, 23 Aug 2023 20:46:26 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 , 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 v5 18/45] sunrpc: dynamically allocate the sunrpc_cred shrinker Date: Thu, 24 Aug 2023 11:42:37 +0800 Message-Id: <20230824034304.37411-19-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4068EC0007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 4kdktfyy5yrpwr5oan1funa66d13gu87 X-HE-Tag: 1692848787-32147 X-HE-Meta: U2FsdGVkX1+jXkOprOYMNZcO/gBSfakPlaWTft3Z13SwGmpnoIUjL9zx3RqTuz6Y5NgWExdnrdFCLEyGFDJMbsacgO8uBtd5FZ5zRMgv2hpesUNY0cOMG7jCJDA5oTkViEuzmHJkQNwWz1OMFrV5vB4jBHlGcCEW6Cr60HFZCIh56L7oqGGDAYMK1QliiY0xiSsQDW2td5Qpnhd6zDihNZ4P90mAIK9oN9IhfK4TWLGjfq50bjoFqQlzCaK1ndgI42ZthRCf4Yjy4r/yLR4uCz68qmnhwMYRk/Rgku/sgCSPph4iCw9nJoFSzKSxNznQFps3H9UbU2xSbtM4Bt0UtgbPPGm7BhyZWe449hU+0qHEL6nZz9uf36Zh+7RoToDzCibtVDx7nLXzu9JbbG/4g30UWNiYMCH/p4jUMV8ltG7uti3UBUmA9Kxw4UYOKRu9Bpk25VHwOWOZJm7OVdbtunG4yYZHY4ZsJBbFy8ie4FpO0QfIlc7Np/u4boMpvAJ87socqb17ZIAKntsZSzFPT4fy8wRg6XYlK8cyyjK35oIBE+8LFyCctKksj3/c7jT7WDw6jMmGkktw+QyQRHwmjvDoxQKCHP69xJfZOJTfAMiT73PceiYLcaBw8gwcEwzzSpcl3BLB6oz2etDaHvg01YbMceKh+o06ITPOOkLubqQ5LmRf/yvqYg3zQR9BDOQ86wJJvNR1xZQL/X41kHoqCiOOL3J5kHvZlU1HgLH6z+1t5noLDNnrpQIgr6liEE1gW9meUm/R9sWAjBotqujZfV7oRqkyxEDts5X5UMNsL/EkBTWr0ZtzgbBXbs/KV7wWYdqY726iP+5Jo2a1TyQx1b0ttrKNI7s5RfnDj3aQEhwFmYlr7A1Ues/+aLIrmUy9AtpzTbdgNFSTX35/XmOb1ku/CPSvpEMspvyJOPvVFgC435IR1yB1yCKHgfwhx0mXwZ+RnGHKJ2KyiRiKBLJ LvdAkaWl 9Eo1MyhgbXrmRVNUh/pVzZgSd+iUnoeXIgiKIasdyMKxX/mMlxE5pU6qxWQknSsaGwOrwrfXLTSWQ1iJVK3vxFPT5WZjBMckgIJ3iGNlQT4fwlrNxdNutQz5/I5kfn2NvwCmUQlTOPX17Uml4H0z9P4uYeE13WvxejpWhhVWJVSLh93I/KoXtIsiPnPCoRrrh7PvqLsSZJH7RyUPbPmz3nJ3athDRralQJV5jBAbgY3XPd+rLhMmCMo69u3XFw2ZTk+yEbUFnlxKsGJUt2Znx6T6WrwhelwlLoom6F+cI+3AgpWSZYEGkhWFdAt+OzKQgBMy+8WxBWoYlz410h4gN1CeQGOmHH3YzsN/54ZWYHBXS+srvkf23qrK61lS6xRX+7FdbiKg+6DfqhCA2jeb1mgYsUJIF+OLHiEkJJESpIWBGqjYgXmIfAHSRadb8obowDge2/c+dCHpdP9SzLHDXPZmGYwwvPwMWoq34jWyFvXGMtB98K7nvlyGI8OG2n7pzKCTm4Eq7HduySY0stArFobUx2fcgNxlkQFl1CMvTrWPBnYI5bPaNFVlTmmNQfkW8pYqr6uitx3YLXsAc7sKZ7g2RvpNnrXWEGb3uLwkA9MToVgLZbo+XW+EzFcoepH9gHufyItFrN6oBC4p0PlCZPSA+d6aZ+aUhgz4lFivX+/5UGKZlHho1ahG8pPHuNxCFrmgrAZWX2emyS+VwfQC48qIeLOQAHLr2mCnG 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c index 2f16f9d17966..0cc52e39f859 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,18 @@ 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; + rpc_cred_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(rpc_cred_shrinker); + return 0; out2: rpc_destroy_authunix(); @@ -887,5 +892,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 Thu Aug 24 03:42: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: 13363452 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 966BCC71145 for ; Thu, 24 Aug 2023 03:46:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 389CE280090; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33AD88E0011; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20234280090; Wed, 23 Aug 2023 23:46:39 -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 0F48B8E0011 for ; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DFF99B1918 for ; Thu, 24 Aug 2023 03:46:38 +0000 (UTC) X-FDA: 81157611276.26.49052A7 Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) by imf15.hostedemail.com (Postfix) with ESMTP id DC6C3A000A for ; Thu, 24 Aug 2023 03:46:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NcBMtAaa; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.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=1692848797; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=Nyw8PJRJOg9guWWtvwd3Jn2HFdj9T3QdN9VbBOM+2BwZhuR9QJx64m9x2WPeeOqRioh9/v cEX1JCjt/QXFUksA5f/M7SVIx4rdSxeN0rTNwDF1j+zDkIU6bZQjutnT8vXNlFvYlowS6C AUmZLNgXYt4oMV/rcOxLwztP6pWyDQo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NcBMtAaa; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848797; a=rsa-sha256; cv=none; b=mqYn7q6PxWmzZhUxLmyn4k/6zV9mCBIMN17KOaSv/2Gj73XiS57cNdGupH7vzmWlsnTrfr zxaddu3w0grFPhFWPkLR+reUTVuYREiWccX7BNRneGesW8G+FUkf0AXwhq5py8WDyUXhe8 y4u2IdYkmW2K0iDH1yj3PSecvY4fbbo= Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-34bbc394fa0so5580505ab.1 for ; Wed, 23 Aug 2023 20:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848794; x=1693453594; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=NcBMtAaaLE0r3U9cq1G5ArkW7KseQfBeg2oIVpo0zwEHj2pxIXv396lmpHWvqNY6WL JjyXJcQ+71rZjpvUyUbfQ8TBZw5eC/hpC4SZQrI5yyx8ZDcSfC61r6xS0cAm/1P5jMWZ mkFz/DOMsozI6+D11/YuxeVQCAHIevBxkzEmHriraQYG91HLeEL/u8PL5wK3f8VZRjuT cz8d/r+S9nMPLi5iQaiL+tTIS8oLRmffsx3mniOICQT+h1azffq4WqSFD7IduUw5wFnG KASaAakXH9kG67rUD+T3XOhVhqWNxRqdqrYEnF7FkbsAyj3LDEWSCHCaKrbISFen/hwS Jp2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848794; x=1693453594; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=bWXObE978tOzygUhkfTP17D+iYdyk11rKNtxqUNICgp0powT4IlU8IjpdAi+3jKRhM biTpdptyHRaeRZhpCL99/gD/sfn3W75QrcqNRRky4PxkDVj/fQj1su+4Q6YCJ6OH+k+Q HqaAbdpTQSYwjTNC3R1ZC6J5mC4nsHMEwBggzNEIQJfNGAvbovFxahqAQygtn16N+fz9 j7M0ddQ9rZUc/EfEdMv6hxbmIx1ja5lqhBmoKG7/VKuXXicVSed2VTrNuc4Y7lNFGndF 2S3qlGRtwyN1qizXBEWjKDSQ2rpIjlKWNgb35f0wIZFWHfjQv6vjXAh8e5ye7vs1zaqI PzWA== X-Gm-Message-State: AOJu0YxFeWPydli9YawARnJ+Pk80LL02n/FXxgc550mDERkFbK0S9YWW C+KPgDtqETIH6VkNseFAjUb16w== X-Google-Smtp-Source: AGHT+IF6gasrupmNMEd6iGY3g7E0ID/cc6G3nenUlRac5+F8aF1f3dod8FyRICkvmINEgAPLaLvdgQ== X-Received: by 2002:a92:c90c:0:b0:345:a3d0:f0d4 with SMTP id t12-20020a92c90c000000b00345a3d0f0d4mr15091049ilp.3.1692848794044; Wed, 23 Aug 2023 20:46:34 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 Subject: [PATCH v5 19/45] mm: workingset: dynamically allocate the mm-shadow shrinker Date: Thu, 24 Aug 2023 11:42:38 +0800 Message-Id: <20230824034304.37411-20-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DC6C3A000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: atcgjsf8gyh87grpcxa7spfjkpg7wrsi X-HE-Tag: 1692848794-789981 X-HE-Meta: U2FsdGVkX19CLV1KPIm4iZpCKhWYZmIoXB0rjSH6jV185Fz8Jg5mHahmKDHjAr0IwjiyXSCuEIEC8gCjuptK+wG/5K+9xcrmKHWNShV8FdeDlEL2x9R+xmsp1nkJgMKJ15WRMr8Nigimlk+l5jqumkYPi95V9KWfhE3kNgME6YSYDOqR1hRfAYOMb1PyF/39aqY4IntU5gcDyA27SSTT1px6KjMC3KyOXwECC1gzKA9ydoTl4x/dvuc4+iTxoRrIc5Mz50l0FV3TsgOj8OgnLk/i1JaaNCuWIZIapbR0B3bD4W6F/7w8y8QMipHSIHWK1C392moYCK3uXc+rh4LB4crYa0GauLSDn4mn6p2at6hgrWN38VsMjBmZW8UfbDZ9j+24UCVM/xaSGIonQfHCTIGoEcd477jUDoWj4WlVKh8TVOZtOyAMaBGihLYPfJ63jBbbee9zi4659qBNK9wwE3GNP2h8FxiK77fvycvXkEEjhl77PI3ssvQxVc8OpOE/QNrOkFAq7UH4iigLoq3GaVg0NKXTAFpkDlwF5Xo56XBUzb/gK8TETUow2PJWry+7oXOzcu8E8KDIJfwGMqkrTQh9FlvHgwLWK4jxiDDW0bIjG9C6fbygN6z+AVfNhLB4dE8TMC+WnTcCL9HEcfLeJUfAwuE3lV3WdCEYtUtGN+FSRqJ+6bPb8bWe915fZFbfCtiQI9ynklcIbjwFe9ZR7DlR2xMCKNsbgZxsBt8paAP0rPxtKMHMCGAi7k07To1knLt93wRQHWzKgKVRLLvVosJa1B92d7YYL3u2kpBBW2PhXcGF3dmpdmepWzmEtcfrp0UhLzBZaYomzlLPJ64K+Q0ylmb2Aq57AH//BFOevf9E7fpn29K2LXUfY1PZhkouxKjjorDBhK+X10TdbR03j32+BPtvTSQBd8wxcPCjHolQy1lvFEWSBGYd1AyDTOHNr7kFyBDep1lb1+DU8hp Gi6wuHmd vMolOT6FHNW5i6i7TW6GgSbsXYcR7ZKUm8mz0z1eKSkXZGDzpxLdDCp9yXaeHCCvEFbezuDkwHOIGd/PArPhPdqb7TQSr/IezFZVZdrXQt64IofudpO3MWDw7Ql8qITdNnBdUztgM5Ex6ASGIomyzouA3UFMS2a/xqf/KvQXyp7Au2BBZvh7MsFQN27s9qTYTXtQ5SKWo0f15wNUfY9VXoiexTOso3qGbb7NwD+Moax5iGGmA53X1LKVkygaaLqiLYnk1siu7v5Z0kd0vVpPdyr+IAtWG4DQC0ghrU7mICy18VwKuSRMbZlG8wV/JGr/hkhnFKCrQ6f4cVvWLqYoua+fWmgYFWalcvJybrUvIqf3rfYIr7GHpvkw/fM0kDbGcOFe0A761ewG1L2r+UQ8+Wk5VgvIavRY+z9mj 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 --- mm/workingset.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index da58a26d0d4d..3c53138903a7 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,24 @@ 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; + + 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 Thu Aug 24 03:42: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: 13363453 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 2FE47C71145 for ; Thu, 24 Aug 2023 03:46:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1601280094; Wed, 23 Aug 2023 23:46:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B784C8E0011; Wed, 23 Aug 2023 23:46:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F1CF280094; Wed, 23 Aug 2023 23:46:48 -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 888448E0011 for ; Wed, 23 Aug 2023 23:46:48 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5FAA28018B for ; Thu, 24 Aug 2023 03:46:47 +0000 (UTC) X-FDA: 81157611654.20.4467B1F Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 7D45340008 for ; Thu, 24 Aug 2023 03:46:45 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M9ObRuet; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1692848805; 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=uwx31tS90WjUWjp0SbR9DGcZF77FU28axltzBJRt4c4=; b=KLAhOC9zRvQ7+Ls1hLtiwx9Pl/KBEbtYajForLMN2GmSg9ZANiomOoORl1Gv8SKzFlmo6f 1CILZjgjm6L1FmsVYC0zDQwpeKKKeQYc7EWyaxIE4gEfxXVD8tM4aMfO4M4X2wlk54NwkL ZIAvnSENcevwduGTS94qNWmf2v1mpk8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=M9ObRuet; spf=pass (imf12.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.173 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=1692848805; a=rsa-sha256; cv=none; b=GdKkZwXBW/7xN/CfFPQ8mnmObS/siK1ak3ttFBSSE9VHMPVh8jSBcZ3MOgUQ3SBgI/iw/K /PzF6t2rmOnlSVInQW9C+A/fVfig8SljYr2dgvwbEKyn3jBch2jp1bIbCiP+i0mo22010y gJ9ktQyAbB506RTu2zcco92AKbqh0L8= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062495b3a.1 for ; Wed, 23 Aug 2023 20:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848804; x=1693453604; 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=uwx31tS90WjUWjp0SbR9DGcZF77FU28axltzBJRt4c4=; b=M9ObRuet+5GPiY4quY2/78PUkAPB1JrjsB2ESQr8Kn2AmS/yGh61g1cECo/MnMph8R EgvmGO9xW7uKzxLJT1EsEhHFDVz8SieDFzxIQZ3yZqdTck2102eAJRDpa6WGxOX6HJI1 oyAm+jxYdRzKYJXtVMNWxIgInu8jTEmDbViIVQNnJb+aKHQ+v1QOZyzn/AqSRnLbLycj 6PdLlHtIT8mann8zWwocxLvjESk9x7768MCHxVbB1agjjmBEVTFCGSB2g8quENDN22nn MxJ8OICOclnmIuKfUmbWULuOfFSwJIbwJlmI9aW5sqnhTe26+jLXnkYaLv9NGdlm90ol LaTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848804; x=1693453604; 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=uwx31tS90WjUWjp0SbR9DGcZF77FU28axltzBJRt4c4=; b=cgBZOoMJ6lr07LJ0vhsWRJ+HPOeiCUrbVq0OXVPFmQLYXYUyXIfSt1BLB6mdtK3SkV ybyzNN2S5Cyznujp1AyuyXvNhZtmBof5dmxOIeGMromaUWAJjfatSj9iWvzbw8i98wUM UTyrh/eU3w29aug7i8B7q3bH6r21tv7QVUapOrYLV6K8Otg79i/fXsmmHnegJvwbyu2t KP8G+vgPmYqnPzaVNX1gttCEzYpwVVhBvLkGoYN9ZNhY7xOR4oy5iSBUwM11iPfSBQSj ulSIWXWQazxaADvkorr7ZyKlNukKIEDSLqFDg1LY2Qq9a/kTrJc6w5ihSL+szVhiWjHY KjFQ== X-Gm-Message-State: AOJu0YxsD5TTwJgJ55oKbWSJX7oFcZSAzdhuUVPUK1WzG1JgGaVTxqyt 86i00KxCZyr4EgRcmEmRPF2NbA== X-Google-Smtp-Source: AGHT+IEwX5EZusqZS4WDTl8vi+i2E+fjUU28VXYK2I5UDaIClqUUGhB9bFuORRwXdWrDnPbD98IZBQ== X-Received: by 2002:a05:6a00:1791:b0:68a:42d0:6b9b with SMTP id s17-20020a056a00179100b0068a42d06b9bmr11892145pfg.3.1692848804382; Wed, 23 Aug 2023 20:46:44 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 , Daniel Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v5 20/45] drm/i915: dynamically allocate the i915_gem_mm shrinker Date: Thu, 24 Aug 2023 11:42:39 +0800 Message-Id: <20230824034304.37411-21-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7D45340008 X-Rspam-User: X-Stat-Signature: abd9xcc1fpb8tozx97nunou36yg3srf5 X-Rspamd-Server: rspam01 X-HE-Tag: 1692848805-804653 X-HE-Meta: U2FsdGVkX186//3LucrOWuQA9Tt9whWcSkUJ6nJQMGu6piZsvjvE2NADzg8B97vfui7Ajb68OYAolbPkEfbcmLVI8NWy5aID95UTDbqeWkt/1Vb9j8Pkky865i7iVtgH1W5d932vwX8NzHeBQtXUtEGtiri8wur1zur/OGBhSQFcXvZCTGH087DWX5F3K2TpYd4ohDg4VcJ61ioe2sJhsjMhvYpVdhtL0YeGtkU1sqAfbLDJpwTvsmSwvkND2ArVHvL5IQo3rodPpWA2X9SKixM0B3T3Bfxu0SH4F3Gq30YASvZI1dRYQHaYn65ygjT/SHYqVljVeA6ujaQMCu4ZSzIhUFwOavLLKBEbUAYDECi2+mk1o+nGijpWeW6B5LKVw513S0HzPdqX1l+aH3kuoihvaYUA1Z70dUxI9PVDeaO1dgsPZZzLOpwTX1Lw2GJ950GkfEyAsA8hSaOBT2x6MBeyPZ/ya/fKzUhLC9LXVLijWZPd6wvQa8gvIOulV5wTayozDmTu0UzcBkjoMxENaX2pfVIgWsujc2Crn7NJCVTcmKgmS0TolMhqyeuk8aoorlmGyiyxPick7jBKylQyc/xQKbMpbTkc/GQU92M+Pu4krlw6W94GT3A00569bsH8xVvVtjE4d7dzpE2JP8LVH/J/fwBNmqd3kpN6PBIH7VYZ1MXsNZMePDW8ZTeMQ+F9l+uz86XvL3zsNDpT2qZH3Pt1aV/D3e9PvgVel2/F4/kWWJONRRUFbmKEg92CISeNLwDL/jzaGf0ll3AQcYzCoNu159K43d1o+ejwF5fAitnQIAOEwWA2McZt8NqzOnRantqFbwksuP5iY8jVLVrQFINxV81WOsbjl+xlz7G3WGfiZ7eXkRiB5L6o84IIIuJnoXJybg8UjrRzXkgERJQJ3/TZG++BjaGSQl13KY4gEMDQ9gobvaeAC8OBbEzxMElyMi6pFL1TGR3QUIQ9r7F Mv4Lur+T Ge3Emh96gzE25fBYFZf1rXb7957dm+s36kq/M/VbrpAyBs2gEBghNdwDYqaPtR+Q2SukwVmVpMiytajpxgzWBKlWA3vXqnOuMFPQe8w95TqnhHfGhVaWc16X0X/LkROGQYyXYwNPXCCfbzNBHoeCTH81ryTHIkIRp/ZSRCZVxnbUDrdLqH33jqH0pGWBrC6nR6Rad2U0PAKokdxLM4iE7ClzSd1f+wcU9/TWyZ83et4alZrcfBm0lyRYuUEZWxUGNqeBjeMXoEalHtTjK9zXd81Y9HPf36wtaWFbnzRza5foKIGSwrWpp6w9bJOa8eRn/J+H9ZlpLTot5OtJsKGRINC8d4gvxukJ5aFTFOo49Tq5fjQh1QviCVpEtZXH2/PK/sMvBLWsl74ayC9t/2JHFb2T20KUoC+eDk59kg7PW2wowrrsFNAFJQoLxtN8DhY0BG/oSF7jBG480LwLULkETfj/uZm2aUnij3p5lBcHh7OSeJlRVCG5C5f4kW5QCK6h7cJ8mMQtbqQOAJXmECOsgC73Rw5iBsFdPFuylJm42vxxVpngPTybrk4WYtqbRYVMgTvD9 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 | 30 +++++++++++--------- drivers/gpu/drm/i915/i915_drv.h | 2 +- 2 files changed, 18 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..4504eb4f31d5 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,18 @@ 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->seeks = DEFAULT_SEEKS; + 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 +447,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 Thu Aug 24 03:42: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: 13363454 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 9AFD5C71145 for ; Thu, 24 Aug 2023 03:46:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3FFF2280095; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3AFD48E0011; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 22A06280095; Wed, 23 Aug 2023 23:46:57 -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 0B2628E0011 for ; Wed, 23 Aug 2023 23:46:57 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DD596C018E for ; Thu, 24 Aug 2023 03:46:56 +0000 (UTC) X-FDA: 81157612032.13.20F9A31 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) by imf17.hostedemail.com (Postfix) with ESMTP id 2138A4000B for ; Thu, 24 Aug 2023 03:46:54 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RN1mTOYq; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.53 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=1692848815; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=mEFZfPpEkPetTVsOGuPqdfSmJbzO4kyokRZGFW69OHu3SFn9jpIakI0+72vgYItpxTJGZ9 6X0b7J4FjMHPXmV4ttX3AQlscSZ1N/5MelJLiI02YLsq3kXMbmGqlSasPp38NerVeURCo/ jGk+zPsyCl4dq7HSQyepyrmoI9sKmuw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848815; a=rsa-sha256; cv=none; b=Ayg6mt2dTaOYYd4l+4PGwo0MXcA7QyQtpTtaV7PUAYD9RoRmWGHMYFTTHRjcH/vcP+B/sT is/+lr7UuaQ2pEv7nRXw6fbb7JB5N+ruov7q2ShWDHcIHAFZ3scjsSoaMChwWbOqqACN8+ pcvcuuSZzTdD19Q+R7TsRusgqnJzc6Q= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RN1mTOYq; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.53 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-57328758a72so32467eaf.1 for ; Wed, 23 Aug 2023 20:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848814; x=1693453614; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=RN1mTOYqeP3avt9zPEfyVXBeBNAQ8xUum2++yofpjKihMRzWKaexWVds4tD6V7wsIw 3d5/HMQodK2lDRKB3Hvhhg7R2LKBUPTz4foWriRhng96eFsm3nWKhQQ0/O6bcRFM3MJC +RLzQkwSUIX1ml+0BnTKRnbLipEaKec3PbjqhV9dxmp7JAWauKv/AeQCqdq/vzvHEFsf rCKVM7V0ua1GmOHzKpj68Ofh2DOeDKGWGBdHN71OFxMQ9d/TSugo+gBJOkmh9nR1r/OL eVcP9OEAfMz4av6avwQtJpiLw09RYNCv1fAajmP4zjNQQ2P7i9FdedmRGYhnia/2LEnH 3/Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848814; x=1693453614; 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=3dnrZkMjUwZ90Pt/0bCLaxIeLk8svU03Whzw6qzM0MU=; b=WO9+LimnlM1DkQx47ySlkt9feGoKQRKs5devKy3YuESo2GGSShLTu2jV4P7ZGU1pop ls6ngTGfbR496w/eUqDMcLtY4vN4GvziKjoh+K6Dcrb/5UBofNjVKx2uTwKPzPN6tgs0 hEtfdJSc5T+jvMQajOiJLI/PRk3cmG5Gmeq25VzThtGsGgkY2V9HeH9oMIQ3DqBwLios ZzVHpYBI29XpF+FFRqVdgC/VXAU2+dRCERirbtNrPjcFtxe9jEHf1YdM47Qu3T35sT4/ jpEXPjWQ16kB0Bdkwc7mqg5jXc2Dx5oIXVfaXuvjMKvGISfwwPN71vxVoJraQUyvjCQq XZQQ== X-Gm-Message-State: AOJu0YwJ4kCyKZyg/sV4iHkPEjWyXvgUb2nIr/xRrgXQyIdsoqPGwVqt Hc/pDfTWnHZdkvAI6oiF/Fn9Mw== X-Google-Smtp-Source: AGHT+IFg9G87rSymCG7MIid1bupCDmKVyUn8qbP2ZMCQySTJZV8TnOPBtknFVjpmYamcXmmZPTN/qg== X-Received: by 2002:a05:6808:152a:b0:3a7:72e2:3262 with SMTP id u42-20020a056808152a00b003a772e23262mr17149902oiw.5.1692848814359; Wed, 23 Aug 2023 20:46:54 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46: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 , 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 v5 21/45] drm/msm: dynamically allocate the drm-msm_gem shrinker Date: Thu, 24 Aug 2023 11:42:40 +0800 Message-Id: <20230824034304.37411-22-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: wwkhfnn9qx6ms7mehn11mqww9rqubotc X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2138A4000B X-Rspam-User: X-HE-Tag: 1692848814-326194 X-HE-Meta: U2FsdGVkX1+7sBVOq85mKML/kV9EFWtwr3NOYgzzVFjBpVa4ybtmPiTg192Jz6Idpq2Xdvr6TKglyA4/cIWoNtn5tLpyZzytd+TQHewOyRiz3t5Ugbeh+j926CZcZ3L5qU3cOrRytRToqbumwThk52RLA6KmWYwbalc/AIAa9IPI3sWIAjy35BJ5TjOsg66yih0jQaQKRZI+tWOQls7KYLop49Qv/VGj6fJFQMxrbMx2o6IBDduLVKBQMneEqIX2W+FWvcd90+VMRE06tLTPVyKpPqkES/x7pv3r5brt4Jj8WshrGTlTQmEhtfy39DsFIgGnDUeimfZngIuVy2QhtbeZdrLutmH1YxQ3q18yFwO5NkBPIbUeghsdu+4vAqQUGHiGuKhy88992je411p2MxCCHxFmR67R6z6pLO/NE8SDTFBjNoEIgCpSCmlXq+LXhjaDZ16a3AU5Y1BxTinTLYvlkwQpF0NwzDtlMMqdgC8FBP4FTKh7SnivKvUjWj13mYPebyct9kkfCvrKpHOWEr6zmQC9LbzPdsiMRgRuLvp0pYJ745RzCa7LL01TuRI48hvH0a8N4Kh8xR1RlwbsXRetElXLEDb90o7DNqn8fhzqy4+i1O8EEcLogxGTDnYXBm9VJuJS1BfMrB/60WuZoFom/j5nXTZP1s/kk7q7Lq8CYpIlj0w7hnfnk/D2TjcwpHvTAMkdkJ/F0gO8VwSbCwCAaD83i71wI6HOWsED94HlN9yRXqM9DobQ8IG9nASe6TAoG1uAdMYODCGZlJsjwQEGl6hOgqfF9L1KVVlTo/vsOhiPTWqFsPrNMJPR9ybUvJvp7wU9/tDjPjCx5HLhgNkUSr+JtX5vHhnxVnXYmXg0Og6tpGHD9s2RSTE87fuw6EyFdztjOBQsUxb8JNbTIgJRJ0IKxdPjwhlwIELaq488laUCb5ApsgisLWQm3Hfmz5JjCrgvUxIdTGOERsp 1vCDav8H /hNoiI4nIgWTFTDKLlGvcZA2VWfWsy25rE8DA7f5hQ4Yn5UxVFoeSdfZXJ+/R5Gm2n7odVGkhlWc4VPDDdauCmotOluHbHuMRaVxUlUp0Y2onYHb9FnI1jALVml/iXEljps1xtAnFp71FnDaG8ghsr+Qqj6P3YbxwAZIDOT8HIxpxiFwyRl+QZ6SV5MCHSTiWuMJrTbfZAS+rOgXJA1wGWCbYQXsSGY7G3MK15kMWporA7NOspQ5meejpP28SDtFQ6eb6fTSEeT+8Zz42Hhms7z1Uptfjo3iAaRDJMfH/Lq6xSd3OPGkupOvXNU2TmYWgFUSTymlDJL+in9Tm13hGhyQf0THFiL8txxuSZ/2k5h8evvA244N1Ie5f7pBDu8FrgmQBojCxuZ5kogxzsJOMjqr9rcPd+vMHBzf4l9iRBBd4F9YsaqYtwPfApDSZGp/tqRnsKb9sdv8ueAzMCekrXrtRVrW+VHXxBK3bOXsizzjb7W95yWyX0sQT512EDcYrfXpHsv6VnvaF4/00T9CtkRS7VAdsc144mS36OOR1dKSy72SH09/GpBevRlpskY/Mwj7nRxuxDilLlAVDaQpCr8RZHkwz1hDh5jfn1jrCN//F70o/cuq63sLVepIzF+1+uraakSWFsHv9H6X3xtY5h54CWxXWCGmOjSCLFwbOzzPWe1SQHfhToi0+wLHfOb5RxeSvUkTwqGDEe6ZIKYEDVQ3z1lmQWBjXkLD58foCllPZ3R/OEYkj6wV5vyR3k+379O+fGeZxNzGBrs44nRDN6Nd+qQ== 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 | 34 ++++++++++++++++---------- 3 files changed, 26 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..20699993e4f8 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,25 @@ 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->seeks = DEFAULT_SEEKS; + 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 +240,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 Thu Aug 24 03:42: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: 13363455 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 CB88DC3DA6F for ; Thu, 24 Aug 2023 03:47:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 73402280096; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BCC88E0011; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53713280096; Wed, 23 Aug 2023 23:47:06 -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 3D6548E0011 for ; Wed, 23 Aug 2023 23:47:06 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 1CEA91C9064 for ; Thu, 24 Aug 2023 03:47:06 +0000 (UTC) X-FDA: 81157612452.09.2FD9FC8 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) by imf24.hostedemail.com (Postfix) with ESMTP id 5630F180012 for ; Thu, 24 Aug 2023 03:47:04 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LJZYEmbS; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.53 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=1692848824; a=rsa-sha256; cv=none; b=yp9aNoyEAfKTtH+SuVx5ShMI73p/6/rutr6/+PCD10/KxOiHdx6U6eiRTLeN1wYuj0xIM7 c/qKUbozC9wdnbviI9mI9MXRVn1QaAix8/4bgw5V40u/5QGLMkGgxpGLztPyob/K8dN59g Wq/mvH9LwuffC73cY8DsAkyufa65LnM= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=LJZYEmbS; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.53 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=1692848824; 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=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=C34/J9mfQV3vdC+9j+PqGI+jP4Qu6NdFI4NFaJGyvWeqQmHtK8QYIUqlXC/4WMHbD5WXfy xhRFSPK1Myj6pKc2bJqK8mxVnUCkJcXfdpBod8WatSNUxpPCXHl9qrlCIeamEfBs2XHzgb 9F0iF9ow95grQnx/ob5iG3mVqPBp/V8= Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-1c134602a55so1134285fac.1 for ; Wed, 23 Aug 2023 20:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848823; x=1693453623; 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=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=LJZYEmbSlDASLCkgz3hrEPH3dcI0rjqxRg5VcsDNmoqL0ZXgf1o1Y0h/XgghMDeH/K HNX4yAoxBp9QNokVvRY5nZw0cXdicizMAkH4jh7h0xLuD7ZTgWgj+TBan6hPOXN7Z6TU hktNUzMuauvT8xDdnVT3ksoiQbTyrLpmA4jYKOLqpQSWkN7+e8l+DAsYGtPGUoX88dMa MhAVrmwr61P7V2VVrv3ap/Xuz77qa49/YegrwTqoRUio1edOetxqGxTMb//9/u6Zu5JA fSsi178BoJRqOiBvb1O12Z7bFpYPDTJqk3QV2EuyDZ9LfRM9vXhUXI0bl2tIzM0ow6yb EmuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848823; x=1693453623; 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=YdtMxNmz/cn41h0wkDab4HUSCBdbEij6eu1+GgqexQY=; b=glxJ4BNr2wPd0F+9WSX/YKtoYI4Vsji7Kb65qdqY5IN8KfjauCn1F3HOQ/mdv6ji6v TQLk9BiA8iS/FwBOA/ttLiQ1za56BK5i/G7fXbK1D5Fb7a15p/VCFTHg45yfTxzxOvRN sv1xlCmBRa0BXkI926ww3kbDjJgnB6c2RDJ7LdMjYuPfMmYV21prZd7JPgimhaqmGfRe 94Ukt4guINCc2Pba/KncooqPMTfugKKMPop8F+SUDzNuGtZxMbDXLK57Qd4VyMTfJypl lBvWqz9X5g1v3CaORQ40IUxwGDAT9oapRXrtKsim6qfMIKCB0rX9+5763mU15JYUtQuI Wm0g== X-Gm-Message-State: AOJu0YyfRTtguLY2Kk9owqnMXZckx9eDwPEFSu+fpd/ruESORjYjsk6r QdWLUuRGIVhpqO2NR/mZA42m2Q== X-Google-Smtp-Source: AGHT+IGdyhShqM39wj/kCYItFqjS8mjsUh5O2g0IqPZkGOxiCTY+W38pTQGVR8rjRvn0DxKx8gxMAA== X-Received: by 2002:a05:6830:6782:b0:6bd:990:1a2 with SMTP id cs2-20020a056830678200b006bd099001a2mr16253906otb.0.1692848823235; Wed, 23 Aug 2023 20:47:03 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47: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 , Daniel Vetter , Rob Herring , Tomeu Vizoso , Alyssa Rosenzweig , David Airlie , dri-devel@lists.freedesktop.org Subject: [PATCH v5 22/45] drm/panfrost: dynamically allocate the drm-panfrost shrinker Date: Thu, 24 Aug 2023 11:42:41 +0800 Message-Id: <20230824034304.37411-23-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 5630F180012 X-Stat-Signature: 9wjxz54ky7jju4zx7ycifawkn38dye16 X-Rspam-User: X-HE-Tag: 1692848824-521350 X-HE-Meta: U2FsdGVkX18fuJVQKyHkUOuXvWWhWfRcNRjqefgdZIihUIVuAPhKfH8XaJlP6JNRiubYwz+Vtk9mmGuu+6kxx4Dq08MQFb6QKSyZIiUGUOIVPtB+5qUbJEgOilWedpTbEAzvw8yvM4FAF4Z6zlph59DI7ADWffSclt1+p4+GpuwXgZuI0Ny6jpRcDX7eUo6HzY+PMqObFl06ShC7eDg1cCwABnhCjzaoAG+IgVgZHGN0hqC54VylGSmn6Q8ScmdDfrkoCPgwiiP6FO78aYJ0zvsjA18+3xv6bv/nCGJLLHpxwOduIdfWfNYw70QlGwWbrXUIUJ+zKo45sikICCQ3JJrHM9Uhkv5+Bmt1AHD3BzS+ghodtbVLMtLldmZeThqL5uF9yJ32M46XZvTkTNnQJiNhrhpE6Ubqc9csQLJvvEZyM0O1FxQrt0c6JAExJ3PkePTdYHOjsX3oCpLUhyVxCq/K4d7cvNBWDHnmGQCBvhkRE4pqKAT75+b1VkeQvXPdob2jvktcOVAmLwJC1NzPyiR3VoShp5rgRE3IbnvGKOOlJ3R9pzo/vu/JUJgZg5cNvmPSktVwh36hzF36RCX91KNozNmsjQWbzgO1obzWqzvdLYWHTNgMxc6qha50gEfovwo/HqPntIgpg2TFluaEh28SuxznPQ7PPnPdC5xCBCLQlkCWa0KxUd3OOs1GvGwFdIzGw1hUHzeW6q3azlJvl0YoMWrZM/usl8a3U6ndvlEbv/yGS+D0V6JPsvEyj2ZbHw8m22Mx845rHUuC2/dENu0bauylcyEI7JpwpLvBOJe+3kCutu9Qar3InVp77VwvfuAdS3ApWyo/mOQi9SS/ROVU9AP4Z6vtzKVOrsmSWNAvYKJ28GwhJx6mIZt4ZfhJAGXS/5rprPl9G8BgVahhnTUe2VJY1/skqQfqLaWPaOL6pOVB/mY6PbZcJiNaJNcylBTXX45a0BOM93gMOOu bM4fPn/W 2oH6O2NcsmyE5nBkJidJ/AwLHvkGe0MhuBgXLVslt1AvA+9mG2U/Y+xgUx4gzs1ORW846img75usXtw4+IutLJLJHvNIfVBgWClh+w+mvUWjBtrpsvw04ridnjOAWXsmQnNeo8utdiIYHERRhuMmDAZCcVglU7p5VibLSIGl7/ve8XF1FeFeyUV5CJ0wjRTkO3GTkVfHQ7lFxx3JV+cnM0y4zNf7hFgza6qDGZlv8Fuv6K7GgJzkZq21QXMvZivgtojwHgnxykmAlmqiEZrWOY1ql/WOcmzYG4++63XkipBvOxiwejKFDWDD+8dwXBx7X4bErWEAJ7O14aNAcAghXP/iAXcfL3tf/+lSqj09u/ym3NuXUsXFfNcWTnAIvkZOfxGm+xUnafvpL5Nm8JA5qC2hvmAhGOqJvbQWbqMmNnyJbmIye3gZC8/SN4l2gtI7sGB9JpYy25sooDvUN5XeCFLoK/kw/Dq5MEqptU/l56UPuYbfcjlWrHPGUdMnmMNRtGTElY0MvWmf3H5xEKLi0sZXGBrMyEh0CEGGtau3WgfCkPgnouP5dZXKBLQMCbKgoVCkT4tOjAyNBQ35bibylReumaEb2xB0nKiXwo+LkpHD4+xMndBD9DgETk/v0D0QXWnrk9/J4mDoSPuZf3NH4miYwGrDtBZreeNvtMIa+OKHdxNc= 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 | 30 +++++++++++-------- 4 files changed, 25 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..3dfe2b7ccdd9 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,22 @@ 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->seeks = DEFAULT_SEEKS; + pfdev->shrinker->private_data = pfdev; + + shrinker_register(pfdev->shrinker); + + return 0; } /** @@ -116,7 +123,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 Thu Aug 24 03:42: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: 13363456 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 7D462C71145 for ; Thu, 24 Aug 2023 03:47:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22AEC28009C; Wed, 23 Aug 2023 23:47:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B4938E0011; Wed, 23 Aug 2023 23:47:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02FBC28009C; Wed, 23 Aug 2023 23:47:14 -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 E19DB8E0011 for ; Wed, 23 Aug 2023 23:47:14 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BF151160143 for ; Thu, 24 Aug 2023 03:47:14 +0000 (UTC) X-FDA: 81157612788.06.BA1F7B6 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf29.hostedemail.com (Postfix) with ESMTP id 01C81120017 for ; Thu, 24 Aug 2023 03:47:12 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=l3iIlNkE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848833; 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=nzqPXZUzHtAKFX48cqH8HxdHr65DlphUZVtux1vY61nXKAnnTk6CYDdruXFzNeZqRZW9Fd SNSWTILR3ZiGyKnWJMlOl7AbaInR6SB7mcc87qXukFPf5efraLr6kzdgkpCOZnlM6w7oXt bAwxRJHB9UJXKZ8c6baGFJ+KhO9ORr4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=l3iIlNkE; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848833; a=rsa-sha256; cv=none; b=2XO+/uevDvM+rghDXDo4R1P5kcJfMKe5cXyh3+b0tTQ6X9lmaz87SDvBXcN8VZAPENty7h /NUdjw0uq5nxQfK1f/1SjMDGBIo8fAZeSJ66qp/6IdfJsO0jCEjEwzADJo2MlgBMcmjKYv kmyRwzPrjdXDTia+k3hep/Uto+cEFMQ= Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062586b3a.1 for ; Wed, 23 Aug 2023 20:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848831; x=1693453631; 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=l3iIlNkEM9G3Cc/znNYH0hjfEGMFScoGFsPDxRlIYD6Nl4f8r8Y4ffur08X22M57wD rIlSmJrfx+3UpxggfbKcjCE4Dvgc5I/LQBD+OIaafLzWd7xdzc3eeSUn3jYMqVJn93em 0W1GznsolsuflbV+uszoAiXaDHnfJ+tiKXIpWvpYd/Ij4f6UXGCJcJb4Hscr3UTl0p3b LW0D56skk4nR8+fdc5jfeMFs4SDrmcbSIrL0BJ5k/5kJZyOenUt/nJGwsdGpkJqafAVm Vnc6/t5P1QbupbAmEIByI7s5m2r7bE1g7Fg9vHnXnyXTIzG01/FAXBjLAVWjh1RgylMp uG3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848831; x=1693453631; 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=If6Ps8fmYvKmQeBEQVAnkt7Twm61shE3A5iLt4KvmUwUqMcyaZzjO9UyQ0wfIIz7Ep oPQ4VK8w5TECaUcRRkLpQy78+oWats5aNSamOaDTfrpB6yBFENJ08W/0qsmXmyEW59Ya OHU7q2k1O7/vK98/Xiqx+/nHMnGOAXm1I7PEFnjpUa5KMfcG9lgjbuLV3wJLCZVZbKbx ihnWchNFKxdkDjWAXaq1VcKoa5aGQchEsU6ot7/1fwOH17QY1SvQJIDKjbfw9+CB+9Lp zS0Jk8fqzoQJf6wrBRxo+F4HSPNONFS4fFMzmYjeEPePfYNhS4FW/QfQKlHF+G91vYAa ZEUQ== X-Gm-Message-State: AOJu0Yy+k6iAYhRPVzucv4wfXVozkedYmWoD4tQ4+ogInvZLscZzdwjN jSqKLkflRbrhNJ+Ym61z24+8dA== X-Google-Smtp-Source: AGHT+IFa4D13lTfF9qI4lzhNEmw+/ylikA2tFRh1ZHmSW0TIoxErglnaTpv3xvyiYGMU4coQffhatQ== X-Received: by 2002:a05:6a00:3107:b0:68a:4bf9:3b21 with SMTP id bi7-20020a056a00310700b0068a4bf93b21mr11172345pfb.0.1692848831711; Wed, 23 Aug 2023 20:47:11 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47: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 , Muchun Song , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH v5 23/45] dm: dynamically allocate the dm-bufio shrinker Date: Thu, 24 Aug 2023 11:42:42 +0800 Message-Id: <20230824034304.37411-24-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 01C81120017 X-Stat-Signature: ut5rszpoj1jxt7567a8gmbaetjchu4ww X-HE-Tag: 1692848832-499594 X-HE-Meta: U2FsdGVkX19YdnBGLr4ApegRvkTeGiM7zV37QXq5D9PWPyzkaSzSOn4Qp5g4Gq6DlBZXqgqSLi/cMCvV0xCe9+ay1Ebste3mL6AwRyoJPWVhmMDQ4+M1p/xog9YNi84tVlv7eMVtTRnFW/tBl29jzauX/TjAo3pkf16FgV6lP/twTVRaup2TA25AlT2RNJ3rUAL97lnhdWlqi6BdyGWkMCAxDVuikxf7QK3SuR/PlNdhQ0CBAUE8ajoaNfMRK7g1ncj6dtmEbMyBn/33Xh71w1daNtS7ijGJ9k4XZqYQ/r8IQvV8oOCKHQQ0X5Gbc110cPbC5z28aLLHMEI6OiOiU+heBoFI3PTlGpPbqV3ZWmfVV22e5gjtgM7FZNTUQCJ7Lh+NqqLNW4ragBv1IaZYYfENqvQMGQ+wEsS3JE+1E3YEg5I7y1LhbzLUJqTgKK5WYRD/D03urpH6Q27lB9jjd1het/KaJdyykQszy9W5QRvYYs88MIbc0Y92oLQwaNUyDQCQiJLhhB9A6e8taLk9PbPFzAj2AuwQM7DbC3jDlJl7wZ8ViwLpcJEfNDaeG+BGvoacYKTeJPmoRELEX5i8rCdkMs2ZM3GgVz3ALKFByvkG5f8VHShwSRc8017XhSack2P4lDATEnE1NGc7MOmhaXNb+JVZe193D78yZ54Kvwzm5hU2YPylXXUY8vxpzsV6kKKauUCn7e5r18Em40ZH0HH9Cz+aj3HZEnwdJrDjJwtGEsUz/+Wi1i04Fd02a0MoIDf/06QpWqR98LQUr8jF2hK7RNUtMZHDQe40kICnCEyN2JFrSuTu+zeUNEZhNczXFJ1iqlN6VJJ2qf9ealpbtla3kkbtI0JZk/9GhNp8nM+csGYTUW88BMNFkMich9WpG8oHxBNEShPSNOjo7sm4T3/e3EmOxYekkRUyMxsWdf7qTdAjRtpu7Z9Xk1hrCS+BBn8VvrJt9BQBSb0Uq6O kevvbIAQ jnMdvq+N+23l/S4mMsMSfAVu3htd7N/vEjTGDRc4qHGpGMtKe3JODTBbkT6Vi+MnQuXj7ltK1nEMlJwxFTb/ZokytybXXbAghuKPoT7dIcAw+V5ccudz1DV2mlQjQcE/7CVDizQQndBLau8A/v35Oe1+1ewLkc9zKx9yYRBm/g6LWdIPadyMXCrMGdUJPfE0mkmMtZUyxGw08iYuu3kBEY8DGXBkBE5hip+EM5DzNd9lO3lev+f0/kiVQ1KfJVSD9zsFs9Sm/H7OiQ+BlbGB3IU26y9p0lHs4SndFqvUUMf4r5I1qvkXlT1OaqXzWr7yXEQAyiXFFP82TP4qO+1fjMSBcDdfb+Peef911HaoFqfnwt5RdTXOxnv07lJHdnDEJwPMQnKAaarmmOP54CiGa/MfDVoxx85LvKu3acxwYBfF0uSqIbx56LzvvglxDKb3TorzlAwVccofH3YNDUwHKgn9XitRGBnyBZ51ElPTeXdl0tkOZe8C9DoXfcA== 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 Thu Aug 24 03:42: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: 13363457 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 37684C71145 for ; Thu, 24 Aug 2023 03:47:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D00B928009D; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C89FC8E0011; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDDF28009D; Wed, 23 Aug 2023 23:47: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 971F48E0011 for ; Wed, 23 Aug 2023 23:47:24 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 668B51401AE for ; Thu, 24 Aug 2023 03:47:24 +0000 (UTC) X-FDA: 81157613208.01.250D991 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf09.hostedemail.com (Postfix) with ESMTP id 773DF140006 for ; Thu, 24 Aug 2023 03:47:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bbA3Zsc7; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848841; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=KMJ22gDWeeMQKG8EQ6qNMr+3CmYy19SMr+K5lYxekHnFkXrpHd8w80DwBgV/4TZR/cHXpC 3b+1xSXHBMeBTqh3grNNcbJf6saJ9/U53btLT531h+Xo0LK7UgPbTFcqRf2NwAPpjrAEOa 6AQ8vPPyk1BK8JMwixZ7tOt1irprCj0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848841; a=rsa-sha256; cv=none; b=iXvcMxgRRPqqKzD3n/0utaPt3bxoU8ns/z53VD2FMPyjyNHPF8u49jxL+sCxK+rcUV/VP+ eQdWFUkI7VNILqAD729l+FPmNXs6G96Fp0PHEF0SL0zop2MyigJdMODNh4Ecojdoxx4Xsz hdAgZYpg8Ruh20DCtPLH3kWsMsTUvxs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=bbA3Zsc7; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3a751bd3372so714426b6e.0 for ; Wed, 23 Aug 2023 20:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848840; x=1693453640; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=bbA3Zsc7IUD2am3ZTycHTYFrd1TQOR2glffiwOM82rWGJwmsEaewPHgueylM3TI4X4 0fy4O6kMrGiUtL6xCEMYVrA+5o0Hn4Kl2D80XUo6h+baumFzOxU3hlmu5grhjO+IbPzm 0Uz4Dp92EA1hhQawccSf0cOE3hJY+x9I9BT2m0Ds2y/4AnFG96IDKy5xezBiRKN7Ab6Q PgHyunTCKsFw+M5x4A8AQoFknpJ2TzQZwk+4YGLx+7riuxwrefcMbTmVYfJj2kzThdO+ gDjVOwdTnyJz+D7/eOkQqtXKM2jWS7D+5yPSU6HoCPAEzbJ75/odbhA8G4sUffTeNM2E kT3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848840; x=1693453640; 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=1TonPN3sOzzr59sXAa9zxRsvaBjeGBq6wcTvb6FyTRQ=; b=BPeBXcnuHCp8tv1xvHFUEO7aOj4xaKb/SC5J/PR8zTMjFAg3ATWHolJHw5vrkWX/5k K1YtV+Ximmcht+292tPMJrv3I/6Ed1hzAx/HxW7kjIgelkANCj73DJj9rGTL8vXzxcqy HxTrS8ZVZ+4Z8Qq/fJohkhrdIoAv0De3eRBr9r3p2KiG4wJzFOt00JY3yt5A9sMZL7VC h7p7BfpjxrG+zr3WPebg1QyV/wJEEZizraT02uG8qkEvDy9q0VMi6wyFpMIYrfrrzFUh tJOxfLbGhfOy8T45zTJ0/PjCjgN7ZhdkptVTlVLp98qz89LtlHUkqAG7wwAWqO+TnwgK 6wdw== X-Gm-Message-State: AOJu0Yzo5MGSvZZ87XDYcHOoB899BuBGZvsMlO9zIFGO5YmFufCZH+yK t84eNZ2tKwBtflpfT+gWiJbbPQ== X-Google-Smtp-Source: AGHT+IE6mZg6R/C4hkqYLeG6aoFn5MZe1GYXgvIXJGbCBTW0CHE8uReLaaEVve/T8KY77idOwBUD4A== X-Received: by 2002:a05:6808:448d:b0:3a7:56a6:bd2b with SMTP id eq13-20020a056808448d00b003a756a6bd2bmr15345498oib.4.1692848840631; Wed, 23 Aug 2023 20:47:20 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47: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 , Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com Subject: [PATCH v5 24/45] dm zoned: dynamically allocate the dm-zoned-meta shrinker Date: Thu, 24 Aug 2023 11:42:43 +0800 Message-Id: <20230824034304.37411-25-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 773DF140006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 7x44bxcd441rg535dqqy9inar6x6mqbw X-HE-Tag: 1692848841-517499 X-HE-Meta: U2FsdGVkX1+sZ2d4mS6qYlA7Izc1dAZyo5iV0Jy5S6i/ebdBElzOLPlOMKDrWkj2vK6rJ1EPRzNwCrD94Bpsu4SHEQ4LSyGeimbx2oViUuZ8tDPBNNP4so4UmGLdLgzn73gEeAx589qNo+cXSpEi4VqLYZJXY2HixcTbfqdNXmE0GUodxD5kASPt5x62r71vu1l+I/i5+aI+gv9Uz/z2zeGdAyu09NY8w9SCn/QONyv/DOgfpaRKkS2NBr7OTPRQ/CM5w9ImwwxwtCI6DI4xCj60kQAVA+XGfgsFlSPrnbGWSVvIqa45XOhgQx6shBaaWcTVmjIrDyDQ6KYA30cUn0Dj2OwZj9/eJFDzm7YWmuKbGnwKhZuPQVuY8Vkgu06SSzygERt9vUJIuRA7D4/FVYWrQLejMKidbVFPOnYFF1qe+YU8QYU6L06J3GOwBEEquU75L5oLgp9EzXQVlW7c3gZLvEf3dt6dRB48aQR/XSESdq3Zo33/158zIGgGGonMLG9MP54Ut7TJ+NW/AFiDHUNCeWlp43JQViRgQJu6R2/JmmMbQDULrvTDcOK95/+D7aEPgpgJX4ApkposptqFRyhqd9LiDP7iGvY9mmWOxT4pHgKVTujOGJc/FZ5l0p0Vnz3w5Hn786kx8nblh7n+cFjibfsgntbD+zfZcFR3imZmSVKK11Q/XDgDrggg3pkX1x6bXQ2MbsU00TCCb5ROGHzkKifeHOsGg/CMR2fBGT62wR4upazlQpZT3t1ob5HCcVmtxctmXj9c7+fugKJ2smAPEh7lQwvILJGiTHS/qDkTPY1FWIk1ioNDwzF3WpgZjWyGgLQ4ouX+QESGuPIUYOJqK9/2X+CllsVBUFuEbMNcBvr/t2L04gYjA+QCILWmIkJELCpSzFdAggnmJgxSWjTI4/e9mn0Glt1k4Ah3oiwOXUgkr4imeAPzjsFvGUR8wfUm5aPMLQSUTxF9FpT XkU6RVW2 ezhet1gGHSOS/eX6RixJUqeH8ra78GvcDvHFZGyXTVlMv0L2k2eeRGYYaKxQmcgotWzxHVkMscR6+9oAP69oSTDSSz1Thbnl/Ee9PwKUevGSvDPGBWGnqzI2v3aOHNGsF+rdpBasVZfHuMZbiN12a8GRDUM/Ue5BE9m5fncExGsd69OnhcgD/EJGA/Sys1ifzp2hoDLE+Pxj9LrOyqLWorDEyK3IwhM0PUr/U/Z2g6r//lUjXqEDzJ7so89FxkiV0d6vUdneDB7HcK0YPi4sWPkFfpLObH4Vie/I8Oge3UXrbxLN9V9n6jZ35mpVGE6V77yXoEe+G7iunpYJqH5MrGt+RBqzrUOP2JzvJMT8VjkOyBkCdaSfUMU97e78TmBKxAv+7qb2XYly4vhnntejXcJjDSXqVHtjxjLPiTEWpT0RRYWmrr0mcSbLYl6iYNSDAG0X9ar4BcOl9We5RHi5fakaQfxAvcGz2H8fNZRUWkNJCikUir312F+mQoA== 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 | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c index 9d3cca8e3dc9..bbb0e69a7908 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,24 @@ 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->seeks = DEFAULT_SEEKS; + 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 +3000,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 Thu Aug 24 03:42: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: 13363488 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 647FBC3DA6F for ; Thu, 24 Aug 2023 03:47:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0563528009E; Wed, 23 Aug 2023 23:47:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F21F78E0011; Wed, 23 Aug 2023 23:47:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC30E28009E; Wed, 23 Aug 2023 23:47:32 -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 C81558E0011 for ; Wed, 23 Aug 2023 23:47:32 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A0152B1A31 for ; Thu, 24 Aug 2023 03:47:32 +0000 (UTC) X-FDA: 81157613544.04.D0F6339 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf30.hostedemail.com (Postfix) with ESMTP id DFC2E8000C for ; Thu, 24 Aug 2023 03:47:30 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DVQw6x+w; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848850; 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=rDzcwqaIquIVzn8OsvZGliHXRbA8ENN1qRnYnmk/Xe8=; b=AabZHGcFpw2tWr9fBSsYQ+6A4od3Moa9mb9U0xv9bGiS7/y11qgmDgx790BI/s/68ooMXp OC5suucPxaA4uV1xg2UmOcADnY2y9VAw5OY+MDhshXvYLLvm3nV4kQT6OsBpnx4Z/EH9da N/TSazHiq5pQzKiA4p1aP4EwRkWrsBk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=DVQw6x+w; spf=pass (imf30.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.170 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=1692848850; a=rsa-sha256; cv=none; b=sNgE3ZxzmOl9orocGHq1JGplJ+ECTl5OHh950H17RT2a8tRW3D7El+6JW/QFDJ4rE4/VXn 9S82Fj1EnS860eKWP1sQrmmxCkXLLDYyp9WP7/MytoDPv5xjJvS93qJ8Kf05UeH31UJnh3 oTaVKuJaKOocqcZTG6vwfpLe0a/Rli4= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062653b3a.1 for ; Wed, 23 Aug 2023 20:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848850; x=1693453650; 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=rDzcwqaIquIVzn8OsvZGliHXRbA8ENN1qRnYnmk/Xe8=; b=DVQw6x+wRokChvzx3mB2d4JjmEZ8a52hJE0l07W8P8nNrlDhrotmyt3pUv3GQHPCXs 1BrfBypCNsEERgBF0IuI0x1Xr96Fhh2+gAJZZ0EK/1xIsaeYYxT6/EN1k9efrylQkcM1 zJ6XM0kKzaSamlFOt/zlkCHRnLHEfp7PkHOGXd5kLYVg7nejR+dkAMm4O/6awNT3a3Qc xgwMhP+Jmrs8A3VyzQgEal/ZVI5LfCXDTSkiUmeyykfwpxK0jmaWMGlHcl5rKNUdpgen WbYpfAOHKT2MQ9cGHKqu8Hq5a4pOBrfkWUy88QExaDxN1iywSQ8vpGlmHWNB0IOXICaV VZBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848850; x=1693453650; 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=rDzcwqaIquIVzn8OsvZGliHXRbA8ENN1qRnYnmk/Xe8=; b=dtYBnq++bylsCfubDVVXFAFl80aI6QBSjdWYNdnLEqzsjmjAPZ9PXXgQ6Za5CuTXja y2Dm3jq4ykeaoLzrUO/U16KaRozA0lCNr2fZNx/E3KRU2Cfx+VDCFWEk0Vp/NXt2PgP2 piYSb6ks+wKX+A6gAs3vXdz9jKJ7z7tnXDtbyq+xad448elX3SVfrxzrLgk8Frg0Rk0a uMP27lJR63fLJji4rvB+zZsBDGHekTXs2QAU7cmHGgr6Cmh+dn76YLcBUknxrX7cq/1F PP1lFsCQbeN4f3jfZq3e+J6ynuvCTGmgFcsGfq/F98iXXbpiWWxRSTSCKg57XgVpr3Fe IFZA== X-Gm-Message-State: AOJu0YxnJtl0LsUmccFuma0ZZJq8JpUoEas3qVrPR7EIt325ZvvjHS9Y LYFqM96eByd0ZqGotESfCNHJww== X-Google-Smtp-Source: AGHT+IHnOiXJrClBMOyGTENJi9JIt4dG4SRfFKrPyHzsQUg0+5rqtXlfzEqyCDyUa5PDhlr05atJeA== X-Received: by 2002:a05:6a00:1791:b0:68a:42d0:6b9b with SMTP id s17-20020a056a00179100b0068a42d06b9bmr11893102pfg.3.1692848849886; Wed, 23 Aug 2023 20:47:29 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47: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 , Song Liu , linux-raid@vger.kernel.org Subject: [PATCH v5 25/45] md/raid5: dynamically allocate the md-raid5 shrinker Date: Thu, 24 Aug 2023 11:42:44 +0800 Message-Id: <20230824034304.37411-26-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DFC2E8000C X-Rspam-User: X-Stat-Signature: ccj36d8sa6subfg5ho4uzx1a5jj6xqn5 X-Rspamd-Server: rspam01 X-HE-Tag: 1692848850-716992 X-HE-Meta: U2FsdGVkX1+OGJT2tDhsBeFNDbE6uZz1dmBoFShERF/coDfkna/DpG+yes1SbF8yxAB0hN6406nclTkmUIkmUBFdZH2FAk4D8SFZutmM9aG27G4I84ShR3AdYajNSYvVvxW72VjvUP3C/LYxrAJSHlii5mTy3RQzG1mfofoVvA0WbM1uLhk5dXi+D88h47d8XINqx/8e3DEzE8j3jpQaHfumsYJe/Tly3rC87G+cE5CvREy0wSplFiuYrWrQohAaiMjJlf64HxF+SrCecZiHxf7qtIAqn2YJa3GcZ1TllMqg4F2mHtrcXsin7vS744A4rB+PjVqiRewtNrVTpY+nsGZEzP+lPoamxdbnuJFG0aj7Xpu0Q+9voYpVBknDBs7fB8BkD/vHnNPyHHNZ9Y7bDIrhAAqBcBBc1xe/aWg5Ha0wMUpZ4zrPrff8qat7Qi6V+Hz130knrPmrSrNmQMpu/+MAg/FYANcWxFnkYdPl1LuXaN6DFI/6xUCywTTeVJg3armxoMLMCxnz5BYHH9fuMYbS/PLQBn70N7sAU9gglDgAS/H7pYZ2OdlNtsEYlh7ySbnQMoDZsGfBumcGiN6iW+7MY3EiBR/mok7/4fOTcssWp1JLmb5/7zWcoebr23kmMCZ1TcCFEyChrlrY5hs69GkAHHJIaOFfD6wGrVaawQZKHPZMPTyD7MYaNseR5yWs/+VmXpiMkoD3AhDO3cBu1P3RgfCsEzxv8i7lb+ee15WKwMU7Y0AIfvawBUesYLPk5r62AEN9Qml6gR0dCVZP8x3MIhfy/APucsIoWFxREZg/NCjgjO4vHRhbZK+TfkWaDpEAIJl1POeNpB4ZLANAbneHwurTbsC/tOpGFM3IkgThy7X1wTUcX6V1CnajQgQkuPxtwcm0afIcQeG0zitXxAz9Ik81K3RO7CKqpG4c4WtPsQusd16KXlgD3mNyMh51o+qytmUhylivKkWfuoR 8ge9e7gq 8kzrFqMwcNiGKtbzUIY6SSMfy88f6cHmRTf2wHVBmiU5nFk0YhvxFDJMeKcIBLuClFSSyIBGOo0nCR49ygKlIUt/4wyF9+dEghQsI9dDBCYpV4oo431UeS3/7pV3n5A6esACJqW5K+4tlOeBEsTbdbdIIKUTlmX2ZPTuGUj4iqbsQeOqydmPldoqwjJBlq+5lbve6Ivjbu+pCdc8ZPAM2RluM84Q4vuGmv1JdPkQLGjWR1tRkbqv5m7GtdFGZhK4vqwHi7nMw+h+EHiyaovPqBrfrHBnwfQUiiVLVQp/hvZ/N2I65hGF8UwfNJpFzA33l1ZkXYizmWWgoIN3mtrhm+vYrgvbe/pnD0YMn+CuYF+LeGtDWwZ6q4+94TpVUwQmM+5HvJZEE/ghfpEc3IWEb1pBQ3OI+tjrBazaGplgG/X9BOodvgCPvPUcTA9pshfEGQkWiJwhn8dKze36a5K2wypywi5U9q/4Ya/VP 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 CC: Song Liu CC: linux-raid@vger.kernel.org Reviewed-by: Song Liu --- 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 Thu Aug 24 03:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363489 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 70D65EE49A5 for ; Thu, 24 Aug 2023 03:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0CC9328009F; Wed, 23 Aug 2023 23:47:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07C8E8E0011; Wed, 23 Aug 2023 23:47:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E38BB28009F; Wed, 23 Aug 2023 23:47:41 -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 D01288E0011 for ; Wed, 23 Aug 2023 23:47:41 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A8532B1A61 for ; Thu, 24 Aug 2023 03:47:41 +0000 (UTC) X-FDA: 81157613922.05.C992512 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf16.hostedemail.com (Postfix) with ESMTP id ED603180006 for ; Thu, 24 Aug 2023 03:47:39 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=d1wXSjPK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.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=1692848860; 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=IsplaiSSeDczrhlrenoRoRIELsMmpsAyNvhB7wc/FQuNJt+YeT9uM8QyCY8SsBCo3hHEBC qRSgvSLMbBOWJZsb7Z3/wo2U7JmVLVyGXbTfblFXr+TwkEsVqOQ5ztdo3JaWoszObUfvPk 9AUDczM1N7XQhJd9nMWxq7MvFvKANSk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=d1wXSjPK; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848860; a=rsa-sha256; cv=none; b=eYy9B7VvB+ay6HhOkmc9Qcm/aD3x/Nr36q+UaTovsEpeDos0qAvZjkFsqig7JgsLbFaL4h UBQN7cNOnVIBEz9eAkjjjAXS9PY2dl6WJMeUB8y0Juu3chRV62rDpS7VoLoPkEnlqGiTqk 8j+VnsU26PSS//bVRKGg3U0P5j1f/9Y= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5657ca46a56so833103a12.0 for ; Wed, 23 Aug 2023 20:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848859; x=1693453659; 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=d1wXSjPKCFEr8z/p/byM5kRgXe8PbCA56N3zhbP1G8RyclSiP3MfoWO1VjUBFEfLu8 Jv8srfHUD4wK1EF90VWGYzVLQFM3cgUH6eOrKYXPD/cVeTsc5WoF/vQIJUe26UY/Ow3z ENqa6anDehpg55dE40ykBpXSJ3cGdh/QxK3Pyn1kpms/fmsU04YXRAopjkNGU4+76Pq8 3Y9zyUnnRNr/yzJsGa3A3VHXMPXaHq1XkZzHyi87cd+Y6LY4TdHFbhSuzevUvRulOVyP sd5aajfZ70TnWEP93V/mOvFrzj1icTTQnnd4xRKj7zmyKuiZMzeQiMH8vplG2YqtFRs+ 1NdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848859; x=1693453659; 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=ULJTTz+brSZ4LGWzTdgqi266ciIW5pcn7IpQP65kx17iB+kROfRA/Sn/zaLXds8Gaj R3urU93X+qFdQQFdIKJo7+5gdipFP9gjbPmfD/Hnmb8+P1B9xh+o7N4ve6R3hbcQtFZY QsQqjA2c3zTfrqZ31yt0sSM1+zxiCblmXNBu6QcV3IonCeJTct6QV9PRfQ6GAyb5Qbjz YR6FHHmdtZOHcC3kXWbg0J8qVlb81rtn8xlbz9yptf6T8sIhESlSsTt+rb6VpNnjucn0 2klVfez5RgcpMoHZkIOY7wS+EP9HtpjhcQ5vV6KbeQK1L3HMCbv7pIG1gcafFBgtfwAX 6WjQ== X-Gm-Message-State: AOJu0YyMfWl1161jmntwzqOeJZkYmBKXGqgtMJTTZ1zVxSS84By9oxgn WlDc/fG3PFsDgtjSqgHtHCeJ3w== X-Google-Smtp-Source: AGHT+IF3djZSCs4jg/UQUu42D+/WSQ6VNsO0pvWsZu5aji18gl8AMoEFfV4hmz2xAgIkNtsfI3eNSg== X-Received: by 2002:a05:6a20:3941:b0:111:a0e5:d2b7 with SMTP id r1-20020a056a20394100b00111a0e5d2b7mr16582686pzg.4.1692848858975; Wed, 23 Aug 2023 20:47:38 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20: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 , Coly Li , Kent Overstreet , linux-bcache@vger.kernel.org Subject: [PATCH v5 26/45] bcache: dynamically allocate the md-bcache shrinker Date: Thu, 24 Aug 2023 11:42:45 +0800 Message-Id: <20230824034304.37411-27-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: ED603180006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: n1p3kcnj6qjnioa5mjtjeu1r4xy7firg X-HE-Tag: 1692848859-633130 X-HE-Meta: U2FsdGVkX1+ffHp+7AQQn2azwEgs6q48HHFTsKkOcub0uax/W7sJNyaaWRMzgBO61698pgLNF27iKbRktaSy+pRWEQky1jaflw8g3gOpiOmeRDYTOiipdKzdaoe4+4SRgwNTy6kqgmmgYdAl0t97uE9U2pUu3/GJVhGFDut0ha7yeNPIuKvJvcVwecSRTpErXsgRFM61GJHvoDpZWR9JB57MMR5xcSEVKWTGTTh3LRX1RuzE/5Y1vZLR3bKfIHYktjYhLNJBvrDG7zymhh6Li13DmrgnXyLpRUuj+xKUaCRdxMq5KKnGCFDITlNYu66SnYpP1WfxAV+BUq/Tp25Gi6tz+zxWXEmRAH253bI1IsZQdD9tPUuOsC9P1q7OirRIYxPEs9Q9MvwKic1gtI5+4DzIukG2pQJOSLrdfaA4e2kCq4Zkg9E8r4emtMDWN2bVbALNge4ODmWv1ahwUHOOwI8d+1Qg/6ktZbFppqSS41KSnPkVFvwqRIH+hvqC7xGncu554S4d5V4YBgaLbzh4C9TszB8r0IuBIyNtNNppPosyN0yrxsaC742z6RzsIfSupRI2EKWMqsrBSbJz/LzWTvZ+tr+7/GtgrA1wTh5mdGEmz3b1FmE71p67wQ/DsEYVadkfE8wk/hplVfXwVGOAVWSlLycxgvRmduzlBjNwzo7YuFhczBzIXjCJxs/DtzsDEG9rqhWi+t5/5n6McGiQzzk0YBWXqapAMdlsWJo7IE7z2drOhyDExZl/+5thBwVx/pkGYCT83qf49iF4+IB1qqA8Lplr/Z24sq3Uu3WEXhSmhrh89JHQcN326B0DB3lUonIHL/16G8fDsTVpgEKj0P2sZ/k1IHjp6QPxV/3QEpPmk2CqBAANEDaoeLOezx3cyWeA5YBj9oJMCotJZlOgZAZWV4ocQMJe6l949krwL5hKi2K0yWSQwpzRlgkMMhoBiPX3hDk+FhgwuVgFtHp gdLbFUU1 EX3d8CngPuJw3ESSjHN/VrIFlHc2utMrujHmlmPQO1UyeMpOudB35O/s9f1C81BTwhZwSIy/EtdVCfU02we80ylLtTfnK0Hp8hqVkm9075lXGALEhJdSzAfFvid8tu8O7eOLdVXk3PyK4XuMdAU4WRvQiEfu70iEcEC7EczlytcpAhFey3vMRqUweMkXQufUBzPzGj+pu+1GAFWY8tjQ7uD3INpRSw34w/UEMMeaPdbiZMHbkaOubmvXMUsmc0oMFpfjxg/FPH8BUf5AxmN/OzkIyriqMeHoa/odv7nAxzx9BVUo06enZrWgvlJIFEm1il7yP3t7Xx5X1tfqrde4z1tUm/2y+PaJrzFVTY+1bnQmjbBeAlui9Uag8q7Q9xHoqrThF11KqIC5TgaZZHMmkVCNBKPjRyWnCLW3J1i0jYrwILsrLlTcgZh+pPHM/3HFR3tbJzZfgkzZ9XKu31/MwJZUP9LitNIsuqMie1qieiA2CQ+u6Hk9vqWVrPotA4lbaKQd8hLNln+JmH+b2tjYS4ToaJNVscWfZFJ1ljvIYZ7anSY38PCEw1u/N0wEs+e7+LoCA 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 --- 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 Thu Aug 24 03:42:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363490 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 E1B7FC71145 for ; Thu, 24 Aug 2023 03:47:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81F782800A0; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A8518E0011; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6221B2800A0; Wed, 23 Aug 2023 23:47:54 -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 4D8FC8E0011 for ; Wed, 23 Aug 2023 23:47:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2E0B9401B4 for ; Thu, 24 Aug 2023 03:47:54 +0000 (UTC) X-FDA: 81157614468.14.088841A Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by imf29.hostedemail.com (Postfix) with ESMTP id 6E5E6120016 for ; Thu, 24 Aug 2023 03:47:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kmtsq//6"; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.50 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=1692848870; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=tRyv8+xIMMB5/qH+n89ipvNN7wnL2cE6HNW33v1BuAiBQwnys+F9FZcw/WO/01uS8T6U8n GAaoF7+igjjP24ZTwhi7XjzgckG0D0JWxGCjdPozxDeYRDOAM4Q6rVvT5ZrIwqpvkv03+v hwjoJKmnslzTJYihHSolgXHJQaypVc4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="kmtsq//6"; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.50 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=1692848870; a=rsa-sha256; cv=none; b=t2FMMWEnO1HwCoodD3m7cQxeDNfKnMFbeunkvFNR/EpyOHEKGZ1UggPFdbRkA41cM7jgfZ NPS2IZrrrMapaSRb0UW4XsQ/pqY1+Knity1ckLxDKyvHd46PQNFQtna007l5dmkp+XIOjB pGg+Dev68Twg1/KwgDa+5p89ya+zIaw= Received: by mail-io1-f50.google.com with SMTP id ca18e2360f4ac-760dff4b701so60530839f.0 for ; Wed, 23 Aug 2023 20:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848869; x=1693453669; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=kmtsq//68LoSSVsyr/YBBGvDgqmBUsO880HB0D/X0A9lvPp+wiXhpBHLd0cfIsISJ1 WySRAQJbOB7MirqRDUr1lxDBiz4bG14CaKe7yuO/GO7cBBb0YcTM9Y2I3EbKN+nNzPLi GguYtSQnyC5GCZ96dWUb+BUtsgcR3JqmFJQHmDPKX024szPrXCnBPbbW9YCcGmCws6Ag O3VqAcSntA5bd88T594vNGXtnhYJdlTyYo/z8+mucyI7RsSPbvZ9Tlk5oJv0m0ggTdMc 0VdvEN/SRUhc+98mEttt+2USPb5pXEEKX1ITu4ac2rdVGkAruMTdyg9H0mmnNrZt4fBx MFQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848869; x=1693453669; 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=4g9VNwXC7u3b4Fe8S+2AtVie+S5coxV+WBg8Oh06A1E=; b=G5th1bFWF7h/OA29DcZXlaXpQ/Yk1tWpxNRBplP9y5GrKM1COV6BK0lZAlG1U0PmAG uIqqh2e+nSj1C6Qs+SRBdDpHHz/KUHmoYrixTi2SZP7ubrsXNPsHCn3hAJD7+95P2vIg 3HM+q2gQfEjzTrR1ZOLQHeQICDrkSRxJPoN0A0H9OGNnZuHHlCjb+9q9e5L5eFLjgqVG MsFCc1tXrew9259ExVESeQrH8FlF2UzUtV7Vp/gKo4IGKk0DL8UqtjtKt6gb+DZ6Q4L7 xynlpDQocJ7r0jojrVELggattJFAzMQTqrYUOooTIyihdfDcjK3h5GbDvgCjmfiKkLtF 5o0Q== X-Gm-Message-State: AOJu0YytpQndWNrvSc6oECnMbMILwzPOgY/VXt65JEpBCw/0xA786niL hexh+3sYXvXkK/XGoRy8qIYZPw== X-Google-Smtp-Source: AGHT+IEQ6BDL0ShOsvxn7MkRzNY4X27PtjN7dkB9TSd0YJiI2pZEQO2zVH6oQz1kCHFDDwRb6mYVFQ== X-Received: by 2002:a92:4b0d:0:b0:345:e438:7381 with SMTP id m13-20020a924b0d000000b00345e4387381mr14623814ilg.2.1692848869651; Wed, 23 Aug 2023 20:47:49 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:47:49 -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 v5 27/45] vmw_balloon: dynamically allocate the vmw-balloon shrinker Date: Thu, 24 Aug 2023 11:42:46 +0800 Message-Id: <20230824034304.37411-28-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6E5E6120016 X-Rspam-User: X-Stat-Signature: c3nbfsp18hmsobk1d1fsigjzdfiphnsy X-Rspamd-Server: rspam01 X-HE-Tag: 1692848870-535203 X-HE-Meta: U2FsdGVkX19iLgtLJK+MLlhcRVVRDURtB4HIzJmu/0oABTCNZjpo0fupp6w3wpk0hGwpiaiUUEv2hGAow+2UgYR0u8JWIq4RJDAMIRM80YTOs/bbk0xFYoFgN3F3q4VJ1GDtghpktgO9Al8RPsfSgWuCNPgmMVw4JmS9Lh7qQFTb/FzWTvM/VPCMSIg0JLDSnoV7XfNoKBer3HZIOnQj1GyzrRBlx3oyMO1GmInQMtdSOQB+aV0/aNifBlaGpP1ck/hsLJn5S43MXk2g/M0j0wrlLfNsCHpnOWqmRL9GH1rPluhfWQgWOpW6U7xCIsetF/4EkNHXTl+CGcAf3XqmGoVuNdtYwSa3pWra3vVY2dr2gmVKdgAZ6AgFP+9d0CSeL1Veg49S4q6yYAYOPJytOm6jOfBiDs2ccrwHCxYZpRVGrjuRy4iPyOnWrDWjyVHeFXXyJarM3rMYcPXqDceliq7HsZXSWeZPejqcDLJichRtktBnU+nQ48MpcoM2G8v32f1kDxstbuE+SmIOQ2jbqBW5GEhc9RvL5pRD1ce8JrsWOy1mSlFCSp13ho5LOWLSyHp+PlvCM3UdH7tieyg6Ge4/TYKouUj8jOgFInF0khiWHqROz0miYCtGZh0FrM7U5+XoGWUY+IfOcyGxjVdLa7lj9+kV9Z3trKt9iRYLjgYKs/SEv1LsHqFcgcqQwpX5ejE3BgrGChl2O5ZaYlNmiOTH8M8lMpcyPKeJ52YNU2x4hBAkdnJdOizmLF2ARqpNWYPrYl5uTRZfkMlPzR+Qna3tYkrT1YhF291+oecjn2JLV7ydxleL5IUNCHmzZWlsRYfP1EQi7kln7olVX0Ch8bfR0HT/tlYj4KatDNNVjA1/V2Z5eKnqFjP3pQepkyM8GHRIM3ud3ZdmGXONV8VMWndxpOiL0iRM5UqadHzjp59w7tjiyb1KcYFoMb19PiNGgYGw0DHD581m+mnHMCC ABaTNz68 iNtzyrGCHXkDR0zw6OrNIYQNOaLhbIh9lLdy4QK+VM6amoEU9EVEMJXbzIDJtNO6WR3Wfc2UZzcFKoMwWMx8kNCan1LWc4V9k+NHsIcHzpVXvF3hFKm9Q99HJirxTgY38CNWE6fKWT1t+KvxClf0GYTFuWx6KF1W9x930VWo2SPidhqG9psBSRdgssF5ExPSiv5xgvY/eXe50mWJDgxl+TkIafUE3QwKlpzm1vSgHgMWC7n+ezOwzNrK9dCACDv5hxuztPmJ9avK0oibqWPugaM59zAAn4XTqqCD3rmD/Ff+evpXZ29pWegJ3ABaF1Y20ILV0vadBF1A8KRN4ktfjkcNsuULvgGdh/TfkJfglW7xikoIvG6okmVtmQeYGCypg5HPFChr9NfxYIMIGyPnZQmxevGY7DWgKpHfrPlwfJujd7K88EisYhAUIz4Mm2Rj2Sd5eo9MMGOfLOl5M0P+wn2rZwOTaLu23Z15ZCMC5iefP0QIIW3q/JJ2+OhIYsCoier/6S1paXXy113sBeiZuKzRppP151Nz7Wjpm3M1tj+hv8RM= 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 --- 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..ac2cdb6cdf74 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); } 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->seeks = DEFAULT_SEEKS; + 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 Thu Aug 24 03:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363491 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 2D606C3DA6F for ; Thu, 24 Aug 2023 03:48:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C16EF2800A1; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA0208E0011; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1A5D2800A1; Wed, 23 Aug 2023 23:48:01 -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 88D088E0011 for ; Wed, 23 Aug 2023 23:48:01 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 68B2D1401B0 for ; Thu, 24 Aug 2023 03:48:01 +0000 (UTC) X-FDA: 81157614762.27.4E7DDBD Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf22.hostedemail.com (Postfix) with ESMTP id A2CE8C0007 for ; Thu, 24 Aug 2023 03:47:59 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=S7PJEhTB; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.173 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=1692848879; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=wI+FARaAik+c6S+JqKOXCSfeShayThMzt/z0gJ4VMfiJ6z83WenWlU7wuY5pt1ErcuygYF zZXO/AC0X/KynPLYK/lgz8Dh8loELQC0NVhDkedKjDW1lpydrCh/biQt+Krm0CfK7CXmBQ e8TMNYSiwLrKEURTM1R2+aX5OcXypDk= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=S7PJEhTB; spf=pass (imf22.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.173 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=1692848879; a=rsa-sha256; cv=none; b=8CiHT+hd8s5ExETBd4+AgKjZVSTP9CFW1uHC4NI/68Uzq4BoPBY62lFaphxY+2FF9Pt0v6 N3J5W0OfoiXpHFRWacAUjQtvBal2dHB7iY4Ts9kJvm71yYuN0lOIJt2z08jRRt821rp+9S SIRmynyDkC4mc5HU1t2E5MLhvEdU8Yw= Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3a86b1114ceso349492b6e.1 for ; Wed, 23 Aug 2023 20:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848879; x=1693453679; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=S7PJEhTBlU2ptzdizLOxfCUewX7SiUVXbnwlSYN2yOHNvAoStUJTI1eiOSL7rG56BH Lkt4aTffxFuu0wUyb3306dIpVQZ165605uSpyYO/jhILMu6ZQDf4Tgv0Sz+dN089wZwi 9MiPQoX3n2iBc0xXxBVtNs+dbNzAVP1eVgBKzKWyi1Dqgq9N7qukpvI07cbnyHlHwwR6 rSYkx5l0RXfmz5M6SQxpzqA/q37t0/Fle2uHU7Mbba0q0AloR2InD9pLWhiEHZxOwLsU Fti+OAi7IhueuRvVApFDNMDYIN5jErjkaa4mxwyJFA4LjJ5dva6v5WoeRZyJ3mtuwz44 +sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848879; x=1693453679; 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=fNxRXaSipmd30ualQGXe2v/kqoH5WODKyeol+P+IpTs=; b=cY86oJ3zq44jAazTEiUJ9SCqNBdDRG6ha07G+yPYYf1L37mZa6dhoXjxzchahfnr8K O96QB++LlxGnUzRfNTeEW4Q7Q0m8+TPjFcDEKL9RD4OeS7QFJKTaV9/9uOvgn+WXB2iK f/6w3hEBRPduzBcO2nSrC4OiFS1FitDaWlyjc6pe3Q87PxmfEKbQy/mnN19z7QMwE5Cv SeD//J3ZJyAW4cN6DZ8zOKk8G1oZA4x9fx6sp411Xz3Z6jlsVJUGFrFX1crv2gZ/90h4 kwW/OWtFCySGMikSp/Qh1hM88mTVfYDvVgUrQEuAbVAxBPqXmp/+NTf70Xmd/wOXOxGW P3Zg== X-Gm-Message-State: AOJu0Yz2JRyl3RWXJPjjda9VHcVhYjvprpnA9mPgcJfw+73iQ/be90Ic jb9NHl3Wf1zsC+l1r5KN6d6aCg== X-Google-Smtp-Source: AGHT+IE+WG5PH7wniJfO5JcJbhNOS2WEVVvbmj+rtjyhc6DhOoBfaOm021n0CLUAVkQksyHeF+Z9Ig== X-Received: by 2002:a05:6808:bc8:b0:3a8:f3e7:d66b with SMTP id o8-20020a0568080bc800b003a8f3e7d66bmr424249oik.4.1692848878915; Wed, 23 Aug 2023 20:47:58 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20: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 , Muchun Song , "Michael S. Tsirkin" , David Hildenbrand , Jason Wang , Xuan Zhuo , virtualization@lists.linux-foundation.org Subject: [PATCH v5 28/45] virtio_balloon: dynamically allocate the virtio-balloon shrinker Date: Thu, 24 Aug 2023 11:42:47 +0800 Message-Id: <20230824034304.37411-29-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A2CE8C0007 X-Rspam-User: X-Stat-Signature: barjxgu4hcatqbkuknsb754o86bbsksq X-Rspamd-Server: rspam01 X-HE-Tag: 1692848879-100959 X-HE-Meta: U2FsdGVkX18iyggoNVt+VS4dX/XtSfi3Ogp3uy3cvyfomlzR1YgrruLls8D11+noHYXZs8goZiLd0hPkXzxHEunm6dar/vWoz7vE3EG5Bk61f76QaIzPZbCWcBzQJlDmAfUpmJ+zsgh8ZOxnIZJUUPncfNpIhVwKxDYLri80j03cx5xdTynSYdQMKPs7W1vC9Qw18om4t5weD+8RB7lWqBQVcOBhTTPOv8xBUTM8Cyl79YY7Q4O2jc//OzRHRDo+BzOPWPcn6JIiN7Eu0fDKxUXKhxOxZL+2NVvOHgPPnjqOoG8p9nnt9nRsde4XfX29DQWRc9orJ9Amwxr4nnwLmp9yH75kvbY+35II7uYf3wD56ehsapx+wf41PTBD5c04v2WuzQXksJZEnqT0EHoEsf4Jzc0HVopVRGwZiTVrxPgHkJY3gxWZmEzKrb9U6zuIbJK1FPH2DAMtVwAmsejG6vw5Uo27tGynx4tJoLqKGVrVEchnxLJ7WBSPKZmaZM3eNSM1Be5YefN1A+o8wlGfix1KcwHMiqF7VAypVwJjSWczKYoIVJqyCJ3KCG81RFuUeHTRlEe+5Q9XJ4wzuXnp9B7rCDvD8mZoLfH5nc+HxPE8Gor9W6C6hDg8BnCw8gB4uE0lOPUJlSd3o5o/sI2QsnwOVbQ87iW6kwVIAFd+lkDWppBh7AUWh5ycAgrTdNOhgutd6KUutiljw1eFdio4+DBOtnhMI3BjcQwmN7kKENOVX0kJVYhFPjjUko0lcW8fmEzurzIPZ4oCEiSu9Tt+fBdwoWRLlhnphdZJF4CvSK6VjWDkPtl80gaKNKQ0cG8N+7j1Hwmw8rtZdym/x80LKoQPxeoXdGIbusaucghGXVhDTmnIBJ5nz/cfGHPjHF/ACVrawM9vmZjR6TseB/4s2d16NrlA0n21aZMrGXlXLcWPsGGO7+BAjlAFzOf+oJGyC5FWGGPAps42F64uAAg Vf1ZDKuV 0D3w/8MIXGftjwN7gQ1LigzSIrOZjKyKpH+krqh7Wz35h+K2DzVN69gOLlrbB2Ud0sPCkxlFDb7DEPDd7WsZftcNkJ59YC8riG17DYlwIjvys6JHII6EiknqptlsIoGGCyDEiLtN7GTG2qQSfNDgWqa5UDOpPSIIqgs0ExKpQcoGUU146CkvVxeFWrcwLF6q4YVLsO5iTw31j5xLwRVUO1Dr3bLqYWIQ4xvouHzcWoa6KpxB9PgcvYg/YPecQNcwvWgfDIJWrNnrhBkCG5/dkA6JRSEBkbYxvdnsHYyUjGlTk+u1NNiFry9Cv8Nb/dBDOkdFebvzSowpVXWGirzfqmvGbv76wAUMy/WwpprFS78uH3U1Tj/FsN7i+x9NmVtr44k2xSF16OcAWyIDdJxs9xnSMSdMelYLFTF6PVIknFAW7gPv01em6cTykIIDm7BFF5RKOtSsQo0sZgenv8KaHvCXFIwJ3Wlg8+pgQd34rAj9pytMnkbAlyAFMXrbuZ7Tb4Ip2mSw5dScjVK2QYtRiESkV6eBHpcB0WZVCuyFMHo7V+sMHgKpEAyKIzDoYyu3VqCDd 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 | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 5b15936a5214..82e6087073a9 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,23 @@ 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->seeks = DEFAULT_SEEKS; + vb->shrinker->private_data = vb; + + shrinker_register(vb->shrinker); + + return 0; } static int virtballoon_probe(struct virtio_device *vdev) From patchwork Thu Aug 24 03:42:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363492 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 049F1C3DA6F for ; Thu, 24 Aug 2023 03:48:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9A87B2800A3; Wed, 23 Aug 2023 23:48:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 92FD08E0011; Wed, 23 Aug 2023 23:48:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A93E2800A3; Wed, 23 Aug 2023 23:48:11 -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 63E468E0011 for ; Wed, 23 Aug 2023 23:48:11 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EB2711401B0 for ; Thu, 24 Aug 2023 03:48:10 +0000 (UTC) X-FDA: 81157615140.10.FF105A3 Received: from mail-oa1-f54.google.com (mail-oa1-f54.google.com [209.85.160.54]) by imf20.hostedemail.com (Postfix) with ESMTP id 3135A1C001B for ; Thu, 24 Aug 2023 03:48:07 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PJuxMtfg; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.54 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=1692848888; 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=LxPdqdZaLdhGYYJIXR2HiqrFCPctwXJ/6zdagwsVwGU=; b=vqyr1K8ZbNf0+vGx3+elZUnOqyNHMLzY1CawlHgOyWX70yeP+2Yu8QAfzOuN+QZoJfKkSb MGcXmcTPXLilIpRUHy3Mbb45vZXUanX/L8dBOyvZs4hOBkQGU24T33JPYebWoNagRxRGHJ nWpLI69ir9SnYDFCzR70yhPkCQSw3+U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848888; a=rsa-sha256; cv=none; b=IATma63clFu1F+Hpz64sRaiR3pPhbIybOMg+FEmv5cN/kbL8+pMdCAK/mtS2oH4NrEzaki kUieUZ25IiuUpUBu+xpHtS4gnQ06AEEewVYjL39CQhfeO3WuUOkP0TMVMtn5U8yg7VUGJ7 jsJpCXgOwTQRROlXToJB8NYDBFhTH60= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=PJuxMtfg; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.54 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1c134602a55so1134468fac.1 for ; Wed, 23 Aug 2023 20:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848887; x=1693453687; 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=LxPdqdZaLdhGYYJIXR2HiqrFCPctwXJ/6zdagwsVwGU=; b=PJuxMtfgXiGgGBUiCdmwFzQZzSKHmeg0qoDKufcfTS784L/xDIwTD1+lLPGVYKdHY2 rBP0cjJkTTzpPnAs1x87JmXYN/ZYYtC+gXSknA7fDxhp7i0MEmm+MWDsSg/8O5gfGyTx MpXxiJzAYAQERb3t8MJ6Qpur+mk5F0VpMByzvS3sTwsWDwNng4+smpLsPG6NN5jPn6KN G1sHrCWSckkOsM06kv0UN/eMfulOnTn3juEsShLfG3ofrqlX0FOYySZ4kFESBb9Gbc98 6q26WY2vUTZC1oZG+U7DUHUgJ2+CwxyrSKSk9eO7DDG8HhjgmC6fXTySg2XkeiSj+d5c EsIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848887; x=1693453687; 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=LxPdqdZaLdhGYYJIXR2HiqrFCPctwXJ/6zdagwsVwGU=; b=WSwR+o2Nb3QyL188ibTKOXYGZl2klPXkydZwJx3cJWqxoK3lA8oHIe519ctmzpC1d0 7YPvgXMXgqZV8FFsyLIRvu0q00CnOZvs6n6z4sDEoXe2oglPBmij3tqKn71s1c+NltoU 2GiebmKYIYUfZ/UbcV1J7wGeoyS0NlxOX8qJ4j4KGXpDIMSQXMOTV6JCznJHx7Z87fVz bGnw1H5Xib69AvLts01y5YUbbzLGP4NWzjDOtqSX0mhQi17g9ZWZIpwjGqXr/SHRJEm6 HuMRNhiqKDlstGPAInv5zP45yjt5ApxeSMND9o7ReADFiEeKxWtjEJgBjrTKaRRu3ntE 0aYQ== X-Gm-Message-State: AOJu0Yx072N86I0gFbSxYYM+mm4Xq5qzadU/u6vmpDPe8oU3+Yki21Bi Axq2Qw1RBZfbeN3PRJnRSgeuvg== X-Google-Smtp-Source: AGHT+IFCmSzrTq4gj/MOmL4UkrAItcPBwWXNEE2+RqRXlnnu5/fpsCgGwGOaIZ24w8cH0PGv9ZafUw== X-Received: by 2002:a05:6870:56a8:b0:1bb:b9d1:37fe with SMTP id p40-20020a05687056a800b001bbb9d137femr16277998oao.2.1692848887374; Wed, 23 Aug 2023 20:48:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:07 -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 v5 29/45] mbcache: dynamically allocate the mbcache shrinker Date: Thu, 24 Aug 2023 11:42:48 +0800 Message-Id: <20230824034304.37411-30-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 3135A1C001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: h55sx5j9i3g69z5bq5m3pxcu6rda6zt1 X-HE-Tag: 1692848887-541617 X-HE-Meta: U2FsdGVkX1/bcB86e16cJu81/ObRu60oKA19xf/Pt2vYMT1M0XzospAs5rnalQKLyHqOAJBAdgnN9Ya5iR3K8om3MJmH59p+qwotcaB31d+1mK7paRADNS/84Ofsi3l0JsU4JY2o5edYXhBYOXspo0VH5vvgZjHgrOTX9F+A5kJ+yTxtDrni0IVToi0vIme4ABsDPL6FBTZq5ErhxOdg4BaUyK1cv+BsZKSkTsKAgCPbq2qbN4YfruPXWCuB0rWHK6EJkJBcC5mKTKFuWTKSPVUo3BvhGFdkXEi+WY5PFL2MU2p2nrXQ/bTI4Byg+d29FjCimEqcut/SVwDIkaikPH2ZXpOf4jHJou/LYjS8PrMm2xeWacKwbyYGGV3/S97RA0v2tr2yYp+eqlmAhrySP7lwFaw4EmRlvl2WAtkNFd1E1fSzY9gYqqVMZHxhL5MvHwt3/wxv5oRV5JDvbGBjAnoxm1RZ6voLwEHC5ZV/ASmvHAy42WztNBKMyggwMvAXowl6blNAo2eT6ZQc+cdF3/6oDQoW6aijj/nBSURCJaihi2esGZ8K6OKQY2MqZbJ0DEW2dFWZt++ipGyQ+iYgMlXewWsbQk9IZMyu5CroZ2MSOB0NIpHffQyMNm5yqhxfNTn5R67F8amBKFQ7l+i50yucl68sdQrG7yqLuOWy71garNas3em0w73DA9WI8vsZMM1AFc1O4ANFHBggj5PkD/pewtT6kuvjOF+8Z0uA0czLGGe0MIFDwGXP5EjCjuqpxKG9kQtialDld1u9z+cEOTG3R1IOXH8Tq/f1rojWXV1cVRomTai8exX4BqzUPFktpyYn9hbVDmftr2TIW05PQuJCmrfSHwFY6gQo8xX/ivCPDXFBehSHadO3l8kEoGUtiEFeAHJNT8U7aay4oxtu/FhiuO9f1oiU0c5BullFb+rTH5cXgpNLqnCbOYF9sJyR7xVqMWs0zAPDH8LeBNx WPGIOE3J DE3acduBaMIFWxoqiG1IjylpkUTHRh2nMYhf6WBB+eUy3DwWhadrzDt83iYOGm5rRX1KZywSLC+MkOTWMzmELxzN2ZDvXXv0nuz3sQb9kzite2TA+gHES6ISeI2CXjLTQR2TPrHOWukyM7VHLZ4WOeCBFxGE+d5xcYm4j30ASHwuVqRfYWD9UhxaWrDXOcI7ShhHSq4yVAJGyNtFO6LwteiifxyekE8zCU05iuN642ZLGNlSM69klUWGTqqRBcBxZRa68SU/ZAPAVm6n7YTYBf3L+JLQy2BE1tlfYRrAs5GXq1EGhkHEUUX36ZggWiOM9rxLTJjP1iG7mqn/Q6ykApMalpVqoEvNNMcQVUSppbjFx0QRewUe4GxsP3vkGiiX40+sN4NzyLyvx19yFuVciF2bc0fftmyrnoqJpotfzez+J5jvRw6y5ipQaDz+Q2OjeKtYMlCHRVtvEa6AK4eCZeEbZogNvJyZxcGSCs9pkSxE0U+WNKm+mOW9mcJC1aEPdZzYQgUh/eFeykotnCKRu6oweOQ== 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 | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fs/mbcache.c b/fs/mbcache.c index 2a4b8b549e93..0d1e24e9a5e3 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,20 @@ 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->seeks = DEFAULT_SEEKS; + 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 +409,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 Thu Aug 24 03:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363493 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 B62FBC71145 for ; Thu, 24 Aug 2023 03:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 539742800A4; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C2548E0011; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33C5B2800A4; Wed, 23 Aug 2023 23:48:18 -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 1EE188E0011 for ; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 037B41401B1 for ; Thu, 24 Aug 2023 03:48:18 +0000 (UTC) X-FDA: 81157615476.01.1BABA8C Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf08.hostedemail.com (Postfix) with ESMTP id 0A36D160013 for ; Thu, 24 Aug 2023 03:48:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kvKgrGQv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848896; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=dSgnjzKT3TPP+drQRMO1yOhE92VfuZmdKaodIJo/RV89FFp3WZnE28XOeTk3rkv84SjfsR 5SSF8+fSc3ZAxzqmW0v7h/5d7JcEli2Exvf0SdiLLtQsSKe2vLjE7HgRnmVvuvnPUNcjou f8OqxqykcJDXWa6EkNOKMgQ4G9jfRV0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kvKgrGQv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848896; a=rsa-sha256; cv=none; b=6ekrDvTzAYtqqgcPrXR85TDcz6Bxi2htTPHTasvfEVxTUg2pznkMAZthI0if39zBOjQEfI xL92EeZsMRQH9SuZvGmX87HKIB27ShzqlBBDjaQuSnrRw34/ClbWBg9tpvgqJe+UJTXrlT 7PbA6zA553rJGmbnRUd3Hqnl72CDpvw= Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3a86b1114ceso349537b6e.1 for ; Wed, 23 Aug 2023 20:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848895; x=1693453695; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=kvKgrGQv1mYZZS4wF3iCkRztwK2mmzphcIiXW0hKBcBmpcBvr4ErwgCDxT0L2eW0Zv DJtsfJPfQXVQjgbnZU8cUPbTUerpeh1mFrxeeqphvRnfm0XvYoY6wkXj976IEu2KPv8M UY81aGvh1S2CZkAubHr77TRlgVTQj3S+O6bIip73XKRxSzJ3mZvjOtnJ5IA9wdPa4ZiS bWHD8dtc86fBmv8R6Lmll8JjHXVoefuawXEuLIf69c5aeNKZ5HFce3zJFQbqcfZDtHTW 00qh3ZW5H0/jsYXIB/RBrVJBng/341ReHz9UooUbIAK8ltPn7oPpr+d+F95I3H7EoQOD 4xOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848895; x=1693453695; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=JPzL2r2jxTpuT5KKAwKHb03JOc2oJPLa6SOVKI61m6a9hFJ1MRG8KeqjRTsxufazuy o18vMqrPGfG+P+bo1tivbT4EqJWYmPCoo81Iv6OqXGPvqN77woMRJDeVJCL2d2Py17tA RIqtebjIMT5PWEISSQDjXr27RhXCKdvPzTRZVWL7x3vygdf1JdoOr4E1JkMKAnzrElZ4 7fXydDc8SvTfhOjd2ofxxroVhjbTDynvVvkkbM3qQonCuOWmxjOhIfoIpBxX/PAqbYSl RuC2q+EEnvFu3oqJo9OKefw+Ye1Z5ivG0KwATrcheeZPxdX1wsQ6NZPvEuJPtM2HChpD JK5w== X-Gm-Message-State: AOJu0Yy4KMvhoA8CQS4Fhbm8UB/Q4SYfOtIcRY8XSMQdnEZa9/052R5d hiEIM1tIUJJHBZevsni5Mv/4CA== X-Google-Smtp-Source: AGHT+IH2JbF6bibig8NYJYSBcTW5xuf5z4s3TwsXtyBJWRygTdPzsu3RVfUJVPK/hAkIo2xRy+AgMQ== X-Received: by 2002:a05:6808:180a:b0:3a7:8e1b:9d4f with SMTP id bh10-20020a056808180a00b003a78e1b9d4fmr16979066oib.3.1692848895236; Wed, 23 Aug 2023 20:48:15 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48: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 , Andreas Dilger , linux-ext4@vger.kernel.org Subject: [PATCH v5 30/45] ext4: dynamically allocate the ext4-es shrinker Date: Thu, 24 Aug 2023 11:42:49 +0800 Message-Id: <20230824034304.37411-31-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0A36D160013 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: c6c73fu4wcokioh4swz8rrb49qco5b55 X-HE-Tag: 1692848895-724673 X-HE-Meta: U2FsdGVkX183nK757ZNyGV1/JUZ240TlOZd11xupHfrQi2AgHNAzYbA9oiSuYNzo6NAlWXfHbcEydMkkRknxfVdwrrUG+ltksK36SQDVTj1xL0jLKUZ65ddObGJMmAmu2ZJ8YwL7rs1TrR0mqa7G12tpj+iYGO7+oAufD9c9fJpHsKaeR40sQ7s1N5Ovqg1j9VdHveCitC+wlLztaXlpVFDoJ4uYgX04fcXTU6kjP+87BkhyZmsPWykT8Fn2Sbs4tvLqNk7Iy9jXXJ6JEydeM1bK6hamIoffDXOgvFodNFMVI5iby1zUOmKbQA3/840nBmRblBsDqYicKJxOB6FMWLMv+UF8F4t28OwCmNPHQHl/ARX725zWkkQor/sM3SYqyUpRVMG3IGzn0PChB75tp6ii8n7eQai/927QWZ/k7bZeub2AGjhL9ifeFD0N2w/3rpHZgO7ru1CDxYAVTq52sIEcLIqjeMiqWp6XbN1g1cig5RjHZAn1uv82OZ2pQiHgEudX8yp4IshWSt65FMr+w53h17yKJtSP3FDs0j8DzNkK6IsuasKI4tB0oPamnXVP1r7DPN8vc27NjpK485kITi8Xhp9YR+Mc22gxYZqJ+5LxJ2+eVW0j4QeK+ksNjIiS9k64jpFg0gJp0HJ2IoFhIRbyzE47rss9CczDyKkutlFu8+aP4al9vgVappAyBZeh27CuNVogcHdVPxyQBv8lORKk29/m5wc7QMDDpAXwTtDtJ9ugnZr1PjOmGUA9FH2Dp+C0sl8JYFKvCTTR34fPvJOLbCWUJ6syi1KJGu0VmyoQq+ssdZK+NKsMR4H7CLg0rm2RzCrdxP+vnqnNPZV1oAvtElkDanAooGQQQdgORMCGeW+5YJZLWZ3XN9sKIPKSSbBb6iOOGEDCRgsNeb6r/hTU+NrtnuKB2TIMExIISLUNo4ga60Jolamqn50+PKS2f8JhrlGaKYyMlNTvLJy pmsL1U3W u2ieVxiWUwybDLjHvTEsleyy+AFBDT6Z/8KB1P/itrXDdJvwiD442ir47gduEN8wpaGLPEphKQS9srefJz4QgnHBKejTVHjKColL3ENWG0d6Hd6ylrYlbIlC/hyDRZfvkeSDyGbcveK0DVax3MbI6j8SBUkfFyIveBOz09GxG2BZ7lwgCJlBqfZObR7k4HeT6Tfh2NkEKn+rm77f7b+5dpwiKZ9Yt01kd1qw9IwzouOA4HhqjnLmT72SzqAJ2sdiQLNBwcDM+Vt4S7OPWrxf165M0Q+QrX2reaC5ifFYWurHhIK9M5TUf1FFnGydxiTwokP4N5NZ9H56pRRJ+l4nqXRalcYJAsIAcEaK74AeJKHywRNk2TXLVXGnRGPGLcTTv8QrM86eNlTT9tjHsNSzs+9w1rCcSXG7+ByTVeUiqpJuCAkaw22M8FyGuF1hWHNoxIJ/hcxhn7vq9ra5CP2mCmtJmKr5YjclBN7CjrQqbE0HswHTx9hEY3DjhCFPmyAPPK/5klUDLooNhaOW3SIH+a+OUQA== 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 | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index e5055eac42f6..353a7fcd609a 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 9b5b8951afb4..0532a81a7669 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1596,7 +1596,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; @@ -1605,8 +1605,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; @@ -1690,13 +1689,18 @@ 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->seeks = DEFAULT_SEEKS; + sbi->s_es_shrinker->private_data = sbi; + + shrinker_register(sbi->s_es_shrinker); return 0; err4: @@ -1716,7 +1720,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 Thu Aug 24 03:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363494 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 228EEC71145 for ; Thu, 24 Aug 2023 03:48:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B54792800A5; Wed, 23 Aug 2023 23:48:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADD128E0011; Wed, 23 Aug 2023 23:48:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957182800A5; Wed, 23 Aug 2023 23:48:27 -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 823658E0011 for ; Wed, 23 Aug 2023 23:48:27 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5B5111201A1 for ; Thu, 24 Aug 2023 03:48:27 +0000 (UTC) X-FDA: 81157615854.29.E7D11BF Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf16.hostedemail.com (Postfix) with ESMTP id 857DD180005 for ; Thu, 24 Aug 2023 03:48:24 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YIHIoc1R; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.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=1692848904; 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=pYOB+hnIO83YvzUHSYTSuFO2utsF72W4sdU/yBHPL1U=; b=0GR90XH5JBl6bV+KDz9JJMA6/rTOHC5sLx3q5yAK8oxXO50G+H5zJaLc2f789LR1luA2HT Pb1QTdESF3np7iqgJ5sMQzhNuSrgp+cReuQ6enIqEcFvFy9ZG6m7DXNPN90xJR/DJCke8W YftnplQEJK3o1w2DgeF/jgDxJywrCZI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=YIHIoc1R; spf=pass (imf16.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.179 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=1692848904; a=rsa-sha256; cv=none; b=Ilm1yLzhVo8o/GhA9L1y13afcn1Q7DxwmfbuwkB3biL1Bv/JwO8PPUpUDPXfnJoJ/lmyoy VtzMfapZmzeVGyxJxvNGBBKdGMa4ngrCuXhOIRw6UEffSZH/n4dTGSaGA9HapJR3/CQ9Xx pFSFu5JSEM8SfT3S4YUojPOhYEGBQ2c= Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-56f8334f15eso164516a12.1 for ; Wed, 23 Aug 2023 20:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848903; x=1693453703; 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=pYOB+hnIO83YvzUHSYTSuFO2utsF72W4sdU/yBHPL1U=; b=YIHIoc1RJYxmkhYVOcGBRkBxvRhCV1vgbhLHLMHVKdroyXNJiDuJUutMmWOFcPBpBW s/5YL1T7lyc2hav1PtBIIN2Dt6hyxpkwLoN2k+dutrk6yEzT3g/nPXTNMM1CpwIdn7cK vKpo4xp6upXNV6Rk6KduOhBhcTSJ7rKvPI0CWETY6P1zhV3T+cGTYcHPpNts1uIFt7Xa slnyTJaIC+EL0nEINpq6Gumx8Im0B6M3kdYzAJy8prFgOUb8N2+zr2h9bofMyVLTfYMe wH5VoCpJVdhicwlvFPsZC33a5pDKbpFkIRl8d9BjaJjZ66w/ZuYhKjXRayn/0wC3WvtB B4WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848903; x=1693453703; 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=pYOB+hnIO83YvzUHSYTSuFO2utsF72W4sdU/yBHPL1U=; b=gluNa+g3gGARCiNe7kqc6gzc1rqKMbobprXXoVbtsWf59FTs4CNwVddDVOPkjVapaF Fc9nPclexvtD3dOgneamGZv3NLAtf7aOtD1lyZgyk4MVUO7w9Zw2/737FomwU1xI+YOD QVXund+IAAd6WBX46XELUiWc0Q+0pspAyyJYK0/Vp5QymJLefni4HfFohvOsgIAcWV64 bFEcL/RS9ihrNlUPE3y/TSkb5IWOB4io0bBqU27jMGmvMZfnqVorYv0tLh/OwiOc04pv B1Teoj3Wmv3aRLadHs2ZOTcaZPJ+7jWDjgGx4PbmPE9GA3kIDNPpq7K5RWxxfPOYjb0z W2pw== X-Gm-Message-State: AOJu0YzNWJXtMganhl6/6mmFtabU8rrOZn9YYEBir6j3g21SSkM5OrNs 7gUaih3W7Qdd6ke6MQ6Gk7UumA== X-Google-Smtp-Source: AGHT+IG6N8tn7T7dg336qdyH1rso/0WPaO046+rzbqZhcbNGv58+8uAGt72gzl/ZUc8tgddqdUvO3Q== X-Received: by 2002:a05:6a21:7890:b0:112:cf5:d5cc with SMTP id bf16-20020a056a21789000b001120cf5d5ccmr18056004pzc.1.1692848903439; Wed, 23 Aug 2023 20:48:23 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48: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 , Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v5 31/45] jbd2,ext4: dynamically allocate the jbd2-journal shrinker Date: Thu, 24 Aug 2023 11:42:50 +0800 Message-Id: <20230824034304.37411-32-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 857DD180005 X-Rspam-User: X-Stat-Signature: 8z8obsitbmxmptdp6gkj6p1sxu5egcrk X-Rspamd-Server: rspam01 X-HE-Tag: 1692848904-140287 X-HE-Meta: U2FsdGVkX1/mGmZzmhBlQfqrZM7LCZIowoHmWzsXKPe62pW8q9ax13tMCsnY2c2L7XfD9to6HTX1cxSW5V2SdLipGojZGQ8BaYETVBBztqzirMGC78RA/4Vh/wPsKj8dfXEKnE0ueQV7t31qQBlSW8yeKkvuk8RithSyWDyQBX3/RXby6OekFYJd3B916dgMe7bV4U807Aq3SnPZRDeM3zj56nwu6IgskSspywtwYpat/4gqfUkguLB9cHSAXZAEdVjFyXL9ADzqBgBAFj+h8RoLMGjazQdTVyBCTGfaMMyj1hcFYImgKMoxR2hRqVltbZumXG+WJf9K5z/H0UsFzCL4Sv8JbCh6qVbGOu/ZSNN7GtVJwflKyVWRhpEwT12o23Qg/ioFBSd/qCLYK4CwsGhWEdyFsKSBzOsnmHj8lEVhcpybZhZWIiQZOuhlVRdhpf1tYkDwRGZ9Qm1FUQRC0miNQgQiypKRcIAObuljPCjr0Dq1l2b1vZzvAPBgHDKZU/gvhi3jCUC0K4PVgrRQijSXgVmNzlxiq5i8C6RoViHxpbhWs8H8j4jCEajDlbUGttcqwnYoM6Y7C1sDb0fHcASBZwGTIS0zNvqRUcrhAHii21mZkYNKPoqCyD57FevY0TaVtdZsIykOA/6hjTgfRNcoPCvQsf6OT/om0p36DfHq1JbiSYdk3W5g6L7DQMAYaJFmT1uxOWXnaigCdHe9m6MGx78f6rzDYDzPWXXB9PFpojkyUnlLVPKoMlOVDs2tbsZYKyi/VG6D9p3d/0U/pETvHCM0gxygSi5tnG5Qqb817/EKTT4iL43/LAR2DMxz9pQBDs97Dj7kULaXmPHNL+NtO3RaexvTcL/abFU+0GDB6brkcjvSaJjtJ75fHF2b7DbnqR6Gfsk0O+oUABw6KvDwLLNp81M4aaIV2qkMzQ7NFW2bBu4Rvsq8ba769Nbj6XRWIX4toRrmYTsB2vM fmlYvcFw GZTRaRRM51pJqiuc/d8HF2yKG7+BZuLNhacXzM/4WXEOQkDQ3nwtGq6F3bOiMjZb1UE4rep+VhOVgoNG3Gw6euh+mEg2ugAdKPc6+hLQ2IozTdnmHd29QgXcbE5XshrUn/EM6wFTJr8MJ3EXCTGCHpgB6IfAGXI6Qd46BfI5pstu9h7H/m/Cy6mefU0eY00uC09LFR+v05G+6lR4tSvjRj+fPjYOZKHCZndA7MjlD99aBLHqET43yNdaoztRVcYoV+umyVlua07X4PIyWcHvFa1jwgcrS+VnbOjiLur8Giazgsy20YCOgGCKS1L69WHpvDcjoq/bVN9UZBIG/mQCfxyli+EFj/viwq8geZ1x695eT9A1UX9uONDV/7c38byOjscu7fMQmsV6KLF4Zwmypv5CDqoai0JJLbPPGWugREYtOKJN4Jb7OVpt3ScfdR7hnVLpJvA8ZnpZ5cyVbMD9bBbQ4jFafIyWiTxWVa4pBJej6SCnhNCu/EUJKXQ8LbwumHK88b2IZgfFRHDeyUUw393ZnCe6Zuq52qsw8 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 CC: "Theodore Ts'o" CC: Jan Kara CC: linux-ext4@vger.kernel.org Acked-by: Jan Kara --- fs/jbd2/journal.c | 30 +++++++++++++++++++----------- include/linux/jbd2.h | 2 +- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 768fa05bcbed..75692baa76e8 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,22 @@ 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->seeks = DEFAULT_SEEKS; + journal->j_shrinker->batch = journal->j_max_transaction_buffers; + journal->j_shrinker->private_data = journal; + + shrinker_register(journal->j_shrinker); return journal; @@ -2170,9 +2178,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 Thu Aug 24 03:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363495 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 8B9D9C71145 for ; Thu, 24 Aug 2023 03:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27A5F2800A6; Wed, 23 Aug 2023 23:48:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 203D98E0011; Wed, 23 Aug 2023 23:48:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07D2B2800A6; Wed, 23 Aug 2023 23:48:36 -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 E7BFB8E0011 for ; Wed, 23 Aug 2023 23:48:35 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BDC5C401AE for ; Thu, 24 Aug 2023 03:48:35 +0000 (UTC) X-FDA: 81157616190.06.CBA6928 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf13.hostedemail.com (Postfix) with ESMTP id 03B0520007 for ; Thu, 24 Aug 2023 03:48:33 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=glrCcAGl; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848914; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=wZOYBD/isRhflSSHa+DYwbHoEcqvUhsEPaKIqm/QpkrNZ2xljWOIJn5tZNM6wzTpFMZuzD idptFaBhmDw1Ow1MOS7Zy5L03GYEaRzdntVmOm8wrhzk2BZe1tewAYMDNHFFdRiVVucJT2 r1mA0yjpTV5NuRVgpf96JHjNPlXsU5M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848914; a=rsa-sha256; cv=none; b=oYUmzrJ36X7tGCckGG0uZRMkbxPDr44HF3ls59IwUckZxEW9XUaE1twpAw5G6waGTV5EqN 3DfjMqZTIsNfQ4D1+f2FXbxNXm9kUEM14OgO5FX6VlnqSM6buHBxbY0KHvGSVnp8BILsyF DWa5E89EuPbg6hQuvrDnG707M1EGR9g= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=glrCcAGl; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so756316b3a.0 for ; Wed, 23 Aug 2023 20:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848913; x=1693453713; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=glrCcAGlI9tORwLN4JeOX2Ojmpg3nd+ma/3S7SfNP2JPT41zIZ0IQM10eTVKPLkYqI pg2c3cj/mxF72M7VVk2LY+U28qMFYAPfxu7KPD67Jpu5o7z+DfyV007ggfjzdgLysN82 cVDAiZHzpVRc6gETtIv1NBFK6Hvgz9JH2aOGng4fmagYixWYge8xFOfj1w99o4OKSpcR lqLQMu8XVXXZKfG0W+wqfQnFIKtFhj4kiY4i3y6Fokx88A3jo9QjLRBpri3lqrfzuIJu U/0aQHnJg90B6KEbY8BJ7rA54knmfENUkK0fN4nXKSLjT+G6swoIKswdwLSd7IVK09ma wTRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848913; x=1693453713; 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=zC9WqkIww9J/yjcNVRfpW3XQ6AEKQ/LjI/iUfI4jlaA=; b=FQAx8Jz5PmM7Vn8fQ3jKOyjGzXdv89prPtzanidN+2ywhNFNYWnE3az0fE2eKBhR57 6du0QxoIdgsPzdgXHbzfe1AxsbOJ4yj2RERDtJgMG4s6Kz8VIfJ9QaQCw8RkctDXJI0q u41sTbxYMx62CMSpryxJfF9aFVOUrfaYL7xKD6/qsz2BKeHLCTLRgHjHE5HUdUSzpHmT pZ3m0lke97bIJUn+Qpt7EyMlBl5hgZufH70B+tHSRF4dPgmRLUCbe5eeimAk57IuKHkk E9QL1Puhk9mqN4mF6nhIK3qmqh5XRX5Z6x/52omqz9tvVFd3wTLtkqU2ayglj6cisFNp 7MIQ== X-Gm-Message-State: AOJu0YyIDX73OLNxO16FvvZaybwztNd2iVlI5DeBAV0/oxm1YwD8k0eV cZsdDztytVmOhlJejrauV8LOdQ== X-Google-Smtp-Source: AGHT+IEQ29rJQXeZVflVKNLar0GggbK4xIRfj9VbHOaq33vMQI6xRJWrdG4vksRQlcd6vKsocE2yjA== X-Received: by 2002:a05:6a21:78aa:b0:133:7a67:b477 with SMTP id bf42-20020a056a2178aa00b001337a67b477mr18675611pzc.1.1692848913047; Wed, 23 Aug 2023 20:48:33 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:32 -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 v5 32/45] nfsd: dynamically allocate the nfsd-client shrinker Date: Thu, 24 Aug 2023 11:42:51 +0800 Message-Id: <20230824034304.37411-33-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 03B0520007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ieej1yipz5gsr4wbuwd94pi4jmmj3rxa X-HE-Tag: 1692848913-102058 X-HE-Meta: U2FsdGVkX1+XTRcMYzo456epI+M2nEQA9srdrC8Tf4dZaZAlG+nPNGSXRo1heaKCFsCs8ikTQhG++kuICRpJCngV6/TGevWY4tssnX+xfrnzAFYmaX55IrwFhG0Q8PMZDGoDtS30T4qjETaLGFxvpDzuSvrTecPUnYCzkp+P0QolE7kp/4ng8yl4XNzJJaGEjFnDvdPQdacc+n2P0IFsIN6NejATgbHPUj/DreKtMn7dnIJQf9MjoC//uyjFWIBLPgeaTow7WbctVxGXs0KbN5dWeKtBHDL46P1Bb79Un78ShMmOZwYYdtqwTcc56Zj4WN5lNNeWwDtdY0cHl4J+weJN0OGq9fxlKcq+2kcBQF4PQaUtqnMhrIz45SemntLj+LA1AnSBnuVJOavLLPwO9gYfGOqPnwlHMG/Z1Df5DyBPI50gmF9IcAh+SkuW0w1BIJKlC0bqv3fHqoqM7NnxbPrzDSd1r8NofmJdohoJgA860l5hncdvDt1MxvHoafPujxFEtUcZU4MbY7NoHIX1r2TJbq2rZkv0c80jJIsJR3Pox5djcSlvhT6gdMhjq3tO/H2MgXc39wXY7lgql+WONMRC1Mr25/ZO/ruVjAMrg13VjIE+jvv2VRrabPtsx53Hc67vez7fp2cCC0I1aO0JsbEEyMyqOAfRfZO8RDy2L/xozV5D/h1P8z4MIz5qUU1sXGNDT2XmH/NLi0y8tZEY8S6W7LrddsQfhFvWEwVSN1+swkO6KdtXShkM1P9axodanNgqh0OLvJNz+d6iRc1QHvRMnVaOH7dLF9zzsRGxAqDfLN2h6bcIXKlUva7VRQBmVhyzgPXFX1IJogpY/fjxtEbQZMowbSTMtdricrj9vhsK+uXTFRLJzqjRoBKdRRdGzF9PfUCYTG2TvhBdglYep5QGsq0byia87q71NT7aA0TXm2f85YXCfYDmWM/HJJqIvV8nwLn3hOw7aDsFhua DAxkKSJO z52wEcwWM6+T8IyqbwNGzuX9p+OZyvr5E6sMyAJjLmR6umtpHmVdoLvtHVL9w4ubJpWBE0IXX+gXs3U1MZmwuAVcNmOby8YVzIZ1OQzBRLxWXNWOt1JPqbNprn383dvLFPtIQRiU52vLNJBoE3eOCVwbrO8UqZ439N2Ov6xTNE3EWmAV/GAbnJaDyh1/Akjf42T62eexB4i9P9ok1s51TcWdlI5yu+SYu3QsGtn+BEUL6tt4zyQ71echKekdV3GIIzpQPd106JxSkg6tVvjXVcQENnr4or3gwwCGoW9/nXtTXR3vAjEXtlZmP38LuB8JfA2tbNC9wqELzYNFy1EFfwTxlaYpPTXiyIJNVBpPHqQ16xCnCuAc6tuYHlFSs4Mre7BTC+/2T0u3qofcgNJnVYWgMXDWGYWlrF/VubiOgIy7i1NvXEsK5GddCSdKoBPzHEJ9HGI+udm6dfSn61gpTxAHpMrZ3Z0DFwW46zOgD4Xe85oYIahfA9uhtPCNo0HUKSrsRL+pnulFhm6s1CI3Bqho2TNDoQs4oII9hOsQ22c+gUR7Ja2Mt0EWYQ9dE8+37SilnuzyWiE3U2TpvmJCvQW0FsvBrfP2OGLIS8vu/u+saKf8= 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 | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index ec49b200b797..f669444d5336 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -195,7 +195,7 @@ struct nfsd_net { int nfs4_max_clients; atomic_t nfsd_courtesy_clients; - struct shrinker nfsd_client_shrinker; + struct shrinker *nfsd_client_shrinker; struct work_struct nfsd_shrinker_work; }; diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 4c6a94a9699d..b2742065a813 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4400,8 +4400,7 @@ static unsigned long nfsd4_state_shrinker_count(struct shrinker *shrink, struct shrink_control *sc) { int count; - struct nfsd_net *nn = container_of(shrink, - struct nfsd_net, nfsd_client_shrinker); + struct nfsd_net *nn = shrink->private_data; count = atomic_read(&nn->nfsd_courtesy_clients); if (!count) @@ -8149,12 +8148,17 @@ static int nfs4_state_create_net(struct net *net) INIT_WORK(&nn->nfsd_shrinker_work, nfsd4_state_shrinker_worker); get_net(net); - nn->nfsd_client_shrinker.scan_objects = nfsd4_state_shrinker_scan; - nn->nfsd_client_shrinker.count_objects = nfsd4_state_shrinker_count; - nn->nfsd_client_shrinker.seeks = DEFAULT_SEEKS; - - if (register_shrinker(&nn->nfsd_client_shrinker, "nfsd-client")) + nn->nfsd_client_shrinker = shrinker_alloc(0, "nfsd-client"); + if (!nn->nfsd_client_shrinker) goto err_shrinker; + + nn->nfsd_client_shrinker->scan_objects = nfsd4_state_shrinker_scan; + nn->nfsd_client_shrinker->count_objects = nfsd4_state_shrinker_count; + nn->nfsd_client_shrinker->seeks = DEFAULT_SEEKS; + nn->nfsd_client_shrinker->private_data = nn; + + shrinker_register(nn->nfsd_client_shrinker); + return 0; err_shrinker: @@ -8252,7 +8256,7 @@ nfs4_state_shutdown_net(struct net *net) struct list_head *pos, *next, reaplist; struct nfsd_net *nn = net_generic(net, nfsd_net_id); - unregister_shrinker(&nn->nfsd_client_shrinker); + shrinker_free(nn->nfsd_client_shrinker); cancel_work(&nn->nfsd_shrinker_work); cancel_delayed_work_sync(&nn->laundromat_work); locks_end_grace(&nn->nfsd4_manager); From patchwork Thu Aug 24 03:42:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363496 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 9C36DC3DA6F for ; Thu, 24 Aug 2023 03:48:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA658E0015; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 363588E0011; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DD2C8E0015; Wed, 23 Aug 2023 23:48: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 0D43D8E0011 for ; Wed, 23 Aug 2023 23:48:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DF737A0195 for ; Thu, 24 Aug 2023 03:48:45 +0000 (UTC) X-FDA: 81157616610.03.B967289 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf15.hostedemail.com (Postfix) with ESMTP id 1DC3DA000A for ; Thu, 24 Aug 2023 03:48:42 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lO1BdOc8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848923; 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=VQfY1MCN3V3EFlPWSPDIANS6+b+v8SKrLcWgVsNTh2RoRewdE6sJ2Gyd20ais9HMzyKG+6 u4H8vwziJEI3S2XnWtWp+qtzvGpQO53B3aOI224Cj9aQx8astcR4Pb/QjAUtUSCgu/5A6x 3WDybimpEEHH2ldo3zLgReSzqsw+9iM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=lO1BdOc8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848923; a=rsa-sha256; cv=none; b=dBLfgtHOvv7hIGZyXfc9NLbLmwuVF1dtD/hnfO2f1VgvKuVXZo2TjX39Da0PbUhUPK3nat ubL9hx7g2v/UHCpvryM9YRkrNukr4Asb38WnFBYF8C6lyHKzNqPm1eo/5LrrvWkIMRnZ2W Mt670uTEGUtHbAswT1ndpy6DdfHkU8U= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-68824a0e747so1238304b3a.1 for ; Wed, 23 Aug 2023 20:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848922; x=1693453722; 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=lO1BdOc8IC76LRNZfOyYy9eMSIbqStBvooSiHRS3AafY74HoA5BqZ6t+3TGAl0AtpZ rev6hFOx+kyDkPHvZWJq9q0vP81aFRlb10Zk0Fn/fmFGc2gfXltX3ouoNMCO0npH2OYh mHzGaYb9GR0YpvYgV0F7nGHXI+2qAfWk7jBdjnrbHQ7ZoXsBAkbTq8I4pxbSsEHVsDz8 ZP9W981GjOmUSABfVm6ksphZLc3U0h1/AMUeOlX2AabLS3bbzoyM3q214L12qJTAcaI8 AuxZhADwW/QQM1sMR7rpIuhO83gYxeJqrQlI0CxOm2IAMzWUOcDbXFo7LC97q86bZmDo i6+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848922; x=1693453722; 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=XiHyXBICBk+DjfMpf08z48rUOYQ+6TfCktTC0VYTYpZ0z+42yyb2n5H3UjKNWCMxXo qQ6oiG/ruWiZMoAbxkodSSjt6of1BHyE5pGzHs9+gwvxwcWQJsTwRIoXQ+iyjpttfCXM J3HZTgn1LcsjHrftRMM596KSNf8PN5Qz+YUBbI/kWz4pI8lGnn7437Ces0pYLZsLKnMy Cq7ZnRy9M0KrmJeOwL3Q+YGpaV3XnVM4HyG5xkiRQ4Bp1RBQB0z/O2Kuk6RthPGkG6sd obV7/8H7LJ7JPMh50fldBUJwf2tgDksbPwAAvG3A2x4c9Sjfioduo/pjGtFSrgVoGyXk E8mg== X-Gm-Message-State: AOJu0YxukNffF+aqNNnHJO7hpw4MCtMJgOWNABS794f0Gscub5ar8WGC +3nN8HgY8yI4PGzLUXbk/6qHog== X-Google-Smtp-Source: AGHT+IGiDI02Gkdoww8eG0IG14i0OeHJi8Gmt0fnAr81rlF4DRqTG1oQfD1+mqVI4jvLZxUezjNelw== X-Received: by 2002:a05:6a21:6da5:b0:133:6e3d:68cd with SMTP id wl37-20020a056a216da500b001336e3d68cdmr17945492pzb.3.1692848922018; Wed, 23 Aug 2023 20:48:42 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:41 -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 v5 33/45] nfsd: dynamically allocate the nfsd-reply shrinker Date: Thu, 24 Aug 2023 11:42:52 +0800 Message-Id: <20230824034304.37411-34-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1DC3DA000A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: f6fhn6fhxxzg4qqicxkzumz4tpjzg74b X-HE-Tag: 1692848922-261035 X-HE-Meta: U2FsdGVkX18TEEI5Y0FMDhoAv+ZW87cVCm8pMxrUiD3fqb0590TklaGz/nO21qCI3sFGRq1VpdxpFfhJQmfp+5CfjuXOKE+E9Q63cXTASW7dsLX4QwjoS40xDuF8F0LdL6YLhJA2PIU9K5DoG/phYFyxU+TKtcJg0UVzHfEEYHphKSZqTqxfxDXmx3/hfBomPAh2mH4i3OBGD/rXx79PmxNGVog1GQmfUmAV30soNX/rKlilUlIsfL5K9GvsYbwWZBfhQSlUgursgPBC531eO8vKZ2nCUOOxeNqvbOnWyXMneP3AI4ME8+rt5GyhwKC7MNuLTKwtnfQaL9wQz0lVeYr5gMjQEdpwIBCkFOM0S2sEb/DoQv8FS/Hw18999VROHZmhlTA4FunimCL7thj/sTpqrfVv75sBQYiiuW2iyxIFHoH3zihAkWc7Tn1R0ugA1y5pA2f5Q1ug2MJ+Yeil6LzP6pINLnoFeQRy4GoQDalvADQfjJHNmXqklWsD2XJH5ZE7PovgH92sYQPHEfUCHNQxImkPDCfT5GYjl3D8Yj3yhKXtmvvSobz0rGoYDVHSma8tf+YJmPFkcYLG7lj7CbKzfjf2FbG7/8S5J2YiVLIRyFsUTXC1jh36nFR3qhpHs+zXggmns6BjBlSwO1Y6uMyIVLYbO/d5dXE9kCYwhTrShI00e6Z26scURIZp4qGjasGeDNAlIUXN0KPdD+Jfua0vAPas5OhGSqyRBiJ2SXGcHYj8u8Gsq0HSJr3qfsIOc1rF/+PTBTcHBV8hOUK2nCSG9JeWkXiUkQKz/0yiC023Av6/DpG774eD6wzB55HzgJifgGwUj1sAvwaVcfCqEKpRQ5RwQXOwuVQ4z92jSc1BD3USFNSpIIiTNPs71sBkCXFlmByK2PCl8g6kRxkY8e3QvR63wFujOzmewDpS24XiDAGtXlsUv8V/d2t28bH41WTdZQo3GMZFYEHx/yW Q1XnTNTq mSVk4QhX+DEMhI2Lbr0OhoSFi3hjlQGaMDaPEPguz6clrkHftp1a5vhvnQUOuaoOmZ2/yAO/lVkKcSr1Tuvs+E6j8WJQqMwkI/LJDzHAIpTLbjFh3pzyz01daAwxFRglIHHv8mokbih55di8KiyfR7MRuJGWLD7jZ+5G0n9pCu+pFJLDPVxkr33vWMUlkilID00SzBPY4djpGm8XC+rbHYwgmYQGybF9VUNyYdh48GNRlDMYT38DSfuJqGJIVb8xCaTNp1rlwLEtZ9/0yjhm2344g9oneQjZdc+Yk2p9fzG5aFPXRxaMoBvIlE2wUrQmyeJsAm4Cnv3h4qZ8/U4i9IOHLs7LrMAsNjY2HFBOoMo3AFyRVpOp6zaiZsodv7cWE67LKY0ZB4qwZs02K9V1JUZLj8zkaWDxBx5TKzhwDvNnEIOBkpTXEhnmz7qDOphSYqqLQ2GkNJeUNXbrA+91tuqfAuJhHXUh1rhSsCnXHLn3NcAO3oePH3s1LW7oEj/adkoDW+LMpY1tj6/R09Eef/24Qcw== 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 --- 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 Thu Aug 24 03:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363497 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 9A987C3DA6F for ; Thu, 24 Aug 2023 03:48:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3DA022800A7; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3634F8E0011; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DDAD2800A7; Wed, 23 Aug 2023 23:48:54 -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 082408E0011 for ; Wed, 23 Aug 2023 23:48:54 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D81D41A01B9 for ; Thu, 24 Aug 2023 03:48:53 +0000 (UTC) X-FDA: 81157616946.03.A104439 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf11.hostedemail.com (Postfix) with ESMTP id 2093C40002 for ; Thu, 24 Aug 2023 03:48:51 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Etg773HE; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848932; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=hZ/+CEKmqFbd2DXtWwURqouHRdD1V9N+sGNEKqHuqlaR9r5AmzLDrupnYctx+Ae/jxJJBY YxBjuFORQbfIQ3hJUlJrgzG4rxffdPA/pi3DE+MyHvVTJP/Waz8LADJn5ZWTlnmIO4g7X+ Y7uND1KORdc7h/f5qLquqw8t8WII2aI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848932; a=rsa-sha256; cv=none; b=MYkQqRILvrd412Sc73WmIZK+BUi48m/B4NWxh3c1Y8Gt9WsQH04Qu8MN5rN7yzkHzLetDT FJhvKNcU9T6hzkx8q6OvT69SWihh4TYvNbXF8sPQVTkj1ou87WhxY4FIC+1dRkwgbnjC+k tkC3VIQK+Z2oF6PPUjIvtOJv3oWW2ug= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Etg773HE; spf=pass (imf11.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3a8586813cfso655825b6e.0 for ; Wed, 23 Aug 2023 20:48:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848931; x=1693453731; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=Etg773HEMt6axbPONXeHGSLT51+RdI3dzQiJTfT96NZnFEl37bQIBM8X6mo0sOTo0d 2dGYINCvxlO7NPH+D5RGaTZqETV+0suNEBQUshlRf6R9Z7fNgoXcSjr6zlrjyT7NxVbA rVONX6e+68F+cT0c/emQ6lA8a/TGlO+N4/53pkI2oWnDkzLPDOuqpd7sfIPnNddNcjt9 0vbukc7S0vFSoAGkb3yE/u8zFtdBe/pJpAC0iBfkpaI3MovdpoMhtwtuHo4U7Pnsxdxf 1GF9PbB/mGtRR3mXcIqDFlbcTz7ePkujB41gg7lcY5R6hmxlcHo4GDvhQqafR3/hzexb XeyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848931; x=1693453731; 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=5BIenwMEIsfTGL6YUhExKganEB0/sIfRnhshE0vnI4s=; b=bCRmzl1S44E+BUJGhm1m3Q4M+J976cy9VJb+s9fEbQd6E6Y98TkZjT5SSy9jL8ILoN bzrAxsHfnelzjCsB4y27KwgodKsz9nVDD+R+U8pC0ql9IUaDJH8o19YJdEMYD7E4A3kq FGHjFwAdTN1TR6FjSAse9PjKAIqrzZ1jiz15wL6dWLd785ZxoP02v8RW0r9PEniaRMit AAtbcpP2Gf6zEZzqOLvtFEx7P/GjEP6LIZAlsusCV1K9PEvSgD/nA8o8WEd2GXLbl4gU rxsD97R0/8nEaKkB+ke+/p3pFuEnZI8841gj60hgOOQaEI5ghcsHaUdSba73+b/jvAYU C7TQ== X-Gm-Message-State: AOJu0YzjUxWZTcpcBxxPZgZ8YSicfueNKVN+gU3aM+AJ//oamg0BcLSJ p75qLT3NiKyaZVh42zjgfR4eGQ== X-Google-Smtp-Source: AGHT+IHBqdQGZ5Cdz64aUWukdXrVsG9fgeXOAK36erFQqZ4a4LZTcz+AGem6g0p/atv+siUHR5rZkg== X-Received: by 2002:a05:6808:30a7:b0:3a7:2eb4:ce04 with SMTP id bl39-20020a05680830a700b003a72eb4ce04mr17483879oib.5.1692848931041; Wed, 23 Aug 2023 20:48:51 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48: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 , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v5 34/45] xfs: dynamically allocate the xfs-buf shrinker Date: Thu, 24 Aug 2023 11:42:53 +0800 Message-Id: <20230824034304.37411-35-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 2093C40002 X-Rspam-User: X-Stat-Signature: iinpht3cm1zcsg454jggyp4pfwy53gmf X-Rspamd-Server: rspam03 X-HE-Tag: 1692848931-79267 X-HE-Meta: U2FsdGVkX19oi/24NGMeKuDipaxgbxk8dTl+fF6Qy8YgR22mTPUOZcyjT2v4wtZbUOnPHvABUa8fRNXBAF/cAHYId8Pj93po7Sz0ivKIIGSyywNTgvU/AA+t4ZRU/c1m8aHjYtQZ+OYeThEldYQ70oQYlgupIwAxSa9NPiHns34IRuYYMlt+f5Lcntjau2J/lpi/v9ZAOm+FDeqgx71bC4ZOhPZRlf/S69K00p2GhQTszDTQBFqj/+Z4jT8lvlX1aKSHOkq9oyYYLXfuXj+PpW7yduK5jrEs+Xim9zqzXq32+6vXzHgOIPgfonQ0M1KnbZTd5ddkMLdBJYQNEW/Y/wHGCEf3GDWLOGCVzjVKih39WWjql5+CagWgIH9OV9u8vj5X94Elck/JqRsQLbQ9nAnQlf5+OyAjnHrTd5aBCmugUXh31qelLI+iytQDXnW1UQZpkWPdJ03PIvnCvkvDZ/YKHqvYzaLhFVWwnLOSIatZVfj4jMlxMsH9v+dEqGEa2a1dUx+IvYj/3FU1n+g1lCd711umSw3/oZl+Wk13ANX4hnCDFyguqAa3Wdc3nZK7BjJ6/LEK5fFS/wBe19oxKqWVZzVJTiLolAmqtc2DyV6Or+G9AVeDdm42QQqxQx8pwKymLtjPjqVEh0+bQAUuqYTrX+1W2wBCzaOsyE40u26lPzSeaI3svo1wYFasod2KL+1m81CY3ppliiDmAFaMjbCycABPuhqlO1FpngYDKhwapikG+3rfVeioUVVdX4V4JyvyOqH/VYJ+T+99zfelB5AmsQcfzAgDKhSE9mruyIX84OGEeP3MwEEPaM/8nG56yb9q+ge4zQCFS9uAIYKcwWy1GintrJWwqhvivcAs/VIq9tLCr1lG4wytMYTRm8USzIc64pijlcRaCFCuUduYTMBCq533kpoK2Ohz/XFwi60mhwgYZNh1cJFJVJwuXWESaGdE4KKuyDfnXUia4Pc 8JdlA9qR woUh9r5e8q4wEnSrdGYESBt0Zkd+IVjJg7foaePQVkHrxKzCRWJ0AWaSJq8vtGrze8nsYLFU9vY0gOaYtmZqesf6J/IeA+I0+51vLLDq9JOfQsrKyNVvsEx7TIpAe/PvTGZ6DAxhRuvRpu1XE2bci067Af/u70Suo/nulR9H4OEk/PrFUVYvVc6IGEQBe6+XnkabmjG7cVvox8+cK3h2nsUE79LpiSaXEYmsFY7+0IDGZL2lstSwPYfIFakVW6ku1kr5j2KMi4zEhXEV9teQV4GhKC/jC6AKt9/Lg7PU659SqrRihMj9268208zwGsfm6/1+i4L3cBKgH2n1ibxnzEsfE1mFw2HQx1fdY3/AbISZbtbG2DsLgBmMVkbLX/ah8WNXdmFVDIIxxcoqOc6Ee7GvIQAcw+HlX8kOlsozAnMRHuuVpR9iJ+Et5WVH0VfZExnUmzlbQehjG2oiOG5H27RP6zsq2VDvYFoiBcFTt+oOOjRentSnQ+8L+6g== 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 | 25 ++++++++++++++----------- fs/xfs/xfs_buf.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index c1ece4a08ff4..202d4432d587 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,18 @@ 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->seeks = DEFAULT_SEEKS; + 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 Thu Aug 24 03:42:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363498 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 30098C71145 for ; Thu, 24 Aug 2023 03:49:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C40792800A8; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEF1A8E0011; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A68AE2800A8; Wed, 23 Aug 2023 23:49:03 -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 9377E8E0011 for ; Wed, 23 Aug 2023 23:49:03 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6FD161401B1 for ; Thu, 24 Aug 2023 03:49:02 +0000 (UTC) X-FDA: 81157617324.01.8C91596 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf19.hostedemail.com (Postfix) with ESMTP id B65FA1A0006 for ; Thu, 24 Aug 2023 03:49:00 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RUQ+uBY1; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 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=1692848940; 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=BLBfuVIlvqLTV1NpcSgdf1IZba0bCwIRib9gRQrC0dsr/ifstSWelllZBtPsj3mEkQD0ut VhUMFbmRV/IesX5DKbKYkk8KEPYS2d9lXfreccc9jM9z5wcIiNUSc+djXbwkBKoOsznScQ EvrXMHuaCPilc0srmPdxrSSCmUm96Ik= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848940; a=rsa-sha256; cv=none; b=uC9IEgSHBMzOXsdmX+S8tO5mZQxDvEfcCInHuXZgeHKFoSvZvGC/uMcNURgtUMCcWWYWPu TpXUo7cYplYDJyEZPlRquR/ExE3x24z/ujSDy5DHosL8+kXMCNT7EX3p4v7Dtq3otmoUIZ BDzIOFhOQRwOqLLbGos3jDzl2s21/nU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RUQ+uBY1; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-68a56ed12c0so756376b3a.0 for ; Wed, 23 Aug 2023 20:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848939; x=1693453739; 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=RUQ+uBY1HAkfCuT5ESlCEEytul9G5hnDaEVThHfRmA0LYTVOc7WWLKd9hCsS1rFFHa mc0eH/7dbqdo9EHUE6UmTighkCrSbumK03htQygf67qHe27shmRyY9JK85wG49kiZv2z 8oDCaIHdONUv8zGek6e3NspoTl+vC5Qq39AmSoZP1rBLnuHQgP5BJHtoJVHrZETVj2Kd egVF4zYA6OPsk/LsQqBBw1iTIY44FdHii7ecD8x2+R4p3ld0ut8Qk1kr8FgQOf8sZhM2 fnGgLEb2c03dR+jZvgTtYnp33H09H+otZtQe2aqa0mDWv5FhBJgI53BmsuMQs8rFkhal gCGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848940; x=1693453740; 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=gW/T7fk3yQUOwO1HXJK4GSuCScTmEVBCzBHrqb8R07D5M+LxXgUB3TMhqK1S3VzfRA LC7XAESUnZkXSoEha+FZkEx4WTUrh5QtOEx2ZztNTacKA6O+2QVCf7jUO3NeYpJM1EZl 1WeEFLz/pPK+bno+YK/2onyR6NDiTlkyYWJGtbLXxzrWW+v5nIGChI84uR0u+++I14mY uQWQNjxY1Peg92W/GOgrLReDVm/IR2+PUAg/EmtbS5iN9NO35Yu9SPa1kAWAxJvA+BR9 /cmOFpbvtSemIQ1AwNIkr/9YoIMb/ejeLk5sbd2oQy3j5p3q2arDl3UeMuXAP0f08ncg rcLA== X-Gm-Message-State: AOJu0YzsvEsoojL2wxjMKncSbFzO/RQDYgpmFtFuiOQxtpYrJY2tIfXr KzMWuygYLnXEYYgaKoVoAKndWA== X-Google-Smtp-Source: AGHT+IFx2iJ97bW+6mvf322k3W+3GQwieeJP9La15RA3gyZWBJ7q6L8OZOACecxW0xeTb1cw72OuKQ== X-Received: by 2002:a05:6a00:418f:b0:68b:c562:da46 with SMTP id ca15-20020a056a00418f00b0068bc562da46mr3997585pfb.1.1692848939719; Wed, 23 Aug 2023 20:48:59 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:59 -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 v5 35/45] xfs: dynamically allocate the xfs-inodegc shrinker Date: Thu, 24 Aug 2023 11:42:54 +0800 Message-Id: <20230824034304.37411-36-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: B65FA1A0006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: pbam7ky8773x78f5c8j9pkusrazskqgw X-HE-Tag: 1692848940-112610 X-HE-Meta: U2FsdGVkX19I+poe8yVNEeeZtmRts/iwgC/jRqFJh6sU63oPVjdW7L+BFl83fJJjjp8FO414hAS9a/D0IF7bnXbLn4crU2hOnHtrXbHLKD100IMwFTqYKg7kmx+/j1Rr9Y4cGjQK3gMClE83bqFgUT9iLimzdgpowUyLWCJaXxtl6UfJItqoJDimJcV1A7WsbJZwrqrmmSqc+r4oAMH+TxM0u0iAmeRcR4+bXZWiEL8uM9iqmi6DIherFNEaiXoBmqphJk+gdsiCzx01qyiRelDWgcAKFwLSu4djDg3uJU/SpxCEuIoXJQdVP3vTcbd4w/zo2+z2lZqty5fAxAN51JikhTsexa1gQAjEGPiJTGw93RPWNAvWnUMvsNKyOOU3nMzqQAfvcc2Legh5LtZx27VtpT4TYlTlmfaxXRxCGMCSfFOvndckawZK0Ztr9IG2KExCALPcmOQGEnzrFUW6LfWHBV7BI7NadxrrehhZAl0ZJq9CXMiHd2U/5Pi7Ax4T5ZEWeBwmM+MSv33977ClIASx5lifswv/1G3lvSbDD69wA2s9DAUVgopHs2yolbh4CClxDFz5Y5N/SJnpPtVpBl2UcC4me0ZqaaeNc9qh2SzHB4tzHPGeKDON9Z6PIO/3N/c9WeEPohI1DJ2Ec1EC3LgE+VMSzcJd/6e9KqgXojpkZdepWKDsxj7DsekKgEawIC9Si3MQhM4YQ5InC5F3mdLqFjiUZ0Pt3c++5xvu0eKj6IJ/ihmgbDtAhxhCt0z4kqaqnryGjE9bhP0Yu6IWvtTFkdIhH5w4aj/S57UR0dE/XXu2U6yxRwNuEPg2aopkffjDzHPhLA2PsKPx0VH2/+9J+0urUO9Z3DDgbG64IjCLEvPOfnJMheNNUfZ+89UUwb9GOfsmAVoMu0yNsDgYisNg6hM2NWgTmeVjq3HyvH4vr5LkaGOQQd6/P24C+zbYCzJIJW+0C0SX+rq5PKy vx/e1XQh /LsMP+EvIdy4bDNEKO9P2a4SWjoPDSE7ohoAZi5gApNCQrfxYGOlWwqpBW70YbBu3tAPyczDUh1OGCMhr5XNr4Xr3qMfmkjIsgmAsP1ChwC2TcJrbEceiMPErI5Tpv8TxV9PoP/65X2Yy8pcuVVf3fW0zsLTxUYlCvwizNpkqWATJnQ9dOxx/wZIjRDAOyYhuLCm9LaeZpFfDYp1T9Qe6hDree9Kc85AeFYPZP+xjMZW/2PwrifbCPyH4qWHhAcDw5HdTPhfCIPQtaZleIkvBwJfNbe6jG9HLuja1EozHPhggEcqMB6Q3V/+9LnV1j3IbynFTkYEePHlHIybZQAn15wh/eQ5N1dBV7AJUfel5hhKvK+Losy1F/N8M6t1eSrBqZr/TiPPk0+ACJ8z6pgLmIAqR2i+WOFKiUoCAC/j4eoUVUyShInhAwCj5nTww5MqDOgLN3DuDuX9aLVbCp2Ipma7xyS1N0OQC5iHhXBLTGm3Ufbn9flqBcYKQeg== 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 Thu Aug 24 03:42:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363499 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 1B073C71153 for ; Thu, 24 Aug 2023 03:49:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADF252800A9; Wed, 23 Aug 2023 23:49:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A69298E0011; Wed, 23 Aug 2023 23:49:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E2552800A9; Wed, 23 Aug 2023 23:49:11 -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 7BA3A8E0011 for ; Wed, 23 Aug 2023 23:49:11 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D80B4016E for ; Thu, 24 Aug 2023 03:49:11 +0000 (UTC) X-FDA: 81157617702.28.093E093 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) by imf10.hostedemail.com (Postfix) with ESMTP id 938C5C0006 for ; Thu, 24 Aug 2023 03:49:09 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CYbGa+Y8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.47 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=1692848949; 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=3h1iK4Tv/ZQ556QR/DSejIrzZMOS74OqSxj2J6MI6fo=; b=b2DY/1egjTZ4BkabIeW+oqkJFudx60kpFn9JzAVB25rKSj7J7wRdZLuHapM5JIWr382vcE Wx0IHqT0cKVfRSXt/JqBJoI5ddR34gmEIit9b0GKPTFX3G8zytLjH5dY77PTabWcA4rb+S lQEKrPpbSRdgmBWmB6u0Yle3ZqNODVo= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CYbGa+Y8; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.47 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848949; a=rsa-sha256; cv=none; b=B0arKq+jnwXI2UCD7+lVGg+qCuIOt+3I3g/c7bZCYOyPZDQK1fs5obvvK6DHJ0F9gbFoHY kgh7oB3hUqeQdMz1eSDhWf6jz99gYAWf2Qd6SqyzNJ2hqr4jUZgx5kf1I0JBdFVxE5nh4h 7zhpZx5WhP12GbD1gwYebioeMRdPQIY= Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-1c134602a55so1134609fac.1 for ; Wed, 23 Aug 2023 20:49:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848949; x=1693453749; 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=3h1iK4Tv/ZQ556QR/DSejIrzZMOS74OqSxj2J6MI6fo=; b=CYbGa+Y8xSAbiirspSWcF7tmTfc3vNTi972ZOagbjS5hpdWO8Auyif7k5iVpc+ViYw nP6fwdi1vSkIpa3diPYPZt8B+J6EPCRiz3RD/Gl9V4iTxXAdE+irsgCTblZY7vQ83DDP H56UI3TSBSN9pNHl8/ieVjseHg+VmFwr1Ai/xVQz5GRGk9w7wHVRkKq0FBHVhVkOR7k8 8c0M8r7cnG2ZyIAnVb616SwYdzE5Uh1SFlIl/iUa4p82hojy069jJBbm+zLf/semt70K Ecv68sXawysZ9mXwaGVC7F7G4j5lraYla7gomg30/07P8unn5Jr6MOZfPgKQ/rZCI098 +/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848949; x=1693453749; 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=3h1iK4Tv/ZQ556QR/DSejIrzZMOS74OqSxj2J6MI6fo=; b=grcW2bFRcL5cRU8Yhu4Fy/thbE67hA5r0222fZQkf1PhNoULJHyO7wEzUBJ73w9emn woIKmYdiK5DUhnITVcP8GYUQUpb+FJV8lrADMZIDkyLYMuW1W7hqaooMkfAycEkyDe3I iZLEYJG/8ajYzIOce4iVLlgc3+zZoFNqi4PkJU7JgXt47wwP3tUjzbAhUME2XP/rH7IN tJ0q3PWEU4WASULA+ud7gzq2KUynHypS3rm2waXXObxt4KTK/vgFyKAn2bVkvluGVBKU hLJxj8pi9jHImOMeqMuy2xs9Rn82f8DZZOM5AUY+CNEvYLyoW/K4TnwZFZ8uoTv3+rbw XqMw== X-Gm-Message-State: AOJu0YwAACBE79p+SPLyeG03u7WZLzChVHypj8UlmwCbleKg9cjKFjUb pGXTGHtLtZFhLVsRdQZBQQ0jw6QK9s15UUzCO7k= X-Google-Smtp-Source: AGHT+IH531Xg0nVzdtVymmtmVKGs5L1Uo5h6G3XB4ml4AX+WBlLfp5F3iDld4B5r5QTgv36fNpqXQQ== X-Received: by 2002:a05:6830:6782:b0:6bd:990:1a2 with SMTP id cs2-20020a056830678200b006bd099001a2mr16258206otb.0.1692848948838; Wed, 23 Aug 2023 20:49:08 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49: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 , Chandan Babu R , linux-xfs@vger.kernel.org Subject: [PATCH v5 36/45] xfs: dynamically allocate the xfs-qm shrinker Date: Thu, 24 Aug 2023 11:42:55 +0800 Message-Id: <20230824034304.37411-37-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 938C5C0006 X-Stat-Signature: mrn95s5zbjmf5eteqsfzugxpn57grytn X-HE-Tag: 1692848949-593707 X-HE-Meta: U2FsdGVkX19vDZlNV+UWcS5MYFhVjg27AxQk8FRgJShoLxjO/iJs/CQGyo9kCm+cRZap+FGLgk3g8rT1zxkXvZ2PQ6OyKAoskhs7VX1dSxjpsz8Txcrutra55r+oOce2Lzv5MFcgy4bG0xveodnr32AXEORfc3SGCmXhdjBgCfbb1fvbzljXey7FV1z2n8dG9phNfmR9T3rimylZcnDQrRq7B9TYvCZdSm1hzzR9CaehANJd+d7qBaKaQT1rWW5eqXg4gDz0Ra0egOe7s3m7kQGI223+Db4XbAn7CkA8LRVl6WogqDpGT8xSxbJVNM+Neu2xiyOiJRvFxAPgW1pkfg/X70dyfF7u40BcNq49vrDKSqfDvVcFG5Jg+2JiXW4sDydrQE+go399cjx2F/fxSo/aQ1PbCpRGFPHyUG0KBNhxPd6zwX/B3+TGHHgw3qhlKYqCmBMFVHoN3cTa73XNb5C5/PjUrXRVLA0rrzrWmj8kqvKcnuv+O2eq3tZVKEjHrLWCHi4fKYbXFexJpTTgkW6XJMUb8TxvJSXpn0e3nTh+fPLomQOpwv7r39UfAwqoSnN394tVIQvo2BOPn5RQ/6ZZkSgPgVCMWbml32eyrcFbByJrWcuLQqWP9/5xKYN1fFkZGqnvNAdjqskAxIEiz/qS2PGUbjtHNdho6OUMj/c7p4uTiPNGJ7v5I32D9j4vYOfqpPrs6bWQ4Dcn6r5roHCYEyL+UkCnbpMN7fL2ZgLCkaf0uxul6//ujuc2wRE+ejwy6WF0+54HbNaUMEhDxCqhgrWwYBKbPECZzRDj2bfUzTNjVYKwqyNDWDSWOJkNhuMOzgGebVV1V5QQEdY86vmWUUQDdPKSIYSLEja0oqbZGRix8mrY8EilZ6SEHtO3XobrS7PcvtiMnFAlYa8gcK97Muc5RhcVAEwAqKoN0rxaMGdqKrDMXGxu6Aq9oBKhXYuCej4pEcagR/mTuz9 gbUrFI2N Yn8Qpzm9WLOFg4Pl+VQqHSGM0F8eD8Qrnw1PhyQ5/1yws7cPFshUPbjAN0MY5mkY4l9Twrcj7AUtfHrbvkCJq/c/o+cwi4DtDQARkpFpUvp/aYriXBYYWYTXWbl+Bi12/khDLC14nFL8Y23fvdHkikpA6LhgPoVxLmqQXZspXUjbeQxYXrxNX3IT98uFH8cybcmE5eOsavyajuyXHdPD7LCCnQMRD7X7yId4AbNYWic8SX9Jkb3ZGuYRmste+0j2FC+4NAKVpi3xCTmx9xbG0WueJ1kcoVebEfcpMbVR2dRi9Y6G2KfxjlyLZCkawDVjE6eA02zJlHZJTH3wdxsMgqrj2O510q6GUrWOLjIUg5HvIBr7jvCiBoO9dcCpfdZgA+k+uvEVQ6gAb619aqNm3PUV7L79b0RRfEri782nr+E4qXL64Zr/i86YNfRFCyL+tvYyHuiVFoLbG99KNbdy19KUgYs44pSIyD7+XsVJXFu1CM0zNS/QtZFfPzQ== 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 | 28 +++++++++++++++------------- fs/xfs/xfs_qm.h | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c index 6abcc34fafd8..15ba23f11271 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,19 @@ 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->seeks = DEFAULT_SEEKS; + qinf->qi_shrinker->private_data = qinf; + + shrinker_register(qinf->qi_shrinker); return 0; @@ -718,7 +720,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 Thu Aug 24 03:42:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363500 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 2FCB8C71145 for ; Thu, 24 Aug 2023 03:49:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8E932800AB; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3D3D8E0011; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADDF52800AB; Wed, 23 Aug 2023 23:49:20 -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 9B1248E0011 for ; Wed, 23 Aug 2023 23:49:20 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 71E74C011D for ; Thu, 24 Aug 2023 03:49:20 +0000 (UTC) X-FDA: 81157618080.06.2BFEB94 Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by imf17.hostedemail.com (Postfix) with ESMTP id A7F8A40002 for ; Thu, 24 Aug 2023 03:49:17 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L7x5jXCL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.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=1692848957; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=1w9WNfuz66tJj6wPdlPQcLHTlTuKyig1N+p/PRbfr+WHHWNRrfaPlI7AKzW6DoVlnGMvik dqfh5HFbILEaCYKfKXC8On/DNFf12d0dVPcRwEDYcc9TvOwe26SLRVT1cpy4UJKGF3zhJ9 XCz4LxqI4zZxJ9VTrrpv3cYfEaAKX10= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=L7x5jXCL; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848957; a=rsa-sha256; cv=none; b=EJLTGqWTr80T4Sjyb+MP4pvUISORvyX9NC7tLe5FAsbgo9cQogIuXdHrJAfxKyNk6D8/pR tKXHekjZHvZ9jV6fixeIhASKSF4iSJRU60gIIiTlETQa71m/m3r7r9mSmA9SSlArq5GygX kc77zukwSiTikXw5ssdLPdR99cKY0fQ= Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-34bae11c5a6so6422475ab.0 for ; Wed, 23 Aug 2023 20:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848957; x=1693453757; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=L7x5jXCLRGUnKfPoBNOZqmPlrSGKRjlLEl7C6BxvHVl4niA5K6OO+mhnHCeKV33Trg +tz2csuJvDBNqrKXB6/XcE2vyYga4ztF29T2SN17wG+jUVfGj/XDICzaJYljRr5dxCYG Zm9tvrOY9nQ5m3dzv6Iorm144WDh/2Giohela4lh6+P/anbg+SrBnxyEIv6MLHI2yIeP XULXQeHly2RIA6FIjYfl5Z7hCEVdjI7+MeoWo9KLOjxdk6l1SClYS6K9jnti4St8NGny 27VX03IgH80SMo75G/G/PAhxd05H78j0nGdfg90bK5XQZyVIF0HyYteEvPnP8OTgORus PfgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848957; x=1693453757; 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=8WIyE6lot1VZj2tUhISd6JoXeKtgl5TACjSye1MYJlQ=; b=l3LEhJFhufOinwTUNWCL/O6qim45jthhOA3EM3PNCwBwbsak2K5RrUbLk+azTOa9MN nodqS11zXu4N+TGpplHNzfkbYXG27EwDm8BULQ0U+R6fpZpk3eXJPL36xek7vhXV48pl JCXkDUJ2JZzDVX9WEcxKEjWfYBxtwDxbpg6Dj2nuacRp8Ggi0kM49qyKimotxdmP2pH5 rs/aeBXZEFRdNrhpDVjVBjD4IpDIi9dcv1q8LldXwsX35qZ/wVBJgKl00ISw9T1vaCND W5nilQYgtbWhS+5Ku/edtc96fjuu0n/Of5qB31XuGc+qY3YYUOIkO/qXxnS2Pd70WSBf owtA== X-Gm-Message-State: AOJu0Yx21bFd9tE6lX9bevWA6swIGbHtTLK42McpqgvGokXI/81I2FZX XdAZbDHdbu0D2xw9t2uuDxt5dw== X-Google-Smtp-Source: AGHT+IGm+Au0wCemT3+vxgVXGUpM4u4I3YXm6qtEhhQvyIskTUE4OJ/MtrbM8i5okDP0p1r/eUsjCQ== X-Received: by 2002:a92:da88:0:b0:349:4e1f:e9a0 with SMTP id u8-20020a92da88000000b003494e1fe9a0mr15611442iln.2.1692848956912; Wed, 23 Aug 2023 20:49:16 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49:16 -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 v5 37/45] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 24 Aug 2023 11:42:56 +0800 Message-Id: <20230824034304.37411-38-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A7F8A40002 X-Stat-Signature: pz4edd45gxr4exii7s864ydhhnz69nwa X-HE-Tag: 1692848957-533713 X-HE-Meta: U2FsdGVkX1/Sy2gRCK/pV35OtfN7rYmwGWS0P0sW3SI3SBT+GYV+2oeyivxuVlNNCx6hPXPiXM2RVpb5oF85Yiao/qtpzigIWeKnOm5wI511Pr+dnSmTDNlOjUxUZhy2jUt5v/hUWZ6vZCMRg94IbkyqxmKuPiqJRWEnhjqcMFo4XmVUmwk5nCPn4kqwilj3QrMgZTpQtO+E4BzLfn45tjRLiQL+Mir+4c0o3oS14b1HbeWm1DiD2lJu857ev0XLy37ZEdpvUvmTrkUK9/jtzMCuMZzcdU0FBDlo1sMsyzOEYgPj5QR7qiGTolUjfoFxz5VH1Z12UXw1nfkqqQUWkWUA5VuYS3P+q9j4giwfrho3huyGl00IY6R/80oGrKrt7EHpHSoNxZ9sGqnnEpT8M2mP3utpvHUafGNpfzq4KfyfRMPrYZkx7Te4ZqRm2YhR4WnmllQAs7VVi2OCWClY73cVU+aPkgY9Wv2v1y7fReJFB36Kws3x5xcIi8pjiYMh8Sf2HbplSAv0YZE6PHFcKxOjoYsR9ieKM3izekWa0KX7ftptPMojgNSyWalVlFr0ByimvtjnlzuCcaqkM/PuiXMWNapSAHT4duBUegQ4QRpeYbS9vAq2Ahjpk5HlnPrqdh8mvNi0hWiBCLZiNvMvNeEgrU8CZxYROVnaWy74uUT+6ccsnSQKLy0qHZLlT85BohL0arja6iEoDsRS6xyKyppvUCT00lfnChKdI0Me7P6YvidSYg2dFhXJdq+h2r+oQoRhfgLVtKo2jKWIo2lx+uBt5+ON6MuOVfv9WJApQLYrIZrxcwuvBWuCG6BBl7gsl3t5ijxak4NWR5u+JtyvIouJ2ZlJ8GgE6iqJgjD/aiCT++qDv1wPISOaM8qsQ+s1s/mVJjFTw87GFNV4Zxe4vMXWTcageT2cLjzC7P2AGQEbdMbAeWjaSMime+kX/rDEGAye3FLHXLzbnFXRELu xMSCnYus khkLMdF2ThjraEZgDYC9xGg2Nh+n5AExaG50HW6/S/2GY2bMtMslZA3fqrOsK7cj1tblxKc6hpO1wftJwv6W/IZE6lUmC6RvoZuPXY3F/fONnK7MF4RCpNUjKQHV89Ncg2/QeEihYB7PPOgtwcJJGgk8ji9ORCSYFgRxv1vglarvFrZtPcqKPu8emkzbkduyVhdiSpJlppeP2Tl4H/N/ZoWiazg3hF+A6GRg6qmCu6tNwLErX6HGZaLNbaWkiQU6DUDfxb/S6BbaQUuCUM/U+STeCaHdPEEazIqqCgYoEDOs1yA4fwO/i3MokGcTg2gfjXYw+A0JAzp/m1NtoohPlY8DfL5Iski3sZNH2SiJXIXAETrylzwai58ht2l4XkhTvLoblMVW0g85G4QbJYRJ2PE/Q4Fr+KUV4hcbhWwY/zYckq7hqEP9GLzGW4SKbVwcbp/LB/5o2JoWUymxz9gPa/57MZKQ7niQDEZRr73yIkMzf0ZdwlZfqMs1La6APC3Sj9jqyK7ptexfVEtlo8hIIiIgHurRu2kqtRxGDSorNKZQjS9ozFWRFP9qfh+WDPpxcNx8M4h4uZ1ZGxWM= 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 CC: Minchan Kim CC: Sergey Senozhatsky Reviewed-by: Sergey Senozhatsky --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b58f957429f0..1909234bb345 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,24 @@ 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->seeks = DEFAULT_SEEKS; + 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 Thu Aug 24 03:42:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363501 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 64E18C71145 for ; Thu, 24 Aug 2023 03:49:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 00A5F2800AC; Wed, 23 Aug 2023 23:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EFD878E0011; Wed, 23 Aug 2023 23:49:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D761D2800AC; Wed, 23 Aug 2023 23:49:30 -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 C3F388E0011 for ; Wed, 23 Aug 2023 23:49:30 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 938688018C for ; Thu, 24 Aug 2023 03:49:30 +0000 (UTC) X-FDA: 81157618500.07.0DEC44E Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by imf10.hostedemail.com (Postfix) with ESMTP id CD222C0003 for ; Thu, 24 Aug 2023 03:49:27 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=I3XSiBJx; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.50 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=1692848967; 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=4pvJpzZ+JGddoFyhhdTQRQhhn5Ey+9a9fh8KQ3jqI+8=; b=7Z7v2p3bVs0JvtqTG1AL80KxBaZovdvUpZze3ibxB9zZhwU/RLAEfkyu2YnvoQntc/RE06 BpMlAZlobVOu5scPZtAflFEGUXVDG6OmClFEC6hfMkDPAf6G7T4Wq9DfBsEC1rKgGk2N+p EFiBtd04GBAbfJ+Bxb29ukosguTcAJg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848967; a=rsa-sha256; cv=none; b=IIOrx3Ztcl2F9s4HaIKXfBy01SEXtxRaxZKZJMp6kJIQFyXrv91H1aw6eH2PfXbUV3P0fO i0XKCsBQcwK+7zX2XHI/kQQayp/1rogxoYoTu/BMAehsAytgE1uAVtDe88vqsCYoTp5MfI xU9CMK5q8pqN2SKuvqjWgoHG1xFTcQE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=I3XSiBJx; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.161.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-57328758a72so32807eaf.1 for ; Wed, 23 Aug 2023 20:49:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848967; x=1693453767; 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=4pvJpzZ+JGddoFyhhdTQRQhhn5Ey+9a9fh8KQ3jqI+8=; b=I3XSiBJxFGTyV5v72oW8iYTiSCqWs4HZ1HZw8oZzwqWxapAobrNgMr8upBULWpii7y VR2axtb8bjGL7XqnnQpdat9npGu/rRtd1Fgchh92o30XtKGQss0no/eGxWyQbTc1WMx1 1YnguI2ZWqaEG8ObOf/2A9+7l+bPWm8QGpyq6VNnu7Jm/2nad6x1VHqoAUYkdlXiNgcT cEdDi8dcaQystHhf/K3a20Y6CNUZTBRKOiG8A4F6nPXP93ugh7YPdHiuGUqSFmHRe5rI jDI7/ioUA3WKm/fBXgl0YVy2WWa330giSCtLLFW761sWac9t2hy1dXUh9fjJ5Q2xW36a 0spw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848967; x=1693453767; 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=4pvJpzZ+JGddoFyhhdTQRQhhn5Ey+9a9fh8KQ3jqI+8=; b=XREJn9NqLZ7q+XUvJkEE/Wi8WZcAK72We5ouFZSoXAi6WTGnzJY7MvGDWmQpPhcOyq uMjMi9ZnkbHwlCPTgnJ/TuHX+ia2ennJ+kLSlqMZ/LVs77Writ1YMSo1sDyp7DaCUq1B UVeeUoFZQkpyanCFosx7BEWZL04mgB89b9rq0cFIwZyTSdVBwltoGEtiwEOVMCy62p61 PmXtnBDCasiryGRNqCJGetQt9GpMpvkqYw5BXkmMasnF5KR+ruUVrj8ctCYCrSnEe1Ty +qxPwyWX6SM20fKWDP23p9Ff2yDlXL4gIt4kBCf7MkGWc3N39wJpa+MxseeE+o1RWnr7 eU0A== X-Gm-Message-State: AOJu0Yz+hsLFs2f8Hsuww2KM0mlbemaU7gMELN4KtRd5TKwafG82dFM/ pjInUE0vlucv3yZWvvJsQg5E5A== X-Google-Smtp-Source: AGHT+IE8LNv4W4yBEr9dpKHpPUllD8RN42Yg87AfWyhrznuN0/qSlKWFsLw1CNWJr1EuA0HNZqRQ4g== X-Received: by 2002:a05:6808:1825:b0:3a3:a8d3:e01 with SMTP id bh37-20020a056808182500b003a3a8d30e01mr15808941oib.3.1692848966929; Wed, 23 Aug 2023 20:49:26 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49:26 -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 v5 38/45] fs: super: dynamically allocate the s_shrink Date: Thu, 24 Aug 2023 11:42:57 +0800 Message-Id: <20230824034304.37411-39-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: CD222C0003 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: osg8q6mxw3pibeju4b3rj196qrztig77 X-HE-Tag: 1692848967-579469 X-HE-Meta: U2FsdGVkX1+PPaZ9fMCUmzg7EH6Tr5e9mFD8JjpvGToK+dji4T1JWB9Go6EHlQqSaCqx6D3JuntPyTOnXRG5u6vHbiorToZhd816AQfdMNizF76CsZUvxlWE/GW49ahhz4AFKkcD6z1Q4VfBZhCI4f+9jhGjbvYQF1OUXvPFslUGrK4WEKdFeFiJUDZMKT8ti3eeYi3lpp6bv5j/4v83sLq24i+U5qgaQwDPnBCuNnTX+goQH+7czPS+RzrQaS4YQ3LSdHOOJwzt5xCZOpO34OHMjY4gDniAXnHah0BwiRSepLWk70pywXIoVrc/ShnfylfELxZY2iHCQtTh/msIHOCmIG/WnFRpliadMji2TNuYedjWO87CapQBB3fx9v0lU8kGsTFZ35T647H6LjQDa/+Cbx079ybWpna1tUigF7r22lazaxJt3Aw6m/2M2XOM8JRi8JOAA6wKRzlptZPMRqJlT/SoaUo+i0e0WZ1epPGhaAVE0rRjN8Est4EeekBi1E4laZ/OVbB4PzMMAg56QGde9n1++/Rm3v5udBt30T5L1C2QUB1rzkvUO0daZ5J0mHtHsWhvR90xekSoIkR9jO8zpRqTtI1qfrCnI98X4SCMlLsOhhGxwxjD4cL8P/6c0GS4cxiITS0wT07pToUHVbWtOWTaBZxfTjieYnMzvAcVqn0xuBdYnfuyqsKHlZJLmp3JgjVCBq/eOZmZQjCWyu5nlcYvfQZhTGHUD5R7tDwivwCjQniIhphonGdvqkf6p3IihY9LM6YyMfrkz1dRZvmAXWAY4quF9MLJum3X/5V1+heOVcNN2a6aLT7U5qu3plYm3ZbxFKosuNmmznlcss60j7tVn+f/u0AThAf/qdxkNN/VS+aU+Y1nPs5EIBCYL/qQ9/kv0s6iN6Sor8biDDqrHQJkQIhH/LAB4jPtwZ7Hs2g43wNNEkjp40oV6sHBm3636WKgcp9HmepawYc o4nr92k0 JB5ec8DyI6gvCvRt7rbR/640dpZ5ejEResPBWa3TImbcaI8QkKTLalRNeJ/AA4cZjlBpTUv7g/nRsEws7+zXrlIWlM13dCzsfWwc9kbxPe/x7xjoAxowmQR6Ym8DiN4IwLTd8SToodPj9Q+anU8Lto06BUQ8dXWiELNBToG5ri/aJ5euWPw3SP/UgGPPCxl+b1/FhMzbc0NsrwFKlVil48hFnikuqlU+RCdtUe89EtJBycyz61bLl6/ytJliZ6BLp03Ezmb1QDe/VcG8X4idtR8qiH30WBHxbBG230peCFP7fXGwp6taroXTaYy2DPLRHtihMgru5HSu15vs7I5l4UCCLbLp5OPjgwXa6QncTGMph10RlwDkdPV5l53Fo7e8VRJO9mnzBR5tprdaw1MP8dJNrG7d+WiaJvw72282lb5hYsiVBqrMTjc7wYUM9g3UAS51qU5VLDvYNEcNANZ1vO0bzkean3P31h7OxL7ekVTKuwsBiy2QCfBkIcAtVPKJQWsw5lbICSF2sZ0BeqLWoZ/qiersZ4UsW+7QmKvg36nMnnhB+bB6ueHDnqAIu9649lHi9ov7zBDJ4guge9EK/AsCIQG6gNV96PTmvj42ftvCS5vKQ2XL7LOgfKxLrQD+L7QCJdsZYg7Tzb9uVSBYLnmF8gmhZnA5menNO6z0ZPcUOMGu1RwKUAmFUrC+i1iYwhRErovppfbbLuJjyrOrdLvaMmK80gHEEJN7/mYDTmIAik7HYpb3H2Jofh17Myt9VQcOE 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 --- fs/btrfs/super.c | 2 +- fs/kernfs/mount.c | 2 +- fs/proc/root.c | 2 +- fs/super.c | 34 +++++++++++++++++++--------------- include/linux/fs.h | 2 +- 5 files changed, 23 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 719b67cd4a6b..5ce0c51bb445 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,20 @@ 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->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->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; @@ -450,7 +454,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); /* @@ -808,7 +812,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: @@ -891,7 +895,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); @@ -1484,7 +1488,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 c8ff4156a0a1..82a0b5aca045 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 Thu Aug 24 03:42:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363502 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 EB45AC71145 for ; Thu, 24 Aug 2023 03:49:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8204D2800AD; Wed, 23 Aug 2023 23:49:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A9E48E0011; Wed, 23 Aug 2023 23:49:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64A052800AD; Wed, 23 Aug 2023 23:49:38 -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 505F28E0011 for ; Wed, 23 Aug 2023 23:49:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 23103401B7 for ; Thu, 24 Aug 2023 03:49:38 +0000 (UTC) X-FDA: 81157618836.05.5B51873 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf03.hostedemail.com (Postfix) with ESMTP id 5B78D2000C for ; Thu, 24 Aug 2023 03:49:36 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TRSLMXdP; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 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=1692848976; 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=qmgoIAslokneklTFoEzEoFMrIw6hl8ApjrQYf+i1Q4o=; b=ZZjhLCnhIUe8mx0gizydpnZ13FwRhAUwqkC5DffOe/4KEwdoKHUHcurhbTdI1U8XhJd0vI 47UiPs1HDBUQcmY+VJGTTel3tOgm336Lr14g03xFYvMuNmQwaMaYy2cOnGyBeKGjeo0Cus YwU3kbmsV88LVKlKN2QmDM+iO8S0AoE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848976; a=rsa-sha256; cv=none; b=iVWguqcQElTtQBP0gMYR/yyOdDtNmw94iGZsFqvogxXW65RJyEGRACr5neT8YhddVfpd6b UXT5ZVb9U7k8lJel2iaNwQ0Zgpdn0NJI+xj61Ubk8QiAOFWBEbFiymxeBNT+dqGoW4wDyj TiCOj2CCP/5vMHwxSt/c9oZJfHg/Q9I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=TRSLMXdP; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-68a32506e90so1062960b3a.1 for ; Wed, 23 Aug 2023 20:49:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848975; x=1693453775; 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=qmgoIAslokneklTFoEzEoFMrIw6hl8ApjrQYf+i1Q4o=; b=TRSLMXdPlmwf9YEXYGnxt1Er7+vIMxGkXRFP+npDhhzxHYEZrz2fsp/CNMu5ekgS8P ZVQdZoWjCeWSWoSX0FD+SMWAvhqxdbo/SUI6G5epNK71KMQN/I0UgyD/TP8vnBiqWa2F dpLUodo7woLZUS/OgUd4n8LBwIEnnIfgsZoYtadSO95/PxsyM3N0R5s3QP+YCpStQDf+ rB0+AD5yGw6voV92ne0m7t1cRTXRUFv4aTU6ocrlUAzZSMJTUFcezv4BNlikDZYgFqz5 CSIkdNIkvPbpmdBFPSagV0mGjdvOlzGd8rMQx+ZM7/8xXDCC3lla5V3wstPB0iOQMZLM pBgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848975; x=1693453775; 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=qmgoIAslokneklTFoEzEoFMrIw6hl8ApjrQYf+i1Q4o=; b=HP7gQ14q84a34LwwAlg6mdRkuFxLte7Y1iBVEI7fY7CamFS/o/8ROxKnKwypJvWJZ+ AnZuh0kMqCVm3GaQajyQnYaRcByXHURLEORN3tg1fTOB217eggsYU5hW7coBUJEwd4lE Uj3dWuilbTEJDhoZbLpSM/rWoS/5wiWT3r9iDxyitYXvAcLHrCKSWXNb6fs7n495cdeR ExQ9jcW2o1dGXJnebHPQ4FABUugJW/Y7dTumrS4tw+B7FZQmk8H8GvuI8er8Kexwk7bW yr6I+EU3LfX9Cw1t2yGpJB7wHfCNj6w6cJ3hPnMN/JSxDk+u6D5gNOBPSdvZyiXh4P61 Z2lQ== X-Gm-Message-State: AOJu0YxCgodz9jt20cdm/gH6w6hixjtInoqqRACJIzyziZztHtUoL/9u 3NXfShnMQIUfvR4JF3UIgZiYug== X-Google-Smtp-Source: AGHT+IEnL/536NpETn587uFUKIsPyUoKrOXgr9b77JCUCWQkpC9m8Or3mJZEtRjjogndteOSgzRUYw== X-Received: by 2002:a05:6a00:3107:b0:68a:4bf9:3b21 with SMTP id bi7-20020a056a00310700b0068a4bf93b21mr11175503pfb.0.1692848975313; Wed, 23 Aug 2023 20:49:35 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20: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 Subject: [PATCH v5 39/45] mm: shrinker: remove old APIs Date: Thu, 24 Aug 2023 11:42:58 +0800 Message-Id: <20230824034304.37411-40-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5B78D2000C X-Rspam-User: X-Stat-Signature: 7mumbzkzbj4cu568qqpyej1j4uyq5iq3 X-Rspamd-Server: rspam03 X-HE-Tag: 1692848976-620092 X-HE-Meta: U2FsdGVkX1/5fHodna1g/EMXkHRf/uhvCLQBSu8j2psDjrfDIR8pn0zGy6MgMvP9w7g/Q7XYHrYyHGOntqPTaawR91f10QEzpGaiDnXUEHPxdATLB02S5xpiBrbEYPB5H0IaY3c7bHl3Uzw2PHLRoGsdbCB/iK1dctno+xAxvabm8ZxJaACMJCK3tURhGE0TeOHtQAixrPIRpgbPC+dxYsiRtk0hvnI7JiK+edkEtbtNCN+GckjThikR5+RWY978zMWUfR9/1fXHUXBgH0v24XXBLPSkNcT25JgqcuBK4YbIzsNS203w67517N2UEvh7ZIJ4UNoBuEERceee4Z5AUhu2Mrio1NDuCA/nj/9V1njFolqGvzmadbtABpcaMs4g354RjJUjffZgGdw8A2vvSpwOKYg+kRlQtUoPWKMpLhApqgsHyRL/TQUURd7rMKRqrYhWFZrONLA2BUBtPJo6rp2giOgCohVfULNcS3p34Ug5BNamt82vaBsY2YCkBjzk0RgX62XAN4iTM3EP3vQ5akEiiNIciaxo7VGZwAiwWiZsEM9FB5i/D3v7ohdh1iVF0e8z3z+S2VGjrmVLmqtRG8KAdl5NP5jGRScjf0EFUjFufjt5HPlrbLV1VKIEel7iN7SglWzqb+9AxK4xIpNCgR/7tK24ha4aEUCjbmPJRwWUf0THMhL6Wwzz0GUt0X4f9jxHgKHzapDbxr1ftXp96/FF1mAr43RpEMmg6dkhIyUzXj0MXEafSpJ/KXHqVFr84vafw9cE2hNAADhmNLhk4EWy+amgfioBdKV73APlRFKi4gEM0Lkm+OwrpfmXJgtcLNfH3QGF8socSFwkn55yqajA3AqZZhPiqRV5JhmKrrvWotoeXYev/e2+/OIMzrOuFYvPBpRyXR08EU0ZzVzoasFVPPv0oYhDp2CZuGuAk2pk6c1VVOgxX7XIDNJrrNbki6ai5aRuj841dcbW/gU CHB2gkmp HAIvHmDnUKWBaXsEwh3Yw931NYo3mg+gIDS4i1Tg0y8Wrhn7gZy4Uz8Xkct/UNsPWrqARxXXbtsMvmHPsSeliu7jYJs19DlxZw1lBPgNV3g2LB0bQRMzNMKxp8BZ3eMGTZgtNMu04oNY5DPSU+3MSr3NF/5ubdehCWkgpVa86mXFeGSI9lsc6uz5xjyXiXzbg9LI576XH7NCe5m+lc/DtIfBmv/ZS6CoKTdsdlRmnm7/2MlkE+SupBVhUIJH1VmQKJ+KIKyN58U1aE9SnGzcIuPXVG8UcVWekfV1LKULnMfHrY7yIIP4P6GnTpUNTzWWe3+MZJ44BnNkq77G3baKx/fSNTTXiH/yPbBPvFOudo28f+50BRt69p9VllZKpIhroRZ55JcgpeOaUuw5JbFeY7Lxz2WL1ENw+jNs9 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 36711c5c01f9..a27779ed3798 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -650,146 +650,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 Thu Aug 24 03:42:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363503 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 AD47AC3DA6F for ; Thu, 24 Aug 2023 03:49:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C9902800AE; Wed, 23 Aug 2023 23:49:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 47F9A8E0011; Wed, 23 Aug 2023 23:49:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3160E2800AE; Wed, 23 Aug 2023 23:49:47 -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 1B51D8E0011 for ; Wed, 23 Aug 2023 23:49:47 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F10271A01B9 for ; Thu, 24 Aug 2023 03:49:46 +0000 (UTC) X-FDA: 81157619172.03.BD121AE Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by imf05.hostedemail.com (Postfix) with ESMTP id 15259100003 for ; Thu, 24 Aug 2023 03:49:44 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IN9yNP+r; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.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=1692848985; 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=+gxi0saBRP9dXN5RfxPPTxXpEVR7Zm5dcLEfa7ZFZMw=; b=hyXn3EV5ICRUCSm5Jb1lb15RYtc6IysX+i2z70/4s9w2V2vytV98Geqk5SXkr4Py/BCSek QI31gwIUjT7euVFz0PdgWb2sm+ca8lBOqsGa3FFVGvYjd7RZe/5Rcpu1Uoo8q9sWVVUX+w zReRFmw4wCG0V3ugdG3M2QQ0tzWfGG0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IN9yNP+r; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848985; a=rsa-sha256; cv=none; b=f5AE0uaCIrZFqs8JU+M/U6EJ6zUnDJh5KrrcsKa42+7fA+Lz+Bf/jT1woZH1v7ak0cPWhl gO/eHBWrS5cTT+iBnyO8EJkm1SLut+lh8z6HMzyENbQ9vSJ4rMSfB7gZCkfxFWJAhxE6wR AOV8AUXpG9FoHjDYpxzp1zg80eIEr8A= Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-565b053fe58so828209a12.1 for ; Wed, 23 Aug 2023 20:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848984; x=1693453784; 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=+gxi0saBRP9dXN5RfxPPTxXpEVR7Zm5dcLEfa7ZFZMw=; b=IN9yNP+rd55Jsn1lNbAWCcqB0a9NI76Y7hMCrPB8Srq3S1Ytm7SgyU8eqKXKy95dwC xRCT1QvczZqPesylS4hp+xGBWuJg3UQ525C/ZloxGMjubmvhFHcAOKiDRpz2LVDnf0v7 gOSWNlRtxAjmtS/4ZsDsGeTNQLLU7xwK/DqGBw4FC00LGd98Rlc4a7ikPc20Rogef3Xs sm2LuWdakqCU8O/wriB63gC3BQj+qm3tMz2T5mEQgzSIBMBIF0Q/2HC1HVioKa49jwpR bEN0X7WGMzrw8e5QbBKwdUQGtelU8M0KTZ7CWhFVPqYFvMlY9u/egYbkOHjwwkjk7wt6 tYdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848984; x=1693453784; 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=+gxi0saBRP9dXN5RfxPPTxXpEVR7Zm5dcLEfa7ZFZMw=; b=FMGewp3MIDr2e7GTKsl/AI6N0y/Rf2KI8JMk9wGY1clvF0c/KmbsnB1/bPa+bKbppK AJ63i7JpHe3+u1fQRrRVRf1hlh2Nfe3Vj4PoFS+j/+j0CJXTVwYRRnGMOFiF647EMhI8 ZAu9Rdgq2ip8OEy4+dzsaEOQhKbeb2TgYS+VDKETfW9RfkDxpEhJxPtJ3g9kuD9qjQmy CaVeTHh26IBBSdPwbrb5tuZeLDdvivv0lVQaUJ3i8dhyyQvZsJ4EY4ACxzVjKo7Ixla2 Cq/OQodMEGWMn97VSsDphqwmxpbSdCZn5enFVmJ0r5fy+SbiyF8B12AfvfvezgJoc7dI Sf8w== X-Gm-Message-State: AOJu0Yy5ysPpKYNhpk74G/6T1E2iSmL7fKetK8MITSSmBBeMuGVHg8cu EgaWhLpUfewQOjcjfDm7B1jDmQ== X-Google-Smtp-Source: AGHT+IGjBKNPzzU5l0cfMIM0B1lPeWeFil+E81E9vzloKzgt8oBxA35DwPTCLQo4ZN32KjZ/+hydUg== X-Received: by 2002:a05:6a20:8e19:b0:13e:1d49:723c with SMTP id y25-20020a056a208e1900b0013e1d49723cmr15390952pzj.2.1692848983918; Wed, 23 Aug 2023 20:49:43 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20: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 Subject: [PATCH v5 40/45] mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred} Date: Thu, 24 Aug 2023 11:42:59 +0800 Message-Id: <20230824034304.37411-41-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 15259100003 X-Stat-Signature: 99wtbqsnxw4q6d4egok6pdnkaxri8orp X-HE-Tag: 1692848984-739828 X-HE-Meta: U2FsdGVkX1+dft8Hy0+ZZ7lTX0L+1C7ySYSeatWhH3BvR3Pj/A0DGTB2D/hGTb3EKJ4KGIQEmpZ8m2vBsZNfUBMmV/93klUwB9gyx09Ope5HvtK4E9m3DKqf5/9oOi+dIqaU/xBQd9sOoDcuBwrmlUdjF+5riXPC53+8Y6HpuRGBgS8wSidA4dEW4KUTYJWjKbSjOtRxxJq1KvMh5Dv55ZfChBuWe6t7NJEDj4y6VZc+UUjKQFD/uBRYYBsaijsyZpAGRiK8fOvbRoAVRFBFnbEgMqeY/ne2Q2QpUNKj/HtH8IBDe9B1CdJfJ1DTKegZwbJ+/hXIJkW6XmRY9KRfcDIz1Ncez9NitBF5K28B4ddf99qiOGQ5feWE8gurO/CA3DxBX6yoOYOEl9+sSgA/KFZS4BE98MC2aylN9Bvhz4m/6BaC/JA/QmPrzWi1FBRC8GUGpDbBXn6np9A+/ncz/isjqjs3Y1edvqQjgiftC0Z8UeZhjBxFh4fI4THRv178PKFZzsWjOXkpMZUFIPh0sqSl7tVpWFMku9tEFJMv6r04VH9RVt054SJ8yCq84364ITecMcnd4CZIpD+8ScGiZ/r0mM+vhB1SJYc9eFLNNk/RIYxzz3/Kck8mKdMosLESDSoxtN7GskyFeHACG2gPzkFzhAmGAUNsGXUeJ3sWAPvJhAW8Qieq/aXhxObjUO1UHKZzMnpTfyGDqLu+qUNtssmnWnOwO01PdOh2lj7IBvjwVZcQ3/bDBEAcuR3jmX8/liI3xL28yfFLs6ghlqgzU6MssJYF8etEUSc37ORXbCowFAbR/xLKIOqqccZn44UwAufUAUhUBc2EzhpI4otqQ9NWKLV4zCSkYXvm/FX2JZj061g0JuBNwFG6mvumZ50uEFv5n9TvxSJ8qbkuTPGv6SjF1LgJi99c2EZSqF4x5563vhZOJx39Cvmci2/KaCi9dKLkDZBaZ93yxureugD wJwbazbA PUDtvwQqKjLqpv+GOHdDX+hNEd1MhKxHdoSohBRSLTFMblKpRMZ3WQZM53efxZfLP0e1d1OXzosNFYmTFLq/+YMLTYFZGpMYSy9B2glrichct7GctMApA2AFYxvCNNKuHi3akQRONYhrcIyPhhRNZQcOCPY2s7/+uA7yRcYO8eWj0rSUGQkayq5Mk6x2R1njzRA74b5R+XBClIOJmcPvJYKS6MBNlJ7fSZZEcLZmVBuYJhxU6T9eRvI/hU03PEkNyeZMNmcF0oGffpTIvUiVQLCqo8eW6onbwxrc5yu4KPzdbtmlqRo+soXiJ2wqStl6MncWBE0C+zgRDCD912jhXJJzVPQdZhVebKF8NN4r8mEe3BNZrqyZmOZmBgpBbvFQo99bEiFM4P72CY1bWJGnI41xbjP3ZbuCieGdMAjCjisuTSu6dCrV17jUN8rztK3qkIpSQ+HW4ISANcIIOVfouyDqyDf4VwK6N+J8Usajw5kFUy+yPAMM5IvwmyQD5QyhilxIANJJJGGixq9dxUqsdr0dJgh8Pxz9b0RjMZvFOeXaLRisDqHDU0I2+C9U1yoP7nNXbpuFABERgbWfRTAhSIFkvsFWz/7ejcPB/ 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 a27779ed3798..8fb94cda86ef 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 Thu Aug 24 03:43: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: 13363504 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 AA3F1C3DA6F for ; Thu, 24 Aug 2023 03:49:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 42978680001; Wed, 23 Aug 2023 23:49:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3DABF8E0011; Wed, 23 Aug 2023 23:49:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27C00680001; Wed, 23 Aug 2023 23:49:55 -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 170858E0011 for ; Wed, 23 Aug 2023 23:49:55 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D182BC011D for ; Thu, 24 Aug 2023 03:49:54 +0000 (UTC) X-FDA: 81157619508.01.7D7B28E Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf13.hostedemail.com (Postfix) with ESMTP id 1E8E620008 for ; Thu, 24 Aug 2023 03:49:52 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RZIGD3XI; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692848993; 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=B6aUUwbyOkHscZNyA7A7465dhx8LWjbNO2ZyHEt0HP8=; b=UboxNrjrXazkEGDWzRLlnIQqoc3mJ7umttXhjyZ/TACdxQ9PihJe31rAQVjhs1aApu5ifD t0oDvmLK2OO5jlaO8miW8Ys+ebd4mOSYj6xslkjl+npk6tvU1+0eYsT8or7tM0Rns/dmKZ Omws103Vj4P3qofIHAYQLnlTsAmBYfo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=RZIGD3XI; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848993; a=rsa-sha256; cv=none; b=SmFEaOs6hMn3bi2eEBKn4wBn7WFIG/ZtD8VKtcA9wXK0EFnfGOUVrKCplVqbCBdo+K7oxM FA9qE3RTLx+cDf4hfQ/6iXxUj2pYAJ4A7hmUVLwIeNK1/q6pw/Ikg0Qy7ZmhA7x76Op9KS Io6BO6pwjp3UGzmKe/HV3TbJ2jtlorM= Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3a84c94f8ebso490849b6e.1 for ; Wed, 23 Aug 2023 20:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848992; x=1693453792; 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=B6aUUwbyOkHscZNyA7A7465dhx8LWjbNO2ZyHEt0HP8=; b=RZIGD3XIyyCZko58S15TEuM+V4uZ9q/nJiTp+ASHyEqDdnHKI2VFdiaK1aK7MoBgqf wdxtyAAvH4GiFgfBTLw1NPiwv/vkKcXTVcQTbLW54mHyckLvZuEctVxqt8DDdrPpaslE Ol7Ntjo6pp6tJCg9DKAxClGqr/9qupnwU3ZjiWqQNPlUqASiZztTSjrB3UsJA1JbVEUv CXL0qdpDcTzF+QC8NW0RGvQLHkAS2pUVF65iSlUw78Ld72cAZJ/of4Q3IJraeFXBOiTB /Td9mKt9yiMQ3tJOlkOUGNssP0ntVYTqf9BGOz/QEowzwJow3yewwXQKQe65AdqCGZsY zwfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848992; x=1693453792; 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=B6aUUwbyOkHscZNyA7A7465dhx8LWjbNO2ZyHEt0HP8=; b=eQDoCbisDD6hEQ/FEN9iq8qQeqvoLBnk4TEq6M/BJynXbpzcolk08H3s1P319Cm7/k WZ+VHYXzHD2cB+jhcLze7CBXLQnHgk8zxyqUvlyTTHbFp2RUAGvfkLdpQGp6iwtqZN6G bSlaT3ErNaEdTrUV3lafsQMzFR4NvQdA/ZL1RkqhHh3eh5idH8uQsGIjLmqyf+5Np6sj UCVGZapFJOLwXycYblw5gYLJ2WqHnuHPDazFe6J4LJOdKJKnxs0dY7lu57fkEDgmUdbK kKENyztmDGL2Ykg2zOXqUqcCAqnfyv4p1h64whk/0wrgU84ZauzzeixuDr7begbFJzAG pTGA== X-Gm-Message-State: AOJu0YyN4Ci+h+vFojCg1Qg40YiDxUG/7f+U7IcnrxyKPe7oMrE4Gn74 ch7VUtE29opO2SOoWZM9ZcwXUA== X-Google-Smtp-Source: AGHT+IHd58HOT5xsJFcKqSa59ChLI854M/dKR1Ww2SFEZwh4duvj6hOPZTfKws4370umVNWgT0imeQ== X-Received: by 2002:a05:6808:21a0:b0:3a3:37dd:e052 with SMTP id be32-20020a05680821a000b003a337dde052mr16581058oib.5.1692848992336; Wed, 23 Aug 2023 20:49:52 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49:51 -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 v5 41/45] mm: shrinker: rename {prealloc|unregister}_memcg_shrinker() to shrinker_memcg_{alloc|remove}() Date: Thu, 24 Aug 2023 11:43:00 +0800 Message-Id: <20230824034304.37411-42-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 1E8E620008 X-Stat-Signature: dj454z6j34sgbh1j3af3731qwcz34ih7 X-HE-Tag: 1692848992-794213 X-HE-Meta: U2FsdGVkX1+HH0i3pg5nAWaYp58FxQWu4UhBXN7R3+9pVyHQsptK5AWG1JsPNRXmOKZ3WA/O7Kyy+0KTlZkgPOZ/GbPWSfrCpyZQg5KRg1HvKudDUNyCZ0XeQ9U9uEVKij3Y/Nu1wcygmrZkoe4g2bUDTu2M+gS8q5ghuzIExXWdpAZZ8jGFAOtZcTgB8ytlQFRH/fW2+L2FYlWseZF1rgXOc0FYdnbCk3/mG7u7H+waVmmb21264+XDtaNz6AduZXRaAfqLPV00PjUTnuX64PQ8HJCGuvCZ/4N5F3ZYn45qH9tAgE+lwqRQF+DB13kw95GacK4z2Wn871iWOoemrG0xgRBMZtP9T/h4S9/cpQ6+vgPgcUifuY8mIvq8FJVqLEgFxs90zl/x0PY1Vq21/CqKwi3vwHK3iNhtejheCgdcqe7Ix5LFt3gu1ngF35YAh99dyDTERFPgjSafe1Ddn1qBw8F7RMdKUmn9Od1VyBf7Z7H76ek7NBpUtNRziBQuvHRsy9gjg6IkEpyTR5AnnpPkzzjDdqGXbeYaHc6yweJdVHyj0MvNzq8c3yhBdyV4bV0r5wGLjl2ootgViy+fQMl45hdYEw4T/luIqE4FbiFXcxGcb1p4HEy7Fw2bgOK6kgbg5YmXIslQmEY5cV9HzSsqHTjijvvyISescNEHyg+22uQZuPhNfbBcV2UWwyWe0RgaYhxfaqfwtDdLHWpOltDQWujXM/k63b3lLSdlNIt6QF1okM/1REye8psp1XvotVIRSNexZgBzNb14fGGm75zhe8vFQ7c3T3FiLGZmaCahbNsd+AOiCz9vmiM40rOi/PWl5Ihcj9ezVWbEmfzlTRJ5aWskZE6l9AN2UfmnrUP7Np7GFGHJaGr2B792IljYmcgvEjYU/wHcZqVsa0kz2c/B+eDAJrRKScj+ALKM2xiblwkic8IdjB/lj64/HD6YwUNoemzFJ/ejX0AYFPX Mx2x47uA 19mulX8NNSgqBLGVxVgqMaWtWXQt4PnC1TKW4l48tCzPKjf8bqDX7L2WOXN41Vxzy2C6iYH6ls7U8KKgtEVOkMhhOy80PYzHiu5zsKul2c6bB+HdmbGOv2STnkzB3E1y4vEXqXx9gtBIQH0u+LhpmKTzMTRzOVtxCrHuhHLy4nT8sttxo4s/RJ3oMwjecmBzJjY8hdj+Vtb6jGXOm+FHZC7EvW4dlVGo/3UqRR8urT1oDIaSm5bJXTC78Zb3YLoRScWJ4tEj0yMPwL4p/pW8RXpi/5GgIg3N8DO/mIa29HGl7xOD3KGQh2EWiNQrFvfoYCXN1H8mNArGJDJTkE1ctnhzUNTsGfPk6c4/tUWoNuqTis0ALzM4VPVyPY9Y3D4JC8UVXpFRjeKbbSEWlBolZsK7CARleeTGVok4V+FVcvNZnAGqMfMqjAhCgNFD0pF3ym+02JK++YOYTMCbYOOMkpJbMnw== 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 --- mm/shrinker.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index 8fb94cda86ef..578599c9e12e 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) { } @@ -627,7 +627,7 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) shrinker->flags = flags | SHRINKER_ALLOCATED; 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) @@ -695,7 +695,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 Thu Aug 24 03:43: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: 13363505 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 DECD8C71145 for ; Thu, 24 Aug 2023 03:50:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 847E0680002; Wed, 23 Aug 2023 23:50:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7F98E0011; Wed, 23 Aug 2023 23:50:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 698EC680002; Wed, 23 Aug 2023 23:50:03 -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 59FCC8E0011 for ; Wed, 23 Aug 2023 23:50:03 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 385D2A01A3 for ; Thu, 24 Aug 2023 03:50:03 +0000 (UTC) X-FDA: 81157619886.04.EB9866B Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by imf06.hostedemail.com (Postfix) with ESMTP id 6072B180028 for ; Thu, 24 Aug 2023 03:50:01 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=T9bwed+G; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.50 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692849001; a=rsa-sha256; cv=none; b=uIu/n0EKvcTGck0ImkKYUmmQTRMADFqyDl9Ir54mhO3+SJeE70BhLcPvDzRZqMAjzP5B7u 8KRrczqwWQtzSkZt+nXoUHQV5sHBkUjHeNTgZvgBO9ifdo2ykbYj6A9Av848vMSqNQtc9g RnM+hBu0mdi4R88xNZozOR/zC4YRfNg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=T9bwed+G; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf06.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.50 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=1692849001; 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=dsFx4mRVJVJC0t+ZBsw1YSpuCOjem+CIHrRc8h/J2ds=; b=AV4xfF1wIEm5T2Tj8p+jWd7No2kwLa7HTBkzhCTeCEKpNk+roB0Q7LvlmSkIpgvnVTjU9L oRwjpSq5vL2pOVPmk3WAETBDgkGDT7ll31klIV9SROLktcO1AKC/2kx2adU6IDoIcNP2V9 0n0kHFgOg+1KDiUsQZT6Hun+havDkfU= Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-6bcca6485f6so1045587a34.1 for ; Wed, 23 Aug 2023 20:50:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692849000; x=1693453800; 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=dsFx4mRVJVJC0t+ZBsw1YSpuCOjem+CIHrRc8h/J2ds=; b=T9bwed+G6G/CL6884wg3Clq6JVCU9mv1KCL/vTkHeAiNhxXq1l7CxJCYQU3i/WOpWC 1A08OFSVxS0TYo1u8V+Q7GUclePfjeq6wUOtMx3bTyrvDHqvmqaHiez8fqANNfrf/CYu 6xgEv6qLwI8zcAqLP898IiYScH6ga/SwY4ITJqqJf8g1HxU2IJUWPYtnj/zY7orQP2Ya vvVTWL/LR3FrZAJDXvAv5Lpw+Lg3YvW/d0CUlWyoARedi57JV+mvcDAsOpoi49Mwz89R V751SjSZpBzsM8eH+uc9aPFQNPKO2az8XNmdyCmByqyS9iv6/b+f3ih03+5KG8RIYbgY qVqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692849000; x=1693453800; 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=dsFx4mRVJVJC0t+ZBsw1YSpuCOjem+CIHrRc8h/J2ds=; b=TKkN9Ly735ZDJzRy0sYARe+e87ud8KSqBW/n9+AioM66x6eSY7VXe7LMyYRQAkTjiF +qZPgC2yVXf8LI9yMD7f3aZ5OSWoJm7jYj/KFe5k+ZWxrjbn32YAN+tuAVsyzOfxCtUY fnvqg0QXMNPdY01j9uqVI16v+qUfou5k2S8GnBDk9lK5KXiHztcgfTP3ctKrklMDGJIc /G0JMgjrW7qbNQWZXNYBDzVEKAEFSseR4KDKy6v4Vdrmt49bx1naSpSQ9fzETTYTEgmc mE42b9lRqBPapFk96T7G1SOm5dussKwUvZdlOe1OQWr9d5lAlye2atlDJJ9Yt5xgGjcm wxwA== X-Gm-Message-State: AOJu0YzFs+MsU3mnaVtLbwrPWjquJbA2kpIAHjtvoy31r/yArdrzE0Ve n9QseVgy93Jw5jr8dGJDsZ7XVA== X-Google-Smtp-Source: AGHT+IFxYqS0WbiBFxFNIpIUofKVES57OXzlEkcC/FgmP0MSEuq+oaMoG3jRL1U7GjoDzEUFD1Ph8g== X-Received: by 2002:a05:6358:c62a:b0:139:fd45:5db5 with SMTP id fd42-20020a056358c62a00b00139fd455db5mr9357334rwb.1.1692848999669; Wed, 23 Aug 2023 20:49:59 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:49:59 -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 v5 42/45] mm: shrinker: make global slab shrink lockless Date: Thu, 24 Aug 2023 11:43:01 +0800 Message-Id: <20230824034304.37411-43-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6072B180028 X-Stat-Signature: kzytxzzqokm77k8ftpxtx4e6p4pfx7fr X-HE-Tag: 1692849001-519588 X-HE-Meta: U2FsdGVkX1+7ynNjxE5+v9eoyoMJ571UgyrFqAjYWICbbz5t1FLWyCDKR1SfpMzXEEsM9PnyEPpESnJa9FbhaTRSA6cersGlHQhIzziEz0UjSgXQWV1kao0lqT8GIoXyA8lqnX9bVn37rY+/phiFnGKgVTjrgBZDiz5MbAxSJkGl92/vdPURsXEOXVI45i5TB7MEKznKR3v2fSRfdXQjosRxZrRdvFmOSHHAuWbi+jB27/3tucoWNYPsY4wCjlOmarOva2xUbhDLevsErN+EDWJJFoDsFsKK0PYrY8U4FQ8vvZ8ng8086ykhOH7dLodtleyV75xshzvyynAnrxF6hB64ZrFKChgT4FN1CYKmTQIao/4kpTV8lHbSWK75KgbGc6nBi6ZLpnl66kGuMY3y00MA69n+Uwc8c52OcofuMi4Od5O3fXJLoaROsNyna0f4MHp9y6rOhdQdKLjZTwhet6icMNWF680c9I2LUiwO6rx1GU+hHB7EqAd1jPa82QNtqVobIS3g6BwvD1vGCHXngxK6Zcu9+ldeqlGYDF9KxbVXapMZGQ8xXt4gczGHdJJncyFqDpQZwwlrukdv9rQcdekNlkGvYt+8p9e9FjiUzsN24YhG5ABHGAmi3jByPkbxvLqsqhRiOrs6eWMNz2KES4semIXeHhPP7Q5fhsYqLbPobBQKnPgiDpAoNXXoOmKBQRGdfryTbgOKeOqiVhGLxqE6JjqLj9Nvt4xxP7NaSogbbQY016yuld0iphlNudzL5UZ42FUlFWFhgwsPBrdVCyVpvCAvuhk+bqnhQ6YJkxowCJypd5YF0pHiGXMh8uHg/ElzYWgUlvS09V+5qqI1Q+w321m7PCv5rzZqOMEr7qpjoIyHFb+plKPDSYn6KnUUM3XsgAf/RUIOgrMyN8jjR+RaZ6+fn3pJ+xTijAggpgsAGRsg5opHxLqjN3QFqr2hCSLKBqtVxP/Ly4ZWCIj fJiPskLv iKHODt19ShLCVVhwYPrXCwuFvGGKXm6iXrP3otfsoO8mUdFmhSCxF5h3crdWmfHi4aGEuNrXV/FJOThkYVrGYM/qAfE0EFd/Zv75nRtEsq09SbhCzvGKnxvXQJ/m5R3wMrQQEiJDTDltvLfhSBYtemrbgPyFBT7YmEseUtMHJAQjWNUjT38WpDC0y3nzmhtexb/jsPi4hUIHLMxH+kR43mzUzNeWpS8SQZ41uI6JRQWxf2VGmWHzSzTiQnnlLPXvmqwpdCrDfbysYY7BcOH7kji3jL/t1DOUcuH3YmsPyzpzibQq3+qJzY9i8VxAA6T5JtDAAdP8VF91vC5JWtSQSG90clCcXjY71OhaHIP80daj8kq4xeJacdgKZV0rm9Tm/DHBdvp45zN7S54WOXz7zwzOxQqYpcKbrYnVteIhCuPU6FRj+E5aA5GUjoROLYg/UlbIoFRwwNTDZV/4FMbRaO7LNXtBs4gStNq2wJilaXzbIqqeX/5ZYYY4PF/dMdZDN4puN7P/pULIGzCUsrBIvDBUPI5v57rZ9jwOcLauITYRf4hw= 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 735238 60.00 12.37 363.70 12253.05 1955.08 for a 60.01s run time: 1440.27s available CPU time 12.36s user time ( 0.86%) 363.70s system time ( 25.25%) 376.06s total time ( 26.11%) load average: 10.79 4.47 1.69 passed: 9: ramfs (9) failed: 0 skipped: 0 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 746698 60.00 12.45 376.16 12444.02 1921.47 for a 60.01s run time: 1440.28s available CPU time 12.44s user time ( 0.86%) 376.16s system time ( 26.12%) 388.60s total time ( 26.98%) load average: 9.01 3.85 1.49 passed: 9: ramfs (9) failed: 0 skipped: 0 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 578599c9e12e..2b8c1f1bbf2d 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; } @@ -670,13 +688,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; @@ -685,9 +719,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 { @@ -701,9 +751,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 Thu Aug 24 03:43: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: 13363506 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 8D66AC3DA6F for ; Thu, 24 Aug 2023 03:50:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31791680003; Wed, 23 Aug 2023 23:50:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A1538E0011; Wed, 23 Aug 2023 23:50:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 141C6680003; Wed, 23 Aug 2023 23:50:10 -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 0336F8E0011 for ; Wed, 23 Aug 2023 23:50:10 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CE41E8017E for ; Thu, 24 Aug 2023 03:50:09 +0000 (UTC) X-FDA: 81157620138.10.C767164 Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf29.hostedemail.com (Postfix) with ESMTP id 1294F120018 for ; Thu, 24 Aug 2023 03:50:07 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pf6vNHkc; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.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=1692849008; 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=bj97+7kRuzjBy8tIew3M4TNtnbEno9Wuan+4JTlpSSQ=; b=PxShoz6it+IONq1sIbDxR4qCQ/AkLBCD4+oU5GZaduFOhtsw+sD1tJkYh+dJVZzeCgeWlq TYA/gnTlXeN6+Y2rWLPEnKS1vSA3CA06pAsZiWKbJRPMhusbwaGmy5YDFoiIu5gC/vxMtc OIOmP4laXFghpnXcudUgf3/Oc0I3VR8= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pf6vNHkc; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692849008; a=rsa-sha256; cv=none; b=WPXXEsJOZTGqge7ZWPX1UHyf0bdpNCUKn5SjrYmRyZmoGj0ps0n+spRIhb5GYBq+x8rLjD dW7fUfywiE/HNcDBj3CZeaGOe4WNlxwwUH35GEIaaxzwiph5y9d8gEBlHAFMaxHrB+K7bA RJHkTzHSOfO1hytJ6pQi7GwWUHT1IkA= Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3a8586813cfso655957b6e.0 for ; Wed, 23 Aug 2023 20:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692849007; x=1693453807; 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=bj97+7kRuzjBy8tIew3M4TNtnbEno9Wuan+4JTlpSSQ=; b=Pf6vNHkcB1vA+6pxbgxqpCgxpTQyk2TtDM/one3T/7C2oTeNlkoEFdQ0L+WsmL9Y+q BjBv6VhRRLZdvemmxw4SoGo8giABbtk+hJjbUvzD9xKbM+F06wn4gwW4u8zm7429LXth 3CAeLPVtrqyhJ+pNzZ27ujBXU6T0SdwYWU6AYQtLaBCIKMUwWo2tehQ59lXNTJxqwpjh QSCHxH4GcVwROqRsmcJ4PYqES36W4oSEATQLnGYrVdSRQTVs+xacMGyzpMR7Luxhok1d CDFJezReHQORkNLmpGGdLCVlNbqFm8Htz4v8L6Gp82964pbV+f9rHsaB4MwdgXLHjtpQ t6bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692849007; x=1693453807; 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=bj97+7kRuzjBy8tIew3M4TNtnbEno9Wuan+4JTlpSSQ=; b=RuY8/svpVR2juN/g+kP27usizD0DaM0tc7ar2hVb0fCviYDIHfWOXHihriE0FWYEcr yTXRFbYRUX+cWV45+46pP+3KsS6KvvVApCHcXQgvbUyx2knz35gx3xC5JfF+Nqrp4lrQ smgwrd+l1WZDJgf4CB4mzMTQR3N9mw2+Wg6fVfRZMpvxdF0+Vbo+f50dTgXswSIKeqHQ 6EABsdJQYpvoL5lzJE7BkZSBJaEW827MjL134N20XqMW9mkXL9FiwsEoOADuveTH19wu ZiKEi1zsl7i0zXy6qJ1ccN7JYGeubwbiQg6Xt3aP71ax/dSgt9HqIANEk6Lcrgi5kl2P caMw== X-Gm-Message-State: AOJu0YwR+zmOoYH9J5qRrNZUx1Dqz3vVssBX4HJBAwUeOVBoGckqc6Qv DoXMEGjBz8cRhYnhdITk2c9yeg== X-Google-Smtp-Source: AGHT+IFy9m7FV74PRUXhk8NrRebE6Bg/bLzhyLzquzwrzg4LwcJGIL+HBXsvf05OcawJkJTA6sAEMQ== X-Received: by 2002:a05:6808:30a7:b0:3a7:2eb4:ce04 with SMTP id bl39-20020a05680830a700b003a72eb4ce04mr17486035oib.5.1692849007231; Wed, 23 Aug 2023 20:50:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.50.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:50: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 Subject: [PATCH v5 43/45] mm: shrinker: make memcg slab shrink lockless Date: Thu, 24 Aug 2023 11:43:02 +0800 Message-Id: <20230824034304.37411-44-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1294F120018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: x1eme8w8khkei1oo9xcqzcuyjssp6q7j X-HE-Tag: 1692849007-373697 X-HE-Meta: U2FsdGVkX191RWmHD85VleCOUFpLPJD7aVKbC3Flo/l+GmiSsifValvW5OY+zWBg2hG9Un0D2d+DaG+sjv0qs4/DDKNHkCol/HWFPGvYyUC5eLmPGnJJDWD3kbe2vv2mUnVXvBof87juvZR+GVpYQmFgUz6Ymlm96F7AfPY0+f8Xu/9D/m0FcuivecifWfZCsnXFmSXDq632ZSXdqf2cyZugvhYnpgq4tTf0/rhofSLajv9hCMrztIbBJ8wB+t+Pgo/JmIX4JgmqUJyBtENNxNDjwhz8TK1M2yFNusf7H7U4kbRUyoRavV3uxFHb47U/azob/7/z25l5qCunCoS7A0pxUgCwWGkTEijdw+RY/rFdRVZia+JwyikQAJwLWBwJw+1MMOx+dTKs+BxTL6y7Oz2jqHJlcXl16BOss7DLDxwuOXBFV2VdvIoOrY2aQQAc9WDM7kIhmA5eGZbiA6YxmSBUqwn1tjzCk+Pwokupepqsqo2bD9ItgeFmr6HXKfnQ+Tmc1HUZn/biZlzJfukmJaI0y7L/UgeAP2XEVtd1JtrT6FBkVqMeikZGFihRMoH5Z2sfGsh4DaPbP24YPWrhfy32VebhF3XxoSPuGKjRs0En606LNIgki4gphJjiVumIa/oOeN/0vScAPeIxehw/QDMtSmMc1ZQ1r0yI81iGFJnFF0VLfVnRP+D5Jfk5S7ME4suJ+LKH2GW3Hg88m3K9o8/HgkcbaHoF3vtseWpLEkATgAH/tUzow+7xAnboUy2QcToUkiEp8YwnvZblZC53Ev/15KNI6MXOSCB/NHZaO29MntqjUfTomqmnn5sbhWXeffOfXMaG7cCYyyDGW4+saNyMioSsKbdO48C9MQFUdiqB94jKfKnS93VDivEywEzsIevwn8QBDVMJX6y8VV4v6Vd8IYHvHXeweqraVlzMMApwFxA12vESpWWy/WElE9gs3JMezlzWBgrCf3eRl/2 EWYgAwhv YEIGJes6MNRYPuh6TPxvrqzDLYIiwXcr0WRlSFkjfU1oDFfeTE2YlvgyxEdkm9z4ajZQnepcr2iZYBKj0xT/ojzh7Cl6o2x5brhNu1AsIde9AgxpH63W4vd60bRi1JSE0Kp1AENIIYD2mQmO0zWhGuwxYGCNYvCgOhXEaMN+S0OjzF4qHbCq5E7Oa1s9qTc9rw1MehHxaCuDxRCPMekJBpH+L2mtYgy/PwUPxa/C4BGk+sTAiNYucxW9U4NAR0DUKl4CUprvK5s0K8RaVOoHPr+dvDPx5MD+eZLT6G72jQimty11AtTvwJJ0szWkzj/mH6Hy66Ag9XY+KVNFPG+xYLMmbHBacIUe823I9IOuDxTittXPPlh7uP4xtCgMifUhs1e85H9xWllxy4O6yP3IaSlgaT2xZmLZxPPYm 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: 40.44% [kernel] [k] down_read_trylock 17.59% [kernel] [k] up_read 13.64% [kernel] [k] pv_native_safe_halt 11.90% [kernel] [k] shrink_slab 8.21% [kernel] [k] idr_find 2.71% [kernel] [k] _find_next_bit 1.36% [kernel] [k] shrink_node 0.81% [kernel] [k] shrink_lruvec 0.80% [kernel] [k] __radix_tree_lookup 0.50% [kernel] [k] do_shrink_slab 0.21% [kernel] [k] list_lru_count_one 0.16% [kernel] [k] mem_cgroup_iter 2) After applying this patchset: 60.17% [kernel] [k] shrink_slab 20.42% [kernel] [k] pv_native_safe_halt 3.03% [kernel] [k] do_shrink_slab 2.73% [kernel] [k] shrink_node 2.27% [kernel] [k] shrink_lruvec 2.00% [kernel] [k] __rcu_read_unlock 1.92% [kernel] [k] mem_cgroup_iter 0.98% [kernel] [k] __rcu_read_lock 0.91% [kernel] [k] osq_lock 0.63% [kernel] [k] mem_cgroup_calculate_protection 0.55% [kernel] [k] shrinker_put 0.46% [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 2b8c1f1bbf2d..a66e2a30cc16 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 Thu Aug 24 03:43: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: 13363507 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 583DBC3DA6F for ; Thu, 24 Aug 2023 03:50:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E6262680004; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E12F88E0011; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0195680004; Wed, 23 Aug 2023 23:50:17 -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 BF2BF8E0011 for ; Wed, 23 Aug 2023 23:50:17 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A33C6C011C for ; Thu, 24 Aug 2023 03:50:17 +0000 (UTC) X-FDA: 81157620474.18.2C7CCBB Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by imf23.hostedemail.com (Postfix) with ESMTP id E036614000C for ; Thu, 24 Aug 2023 03:50:15 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CCTuSOBg; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.51 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=1692849015; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=4iCvTFwA+vdBsxASNHsNkjdI1P/8YOzAwv8qFKiLcrA7cNaeW0C9wpdRhE8z3T7eAhSFNV oIJrBHI01Aq9ryUFTXMrAIqnBfHt6eviiuV3ogWyZFwINdepbznlwUgjsePrHBVTRkHFYM 62lDK6Jwbfju/G2aoz+Utp6ynJpO3oI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=CCTuSOBg; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf23.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.51 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692849015; a=rsa-sha256; cv=none; b=t876snbB0CLNpjlLAbkCnABj/EjEEFQFrx9pSBhVgEDad6uU2lnY6p/xjikeZsRk2Q1u3t ZPWG7IBmJDU6H5ChEEYHK+bJen/2kvlL4K+lbj3bERTyQPMjBs2MXm/10jwEyll7qRuSjF U4d9r8GELdCdcAJS5g5E81HmFWp5/lw= Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-6bc57401cb9so829331a34.0 for ; Wed, 23 Aug 2023 20:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692849015; x=1693453815; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=CCTuSOBgedcKOMD6iZJkvY7Us2mVWVIovgQPaP6ZUpdF+pw4bAhv02m/Nl/S4QVY4d LPWSynhpJLRykIHUCiAxqCO+wFldrWBDT8NgV40tAakicxue0r1bpK5B/Q/mLIz5qd9g E+PYwX2FapH/Q+l5AGm47K2ttt7y4CjIrDWtAgA5OR6aYvDU11Lb8F1MD1U2SE6i8Bj6 H25VAPO/X8QTRWh+vgYHVw4v2i7u3qqCizmLZFjpxfwshexicHFZyXOq/NSfx2KwPlBG 0SM3oY1UWfVHYDPVirSv4+DuSFqTIUnfwkygBDf843DNNjRGpZkoSP1jM2B6BMbRru4C IyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692849015; x=1693453815; 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=4FlzFvcCQYvI8dZSQr0uzK4V9UWa182sTQHb8HSYecY=; b=IfstaGKm2HwYgmAqnf+LNfChiUob/R3Bja4AMkIyHKC86WdVtfaY47an3OuJjCZBlD EVyZsrZ9nqglhsH0WmY4NSLT4MBsg/SZzS7PUZuuuiZC3L50MxMfZxfUXa0F+dRYBvRC sDJtUt5cK4Z88Uu69ixnrFsvkXe5RPtaWdCkDAePtANuZP2Vs8OFROHyCRTMBrwiJxyA Q6txJsxWgb50ncyqc/Mifx4lOBjm0+Orx0+9HlJ7cgSFok4hSFJEWv5f6AiP6aaXnQ0F D3MTfr8lVQT/1mwjzGmv8lwdRvGDGYKU26G6Zkn2DzYR9l0EUGrKzwi3aMK885fBmDIb RXHA== X-Gm-Message-State: AOJu0Ywf3Ok7UXrlTbnPp2lb4o/8qE5dXTxPtfGU39+cXIEDO+uRluqO FJySFTjQDPKGLUUedFBPDUSvBg== X-Google-Smtp-Source: AGHT+IGNNFy+tJmkErp1Cj65UOC5qZG9ZWIMpE+ontdaYElYA5FS/+TvI/fJv+zkeYDhjrDv7KNO4g== X-Received: by 2002:a05:6830:308f:b0:6b9:b987:1337 with SMTP id g15-20020a056830308f00b006b9b9871337mr14530264ots.1.1692849015165; Wed, 23 Aug 2023 20:50:15 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:50: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 v5 44/45] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Thu, 24 Aug 2023 11:43:03 +0800 Message-Id: <20230824034304.37411-45-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E036614000C X-Stat-Signature: e66nzezm1yndre3srtkkpen3bearumta X-Rspam-User: X-HE-Tag: 1692849015-180612 X-HE-Meta: U2FsdGVkX1/8dTV1hESZyf/8HjV0Z7/REgVLIqxTVezMLLnssct0o+FoEVN1ooKXfLQKSEYiNtm9DqYFfSdOJFjrzdZN7VNI5TEbmUEUoO7CnXUwhnYa2G85j5SS87SP77K4dUjb7MS/BBokqHp6ENcHN5If23r/bDkXWNrfrPLfPqODGE8eeCQhCgor1FW7SBfeFekK0XQFXtYZz+lWwu0Ztr8WhpFRJWCg75i1CpO+H8Xj7zH2vWYDsYlCbK6dVvADySc6+c9W8VHHVl6rAUiWqRkIVhPb2LgGCmG8Xh+cnKd71UwCxXnKIat7zsMnQIbd7q6WOGUGo3uWMB9H0TVGoXHclsjl7pnbG6g3ysUttwY2IsGDhT6BmyXZUHhmMGot8TApCwhuPODBI3xlpalAfyIMVMxdovICGFLRkG+O7+HSNQ+2DZJiLi8MTZ9fxsgyreSzgWEIxgwUEgcSOmer1WqVm8SmXac5t4Iw6EWwtflBae4O9tGy6neSObMVR0fX2NcaAH6h6kmFQo1SIuxXWds7f9naQ4XdgvPb9G9ODs9gQaXRkegKI5zEXoFXqohp5AtvDkqhsofBnjGCCvJZkceGUNYNmlJpah1v7l+NrS6l4yNb8p3b8cqBqTYl8E06PFet8/GBNUYdTXaS5D0Y34LjEkGAhVZrr+XGvFmzh9QEGsEDcKGhEO+OEj286lGKVZ8wSRdInW0tmCw0jHchx5bnZslrhqnUWi9ye1fmJrpkc3osjkaV+pjO4ZvGMPqD3W01B1nOj9mRQl+Tfk7Gs6KChl4rsf12TKjke/m4dIW1DepiHfaN/hscIANQ6nfYP7J7aVYv5Fz/erz9XuE/+xzNZY7e5EWe45nCsnWs3T7N/aosBmZ1RMRKs8gCZfmdbXXaO/TvznvhLfHBRc2EAXBDL2PB2RH4UbPA9zvfDX5KysI2ACs4WAxwUFEaj3PzVkXMMns9Godtogl IOtKHGyX PN1vltwwiCXfUrQ/B55encYsrjPTfK19gLfKJUTPAhnXHHwyZCoFt3+fVL4p+MckEDvyL4QddJNBQL/G38Tgf6/1z59BzrrieHxD+sx/LkB7cNGLFTvxEcyeGKOfMaUq1k7zxPg1ucehzXWJwJVbC3ZFBFR2Y9vcUoExyu+fajpD5XgXUkDoU5iWEOB20bdSb5YLchnrki7alaVnI2agLlVxXXH49pf1qFVLveAA1FM3LVOT6DOHj2b5E9jCEhqDv1IHPz3H0yWkejlSZCgQ35qwEllURFqX4FrP4zuKl7phx6sOSvHZN+cAiy3rWR8J7u05GliJkkzIr/0mHJuHW/g9UHGLZOKsmjj6PJJyWrEKb/fiaDyDq40doPg== 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 --- mm/shrinker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index a66e2a30cc16..b8cb9d2f5dbf 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 Thu Aug 24 03:43: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: 13363508 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 021D2C71145 for ; Thu, 24 Aug 2023 03:50:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95ADE680005; Wed, 23 Aug 2023 23:50:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E2EE8E0011; Wed, 23 Aug 2023 23:50:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75D8B680005; Wed, 23 Aug 2023 23:50:26 -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 662268E0011 for ; Wed, 23 Aug 2023 23:50:26 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3DADA12011A for ; Thu, 24 Aug 2023 03:50:25 +0000 (UTC) X-FDA: 81157620810.22.380B5B0 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf09.hostedemail.com (Postfix) with ESMTP id 79EFE140006 for ; Thu, 24 Aug 2023 03:50:23 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W5sRxdM+; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 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=1692849023; 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=eu0WK6VzHgaMcegFu4ppWK6A3eF2qt3htkac+PCZB8E=; b=IHtvSoT4WC6cMeflQtJ0/d4x56n0Fa+LVe2mWPxFwvD72c/Cy1p7J5AMk7NbBroBlIiApN gXNgob0eZ5qEkWCWARF9X7xUPK4NDcW8N0v0xFCDoMghtkeZf+OLCTlyplCtaz1Bcvjmnx WBFuHEAEToliAcGNiYMJyY0AJ6AYzhk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=W5sRxdM+; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692849023; a=rsa-sha256; cv=none; b=5SuWfUC+24IKNcORcke79lDwn8Rd3PVZzG3H+U+DIk2nY37Tsp6QYfb5PcAJwcCtZZrX3i jkb2xgJxvdnyvx+o6Pmuwfi5uTRcT7XIYadV13BQrpgXdq+sNayCJ+wfl31nnGyBYvAvw4 +Y+xsAUbMsg4yLF0DqG7JbwJHYCs4Q4= Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3a751bd3372so714794b6e.0 for ; Wed, 23 Aug 2023 20:50:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692849022; x=1693453822; 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=eu0WK6VzHgaMcegFu4ppWK6A3eF2qt3htkac+PCZB8E=; b=W5sRxdM+rsh+oajbFagtG/NArz5lC7ZueZPGHNOIABdikrecbQo1jrzqW9UDqyLoTv TzgvihpvjWTWKJ+1fy992y96S5aNZpN2J9j+w5LSQdltHZCCPvU26E7vwSD0NURE42NC Jz9M3A9q7+eGjsTVvnX5ny+7W7SkEPJsWldwqaDKkSIzb+u07ktNINRkYE/41WYwrn/+ klevBbkzy/VqDZw1AidA4VZQ+3yrZ3HDycykgqXFzDsJiIHQOIeqcsFxXMWk6sTDFmCM gvOSA+RzdkNkYlFXo+ktc17fS4qpzpi1Gg9cGrETSFTrVyvItsj3pbvSN3IX/cRqwFmf 6n0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692849022; x=1693453822; 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=eu0WK6VzHgaMcegFu4ppWK6A3eF2qt3htkac+PCZB8E=; b=HliAgR/JCItojncKcUbvCIxduuTUAhVzMZ2E6v1G1RVGqqZJdIo6npTfogqe94UI+x 3IdDmUaxPAPUb3JxIiU952LATlI6ak3/rFtIrcHUS6Fgkx2FcLfCtsoMzPxAPEZyQnjU En8DS88EhA/gEWpo1r0zo4GwMpjW5O2p261gCJ9ebkI/M0FZq00aekLC9Ctru/dzc7Sn RAqonhmLaLTyexXoC2n8yWoCRyNsV8Bb0T5YW3wfGH6NdHAIdGRmM75lsVnrCEUuBHep LaTqGGEXmO7GItmQIYscM8i5I63+mtxOoMSTM5viwvZiYwGUcPQuMHWoGDzRJB8SVIM1 8gzw== X-Gm-Message-State: AOJu0YzAtXChPLAZbMNVlRK+PK6FayStOayG/qGEcekWeI6s0Psyvjof 3joxF4ykFMuxIqo1xryePmd2FA== X-Google-Smtp-Source: AGHT+IEwP9zlDJi1bkp8oOvqLZKY28k5hZ0rjRWVV6uh9Jv5QU9lxKle/By/IFJpG61G1qev+ytTMQ== X-Received: by 2002:a05:6808:448d:b0:3a7:56a6:bd2b with SMTP id eq13-20020a056808448d00b003a756a6bd2bmr15350556oib.4.1692849022667; Wed, 23 Aug 2023 20:50:22 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:50: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 Subject: [PATCH v5 45/45] mm: shrinker: convert shrinker_rwsem to mutex Date: Thu, 24 Aug 2023 11:43:04 +0800 Message-Id: <20230824034304.37411-46-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 79EFE140006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 6oj7bcmiienoy61wrxobtbfpjjousows X-HE-Tag: 1692849023-636673 X-HE-Meta: U2FsdGVkX194hw23cSUcLdzFpwEboB6W5zVZ0cTdJZsX8ffCRCSw4FRgenYk3kn8EYkU6af4vq8YSvBWatVMmOwvB+wN4zGoCDSC/6LXD0tIfVcdmqVESbx+lGOuGLx2M2zrT5HEr6DCFu5yIGVYfPvNEKTjcF2IwGBf2sOyy3f1GbHRZ4jaCu4QqtMfbxYgWAoVGr6ECo/x7JACAPG2+VTn/rD+/NXBH7rDw5MpL2eJK7MDIQ6mFlT2KnQqLfq8s1TzK2Y1naCjnrTYOx6LfdemZ8aJCVEsoDlMNWnnd8ZgDUYbvMoVHZGM/sZzKf+fNU9u1eCdeKHH2IUYykRMJsgW7Djv4ahS0KIcuGCad/hyONt5RuHdT8FiPSY92CZBiHDXV4Md8FCDnMO6+RbXXSPcAwvbJn/1N9vxTpKhRRMrG2KnbP1iiHLSdMy8YoRzhXYmQDLPxCIDWaIj9XsQnT+dxWA6H6+4Xx9eZAhKqO4nhERfXTWf2/oPphQTTFn7lm6LkYcT/PG7ccAe+wpVg+NR6Bw7O8NdDxcdrEJLFgeL4VN/bbGFQBGYiQ+6N/zfmapLUIvH74dwdhyWO75pN9D93/oOKNZl+ycY0mVl4B0t6U20yGhPrZNFP9aZk/PdamGiTvc2gcvoNkH4PXcysDGKW2wwQg7J5BufIAxfn/pNeWWVgZs6TU2EQIZeg0cVxlMfeTg3VxBI7qtijqzmx6JgNA6tMJ7m6d5A47HWgrbY/mALOqP4pxkVkeVeGlnqXgQcyEF0zl3G5XzGK7FI1vbFQwIOKmUSDwgjwiYxvP7PGBX6as7Mf8Nwu2PlMVW2bY88QjOwx14gAf23iFGvrNdsImbknBMidsko7nvxlIsgfn9g6bmXr9QpIEdczhW/0VCY79jkR9Pvf23RAGuVogVrujP9FQSiNK0DyquheHGfp3VAXLunfLy8VvSLfgsYN1wlu9s1BgqOuVaYJuo yZPx4iSN LC5xiSyb72zJu0tvfpM4dg5xSXo4n2VSqhuJaVbTHqZ5/eigyub1+0FtvT0tM6+eOYIjQTzecwoKrYK22Wq7E6zu4W2SXE7N3RLIXyrIQFN2M0eD/RVYoMi7UBQQxqC/UhP+AaYj/HRq+cgjVBglj+eGrD0tcVaKjIPuzvwShc2sfpX4l8WDMz2GMSZ7rF8rfiAGCyvi/E3QVnSPWb0kTz1hSyH3SAafzhv+/ajYKyFij7Io9dN1yrfaf4ONuOmEpFDBiTaw9qaA30t2APd+YDQD1eIpIpzsPe/tvsTujryo35oaJVF5Xd1McCxmyQ47oYwvrIZtBRn3KAm+snJsVDiw0xZkxU0BNsKLLJOJO68HdXJuNRO5eG+/DHeb9wmZFnD/hhm79PZZDcihu/9jvuvAZP/mYjEMUtifq4LUf5sjw0BMlCg9uP35IKoiBM4yZGuTRfEakUXscKK8Vg7ukgXJdxw== 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 --- 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 5ce0c51bb445..b7a914f3ac5c 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 b8cb9d2f5dbf..a174d1d4b08d 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) @@ -734,11 +734,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); /* @@ -778,7 +778,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 @@ -793,7 +793,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; }