From patchwork Thu Aug 24 03:35: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: 13363418 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A947C71153 for ; Thu, 24 Aug 2023 03:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239637AbjHXDhT (ORCPT ); Wed, 23 Aug 2023 23:37:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239617AbjHXDgs (ORCPT ); Wed, 23 Aug 2023 23:36:48 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55A9310F1 for ; Wed, 23 Aug 2023 20:36:46 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-68a4dab8172so653902b3a.0 for ; Wed, 23 Aug 2023 20:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848206; x=1693453006; 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=N1xChJFXyipb+5RQle6ZyegT3xc3OvIzC5mKhUrbULfJMef+H89T8PEOMnmL4nJdYQ N8zZwV0W6lbNmMmGxMNFgNlUOcPRpyP19+RyPJ8DlNbMVXU40NlXQPhjtgkkI+OTl/K7 8L5JzHE5Msr1tHKYrvJM6quTVdBT+mo9gcMuVKr0nx8NBTltN2C83er/zV0BtgV1PD4/ ACO9Ma9B1JjNMHcrUYOWt8NRs1kA8AusiSw9xGAg5XIzcL62aspNXe2GuAjNFyNoKWrc zIFZvqDP/A4zQqbJ8hoIzQk5YVJUVqKqQiRZYslXjGoF2Cw8Qu1g6Xr1Pa8bM2i/ytkS 4vNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848206; x=1693453006; 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=dlLILlyCXdVlXREsmSn52syxe3NyRAD3ogy6tVQMmaC2AwVVvVNWDm1N6uxVNgewKF fIdfoolzDGfpNM3fum7Zaqjz1xLn321zvrm5hblYM15CSnO9f/JpPGKnyLCFR3H4UgvY ftUYXrVP/aVbEpMZlnqIscIXYCY3KW073unn9iMFRokD7BOBUo2gLq121h1ZrrKdL235 M2nGgNAGADiPjtpP/0tEnds3ruw+WT6Y2TvjyCVJys3NiDrOr5Wd7n6ok7gZAt/iEj+a DPoaRD9Wxed45Nc05lCSma8xarIf9K0d8Xa7DhmaPNrIyOeS1zD6vkC3gKqyj6SPropi rivg== X-Gm-Message-State: AOJu0Yz6cWTKrhg3pojBR3+l0JEwJnEQ8Lqgf+RmvMLZQZtC9hT2KaRk zHCTiRZLsdnY1TA3yGN9YmUJRQ== X-Google-Smtp-Source: AGHT+IF/No7OicKHtxqrUxwVNpcooeU5Pi6D1w0lXRqE33BiijaIAV5KxcraEu1IfHFFlHpUklkwxg== X-Received: by 2002:a05:6a00:1d85:b0:68a:6cec:e538 with SMTP id z5-20020a056a001d8500b0068a6cece538mr7234848pfw.3.1692848205878; Wed, 23 Aug 2023 20:36:45 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id p16-20020a62ab10000000b0068b6137d144sm2996570pff.30.2023.08.23.20.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:36:45 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev, 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 v3 3/4] mm: shrinker: remove redundant shrinker_rwsem in debugfs operations Date: Thu, 24 Aug 2023 11:35:38 +0800 Message-Id: <20230824033539.34570-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824033539.34570-1-zhengqi.arch@bytedance.com> References: <20230824033539.34570-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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;