From patchwork Mon Sep 11 09:25:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379034 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 EC600EE57DF for ; Mon, 11 Sep 2023 09:26:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DA086B0190; Mon, 11 Sep 2023 05:26:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8896E6B0191; Mon, 11 Sep 2023 05:26:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 751BA6B0192; Mon, 11 Sep 2023 05:26:26 -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 648026B0190 for ; Mon, 11 Sep 2023 05:26:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 38D7840920 for ; Mon, 11 Sep 2023 09:26:26 +0000 (UTC) X-FDA: 81223785972.29.ACA937F Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf24.hostedemail.com (Postfix) with ESMTP id 6A5CE18001F for ; Mon, 11 Sep 2023 09:26:24 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N6aEtRa7; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694424384; 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=q7bwmZAFhPRfqsSPFwB3IV8LJcvLn4gI9V7ELWjZ+Dw=; b=XA8AVMxSsEpx+qAFK97beyTrXjT7ONruuncyKsh9XyatA0VgF4YWDh8I5mKbgHw4EcQUHv xn7AzTBcGLyR4VizOOoC4zdQ411OFtlHAU3eI95ArQNXA0U+O5s7ge6PEd98VN3/UhQNnh tPt0yiKNTMxVrxxUQObM7y34DO4vzhs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N6aEtRa7; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf24.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694424384; a=rsa-sha256; cv=none; b=3iJm6un2AXMvHJ73U6HyXkPJjIMY76m4Yi620Zas/QPpkT/ZA9coPxGdohxFpdyma6p5Ol SFuItXD3gn9D704drB5DUyBeV8LJqgbT01spQcOW28IXmr+28B2HOtF1kElyuWHbE5wL+s dGn5iGUENsh+1ihGXkHtDY8F5S1NIqo= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1befe39630bso9331395ad.0 for ; Mon, 11 Sep 2023 02:26:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694424383; x=1695029183; 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=q7bwmZAFhPRfqsSPFwB3IV8LJcvLn4gI9V7ELWjZ+Dw=; b=N6aEtRa7N9Qvuxh6qdRLcjWFERhIKdrECksC6H/lu14Cz52WZoRfzSFERV4mRFlxpx Hl26YkWkalPTkTlwXcXxGB6lTKYYPEbRrOqwucVhB/AiHPQ1nfL+CBldyXJp2qDnmhuN UKlO7lde0BdrwHYdPym6PhOAb9/ZnckKY+Yw50JceW8BoZgWLHY7/prOIgNdvBRqIrA2 r+ONDvw6ho0CYU0AmeTbdwfS5XeyXzpBcNhYsZHj1g81bb8SFr2l6P6ffHceOxWFj9+V e/FEAeb6reQp6hDWVUoSUCGL6wC20mEd+l6fCn50vW2tq20zNTnnGf+wG25TMqZyGoKD gwSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694424383; x=1695029183; 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=q7bwmZAFhPRfqsSPFwB3IV8LJcvLn4gI9V7ELWjZ+Dw=; b=fTVrJJA8ki43qXhEXYf3HwGiPFqLvgO0rV2jeoCBAa05+1upPGR6x4mGQluueWnX8n pbwu5nVwJMR8KwZlQhRndQ+BkFvCswOatpGsxZPoWy28yNfsZZbO0TMlfstEXQxWVMc7 UtUj7iWGaOZCr/arA/iheFLZD7KOe71ptpZsaZdxhtJ5JZigmplyVYirccrDRJHnGR6g 9fQI9jYgWIE3vHG2wldZS0qH5zU3eT+HJlRDzNLM+/Rc4XLWOhqeB13EDaDZq+zw8EzJ up2Qcm2SQLdvvDXKjdzYE8VNQP76XQborTsgr3ztlcccVhB3VwWFa4m7QCjDb0n+/Sx3 QARA== X-Gm-Message-State: AOJu0YzYGQXHb7qdM3VoXnjPrRsDzk9Zx0qQPBUFrxslr7BUiS7Bx7MM sdBBj5griCUnNRYwS4jYPGhvIg== X-Google-Smtp-Source: AGHT+IGuwOOmOTYHUBi51KVf+G2IH+LqVvZcIpa/lkU6FOZxO8pwy9QvfijhxoNvFM1VAXL8ZDsGDA== X-Received: by 2002:a17:902:e546:b0:1bb:9e6e:a9f3 with SMTP id n6-20020a170902e54600b001bb9e6ea9f3mr10956272plf.4.1694424383369; Mon, 11 Sep 2023 02:26:23 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id q9-20020a170902788900b001b89466a5f4sm5964623pll.105.2023.09.11.02.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:26: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, joel@joelfernandes.org, christian.koenig@amd.com, daniel@ffwll.ch 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 v4 3/4] mm: shrinker: remove redundant shrinker_rwsem in debugfs operations Date: Mon, 11 Sep 2023 17:25:16 +0800 Message-Id: <20230911092517.64141-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911092517.64141-1-zhengqi.arch@bytedance.com> References: <20230911092517.64141-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6A5CE18001F X-Stat-Signature: p8mteo56ammozaq3gpaw7rxozzqcbcfr X-HE-Tag: 1694424384-788544 X-HE-Meta: U2FsdGVkX18T9PA/z5NCPZ9Xp2BIaeA4d8SuqfnhwC1tyIyRK1e9FvDB6yQ593bwIhz+jFni+j9Ag7+vLvqZHf/g1wWIXNu2Znh6GWZeqRUvAdL+gIiNq/b6pyHoRXCV0Uty/V8jsmzK5sN6ZJP2hQW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+eTy2v9/+MH6AvKArNv/ocTTHwR5yTQl22ypqsFd3rzZ9erdCl+Kl7meE+EELH6ETX9MiS69O8YrYwZ/GUDkVB5e7tIUl6rj8lcM2IeMjlfWjT4PX8sn00CP778qMrfvBQNbt/AMcZPZSIyuTyIKJtvlGF2aeKRJOa/2LcCjs7KRdQYwGuBpQ20GiLg7GtGjzahkVr+lxeLKXJvqWK5h9zE/l6EowVcfl/660yZmwQ== 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 ee0cddb4530f..e4ce509f619e 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -51,17 +51,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; @@ -94,7 +89,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; @@ -119,7 +113,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)) @@ -148,12 +141,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; @@ -161,7 +148,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;