From patchwork Tue Sep 19 02:46:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13390619 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 65E54CD3433 for ; Tue, 19 Sep 2023 02:46:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CE8F46B048E; Mon, 18 Sep 2023 22:46:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C996C6B0490; Mon, 18 Sep 2023 22:46:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B60F66B0491; Mon, 18 Sep 2023 22:46:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A3FC16B048E for ; Mon, 18 Sep 2023 22:46:49 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 7A0A1B3C01 for ; Tue, 19 Sep 2023 02:46:49 +0000 (UTC) X-FDA: 81251809338.06.B823AB1 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf28.hostedemail.com (Postfix) with ESMTP id 7BB7AC000C for ; Tue, 19 Sep 2023 02:46:45 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Riy6zeJp; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 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=1695091607; 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=CVaCKafr7rXOhFLTAtlQmk5QekExsnPlB/mflEUNsHY=; b=p1pdTMvqpC6AN2wO360itxWgiItIrN0zLs09YycX47J9TbrEC+PwMHq0BvDjxobCK6+o+I Oo1pEAsFaB0f1gxnPJaDeV5ILzTdp054N/gNYL89PHAXiD5cg4FKWWRH7AKqkLAawecuPv 7m9i7+9fwDwVUYUIXx+CKlGRsXNFDmk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695091607; a=rsa-sha256; cv=none; b=uwERO02fxnoBGg7cI1pPkuG91Y6/hawFf+QOzlHfwJOrYTueUqKoq8Tu0ySSnJN9qqu78C T0HlNlxRqiD2TcSn86CAOCPH53pS9xLVKPS35HxsK5pmJPv4dxUvZ7SSeAhdWokGHQOMNY S9yvSbCvsN53mAME0w2pCAWHstsVVrs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Riy6zeJp; spf=pass (imf28.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1c5a223520dso26805ad.1 for ; Mon, 18 Sep 2023 19:46:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695091604; x=1695696404; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CVaCKafr7rXOhFLTAtlQmk5QekExsnPlB/mflEUNsHY=; b=Riy6zeJp76y6SQDGXdy8xHs/1ZurxuglzXX1LDBCeVHHb5ecdfW8s5ozrVQvNia77R cvdkgD6MkDWJBiGRLAd/edklpQYKUj8Pyjcob3X7NhBYDR//mB1f4TuoiOh6mIUVXTxe HQrwLAioGz39dm6wQh5Mm+bzAtKEmyS26jnYqp+Y2X8gveX6ScdtckrNXt71VJ+iHeZn 2n1+tHwlsJ3e5altFhj+3wG5ZO7ZgjEppnOFs5thK09KbHbMthVvyAyCQyRjN8RHXQHu VXIiNOFVxHAIBnjdo0nINrCaQLXuRh+83biCwW8+q7R19niI91O5KKtw3MX+fMP3JUD/ imLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695091604; x=1695696404; 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=CVaCKafr7rXOhFLTAtlQmk5QekExsnPlB/mflEUNsHY=; b=palRbB3KR78EcY2DVX5bugvyBMmo9WMZu4vyN1xxqdJitk8V5k8kxFoh7ACZLrJXKJ mx/OqrrY2CBMdKarK9DGq27ndZrzmCr2XbCUvmcoU/7DoYZRo4tu/ZewV40MLTzjjO2u FUZz39BKQcwsiuBwSv+kN/dBU1IRG8WIV3I39qNRsPazKrsZJea/UqF5asmxKxpbhLo8 p9maRcThkqEsTkZ/jJE/XMMjyKT5PWvZJ1DDL/iq2/hHAadOiowWJWOAgkDXUSzRXJ+j wo1a2QVWaq0akwo25pK4DFDFycNGLA+KvYHPaqu2nKf4dUGcsBSs1n4Sx1PKGEcHxrkx oMFA== X-Gm-Message-State: AOJu0YyJt+v8BjvRf22sSFcy/A+gZk6sO+gX9zreMWKrCb9s6R0NgnMx y8uKd7y+MYbLKwJgdjtiKmAtKg== X-Google-Smtp-Source: AGHT+IG5mbJOtnUV7RTj73z+udKG4UFeAJTSFAjJzR+Q8pglWJacUFjOvahYn+5uh9/MdY3h+cfFWA== X-Received: by 2002:a17:902:e744:b0:1b8:aded:524c with SMTP id p4-20020a170902e74400b001b8aded524cmr12897364plf.1.1695091604093; Mon, 18 Sep 2023 19:46:44 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id m1-20020a170902d18100b001b7f40a8959sm8884198plb.76.2023.09.18.19.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 19:46:43 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.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, Qi Zheng , Muchun Song Subject: [PATCH] mm: shrinker: some cleanup Date: Tue, 19 Sep 2023 10:46:07 +0800 Message-Id: <20230919024607.65463-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-2-zhengqi.arch@bytedance.com> References: <20230911094444.68966-2-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7BB7AC000C X-Rspam-User: X-Stat-Signature: sb3hedttnutoa64p44zttixiqakqiwyo X-Rspamd-Server: rspam03 X-HE-Tag: 1695091605-507701 X-HE-Meta: U2FsdGVkX1/qrohkP0Xj3WRxqNEo6is2GM+e5xjPdXZRbg7ANdrFlxhwZYEZD3Tz/UKkMT/Nf57pjN5ytAddTEzPhWZge6b7UQ9Y3hf3UqCmLEeJHvXN72IBdd5yhvXVSigYsxnhwj88rFzaX01YcjJU5YmzETJCMqRTaPOASF9bUQHiUMZTyLRS5qr0mc2LndqkevMygnUvS1PFyf7RlyW5wlFAVv9GG+e2A5oR/JcWa9/3izRYjTu/T4QHCMXbAYD8+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nkYzdEkBS0qeopoamMHhe7kmqeWSd9aE1bJn+pWz1QtixuLlPKCZMmR/VipPVfenTc7rC8z 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: Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- Hi Andrew, this is a cleanup patch for [PATCH v6 01/45], there will be a small conflict with [PATCH v6 41/45]. include/linux/shrinker.h | 14 ++++++++------ mm/internal.h | 17 ++++++++++++++--- mm/shrinker.c | 20 ++++++++++++-------- mm/shrinker_debug.c | 16 ---------------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 3f3fd9974ce5..f4a5249f00b2 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -88,16 +88,18 @@ struct shrinker { }; #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ -/* Flags */ -#define SHRINKER_REGISTERED (1 << 0) -#define SHRINKER_NUMA_AWARE (1 << 1) -#define SHRINKER_MEMCG_AWARE (1 << 2) +/* Internal flags */ +#define SHRINKER_REGISTERED BIT(0) +#define SHRINKER_ALLOCATED BIT(1) + +/* Flags for users to use */ +#define SHRINKER_NUMA_AWARE BIT(2) +#define SHRINKER_MEMCG_AWARE BIT(3) /* * It just makes sense when the shrinker is also MEMCG_AWARE for now, * non-MEMCG_AWARE shrinker should not have this flag set. */ -#define SHRINKER_NONSLAB (1 << 3) -#define SHRINKER_ALLOCATED (1 << 4) +#define SHRINKER_NONSLAB BIT(4) struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...); void shrinker_register(struct shrinker *shrinker); diff --git a/mm/internal.h b/mm/internal.h index b9a116dce28e..0f418a11c7a8 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1161,10 +1161,21 @@ unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, int priority); #ifdef CONFIG_SHRINKER_DEBUG +static inline 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; +} + +static inline void shrinker_debugfs_name_free(struct shrinker *shrinker) +{ + kfree_const(shrinker->name); + shrinker->name = NULL; +} + 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, diff --git a/mm/shrinker.c b/mm/shrinker.c index 201211a67827..d1032a4d5684 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -572,18 +572,23 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) if (flags & SHRINKER_MEMCG_AWARE) { err = prealloc_memcg_shrinker(shrinker); - if (err == -ENOSYS) + if (err == -ENOSYS) { + /* Memcg is not supported, fallback to non-memcg-aware shrinker. */ shrinker->flags &= ~SHRINKER_MEMCG_AWARE; - else if (err == 0) - goto done; - else + goto non_memcg; + } + + if (err) goto err_flags; + + return shrinker; } +non_memcg: /* * 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 + * - non-memcg-aware shrinkers * - !CONFIG_MEMCG * - memcg is disabled by kernel command line */ @@ -595,7 +600,6 @@ struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...) if (!shrinker->nr_deferred) goto err_flags; -done: return shrinker; err_flags: @@ -634,10 +638,10 @@ void shrinker_free(struct shrinker *shrinker) list_del(&shrinker->list); debugfs_entry = shrinker_debugfs_detach(shrinker, &debugfs_id); shrinker->flags &= ~SHRINKER_REGISTERED; - } else { - shrinker_debugfs_name_free(shrinker); } + shrinker_debugfs_name_free(shrinker); + if (shrinker->flags & SHRINKER_MEMCG_AWARE) unregister_memcg_shrinker(shrinker); up_write(&shrinker_rwsem); diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 38452f539f40..24aebe7c24cc 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -193,20 +193,6 @@ 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; @@ -255,8 +241,6 @@ struct dentry *shrinker_debugfs_detach(struct shrinker *shrinker, lockdep_assert_held(&shrinker_rwsem); - shrinker_debugfs_name_free(shrinker); - *debugfs_id = entry ? shrinker->debugfs_id : -1; shrinker->debugfs_entry = NULL;