From patchwork Wed Aug 16 08:34:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13354734 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 C8F09C41513 for ; Wed, 16 Aug 2023 08:36:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50ECB8D002B; Wed, 16 Aug 2023 04:36:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 497F58D0001; Wed, 16 Aug 2023 04:36:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3127E8D002B; Wed, 16 Aug 2023 04:36:05 -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 1FA5A8D0001 for ; Wed, 16 Aug 2023 04:36:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ED9D81A01D1 for ; Wed, 16 Aug 2023 08:36:04 +0000 (UTC) X-FDA: 81129310248.30.8731609 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf04.hostedemail.com (Postfix) with ESMTP id 1A3954000A for ; Wed, 16 Aug 2023 08:36:02 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Cya0Fxlq; spf=pass (imf04.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=1692174963; 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=v13l7IPlOPgFsnMxGKXfyNRR5BVZeBzBNEaAsOIHoYU=; b=eKd6zURJRW6UUZggBj0cCMs9HrtRyk6MaicJIsdKakit78tOrsIjkyXRdBboBED3jw7nzc I4zev/FpDNYttZNbuV8PHIyXxMMw6F2PNj51/lglHGj65lroN+dgjjtiU0J/jmh7xQYQvw biI4lo64Lzxah4bpgwrs1UmCuFIjKkc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692174963; a=rsa-sha256; cv=none; b=0cWe6FEUQVOp5VO1M0xg0CCinUmhqiz0EYKgzOAhg2uKBciGLA4QJht0dLMX7JDYaE6KUJ 0qLvRDOXSTu+sUrmQLSl/+vTqY/e3dZC/Ba9RCdW9KkwFBaKEdpnxLEVhupzwDX5ACJocT Dg9CdvzA9knC/QfgESMP7wpzrVTL7CI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Cya0Fxlq; spf=pass (imf04.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-6873f64a290so1768640b3a.0 for ; Wed, 16 Aug 2023 01:36:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692174962; x=1692779762; 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=v13l7IPlOPgFsnMxGKXfyNRR5BVZeBzBNEaAsOIHoYU=; b=Cya0FxlqQyLZEroXNZk/xmAruZD4t2yH2du/O66Ed0VRPZDEOyZPRffBcEvP7HuEOA LBh84tW86g14ySan22a5QNsb0cry8ZMRVhKdpQ7IwM6x6CXd+aHB1uLMFM7LKnBIEidW MxKYco8X9KuAaEu/tQZmOH7YKbH1kkg+D4smGVZHtQo4/2ttPh2MOdtMrmR6FWZ71O5C hxTJnXYDLk9lIPZ5IpP3Xo1WYZhQHzfJJDwDlHN+js+BDpEOp9bf7emx7MSjJ4NzGyId DfLKmdnvHJtnO3OOV1eURaCwflNGnEsTjNw1DynpEsLeKdmNr/5gemJjZDlP6LR1sQGo VwFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692174962; x=1692779762; 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=v13l7IPlOPgFsnMxGKXfyNRR5BVZeBzBNEaAsOIHoYU=; b=G5HjysZU0HXQyrs11nWIGDerpJu+m6kciRKj3OmSoMx8QTRGUgH4zj8xX6MCW/e7TR y6Y6HQGjG/SDw+Fgo41XiUYJn8a10ffZQAw11cm1Am6hFKtIeoI8HxXOMGvQsjns67Uc tdCGwnImtsIdyyQsMDeRh5KhF4oaZOQsl+F6jUB30a4BctqLua8Gq+rzy1hfrSJ3YlxS /njmefd3hTGjbZNJqe6xV+hizaaF78p+bivg0h+MWk78QxsPvy7xLJ8YssuC1k2reZiC VLQ1wX3DYPTHGmddXAsU68p5OtsTvoIOdCAri3FObWKwc0W5ZegoYOSLeYYdW++lSj9p oF9g== X-Gm-Message-State: AOJu0Yytr9l7BCYHFPSj8+k6+yjNsQYvxDXF9z1ISbcQRc0Numvi5USp 7xm27uJ3dnR+la/uiEsCT/q1hw== X-Google-Smtp-Source: AGHT+IE+pqjEsxtDBKCnfOYW5hSpBYIW97yeRg+vb7eGqw4ZPe5gd676obnQEAvZzfvbXIOzGXycpA== X-Received: by 2002:a05:6a20:4281:b0:145:3bd9:1377 with SMTP id o1-20020a056a20428100b001453bd91377mr2045479pzj.5.1692174962033; Wed, 16 Aug 2023 01:36:02 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id p16-20020a639510000000b005658d3a46d7sm7506333pgd.84.2023.08.16.01.35.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 01:36:01 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev, joel@joelfernandes.org, christian.koenig@amd.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song Subject: [PATCH 3/5] mm: shrinker: remove redundant shrinker_rwsem in debugfs operations Date: Wed, 16 Aug 2023 16:34:17 +0800 Message-Id: <20230816083419.41088-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230816083419.41088-1-zhengqi.arch@bytedance.com> References: <20230816083419.41088-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1A3954000A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5kq7nsg6ytnyxk67y7kkc5p4wky3akyp X-HE-Tag: 1692174962-376 X-HE-Meta: U2FsdGVkX1/0LnSLmosAnLfKVKBV4LQkHD1+I7F70vibgpgM2/S1QbTHYj74LL7EgKLKSRudDRCo93F8R3iT/aXp6hgi+4Q67a8jZPNaRsZ7pCAClH7XVn+RbYm2OsuXS7uXD5h5Im6I2KZbgMllPhlT5DGyzHzBq4FFaVHpYKRYIkjzVXdamYp0JP6w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RKTSkkCMIGkyAjqOV6nH3DWiNdYcFdmVfowm9f8W5nNyb/cDnqQErksJoJceLVbqzVl4pZNj+nDxVsl6SeFEw95nId3PmVawGVWHCMVVh3yf9bcqBMLAoWZpOoghGNZSHOGK5HjSFYDRgxZzPcQIDXQTk+KfFH3LVe4TiQygFrQCSXiNQSm6JmijTBGSlwL61IbJ+x5V0F0J05Y6e+0bko4jCuggvVGAUdp1vW8DxDqFsdVgfWE+TJKh9DHErARa2WJoGW/p3tXM3ariZ93RVw0zEEaf9NFpbf/MY1EiQrvc1aKSVfuhCJ2A4= 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 debugfs_remove_recursive() will wait for debugfs_file_put() to return, so the shrinker will not be freed when doing debugfs operations (such as shrinker_debugfs_count_show() and shrinker_debugfs_scan_write()), so there is no need to hold shrinker_rwsem during debugfs operations. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/shrinker_debug.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 3ab53fad8876..61702bdc1af4 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -49,17 +49,12 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) struct mem_cgroup *memcg; unsigned long total; bool memcg_aware; - int ret, nid; + int ret = 0, nid; count_per_node = kcalloc(nr_node_ids, sizeof(unsigned long), GFP_KERNEL); if (!count_per_node) return -ENOMEM; - ret = down_read_killable(&shrinker_rwsem); - if (ret) { - kfree(count_per_node); - return ret; - } rcu_read_lock(); memcg_aware = shrinker->flags & SHRINKER_MEMCG_AWARE; @@ -92,7 +87,6 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); rcu_read_unlock(); - up_read(&shrinker_rwsem); kfree(count_per_node); return ret; @@ -117,7 +111,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, struct mem_cgroup *memcg = NULL; int nid; char kbuf[72]; - ssize_t ret; read_len = size < (sizeof(kbuf) - 1) ? size : (sizeof(kbuf) - 1); if (copy_from_user(kbuf, buf, read_len)) @@ -146,12 +139,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, return -EINVAL; } - ret = down_read_killable(&shrinker_rwsem); - if (ret) { - mem_cgroup_put(memcg); - return ret; - } - sc.nid = nid; sc.memcg = memcg; sc.nr_to_scan = nr_to_scan; @@ -159,7 +146,6 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, shrinker->scan_objects(shrinker, &sc); - up_read(&shrinker_rwsem); mem_cgroup_put(memcg); return size;