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: 13363410 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 1BA1BC71153 for ; Thu, 24 Aug 2023 03:36:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C84F280069; Wed, 23 Aug 2023 23:36:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 751EC8E0011; Wed, 23 Aug 2023 23:36:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62383280069; Wed, 23 Aug 2023 23:36:49 -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 4F2288E0011 for ; Wed, 23 Aug 2023 23:36:49 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 20271B19D8 for ; Thu, 24 Aug 2023 03:36:49 +0000 (UTC) X-FDA: 81157586538.22.6EE84BC Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf03.hostedemail.com (Postfix) with ESMTP id 5AB3F20005 for ; Thu, 24 Aug 2023 03:36:47 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N1xChJFX; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.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=1692848207; 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=v+PHQbPy0PLMuV/lpm/R4AF5qBQsV7m2ygqzdWKBe1fmFCAXgfU3MvtEUo8kDv4GX4FQ1Y PGeaCndd8GdLr0QxSzcxyiaSEibCN+CtvxIx9ODKXZ5rLfYWDeBBZxN+BxfwJDAu82Hone 7WfRJufuz1MgwKFb62sEwgMBqbphQf0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848207; a=rsa-sha256; cv=none; b=pY8u1f2O2U+Ybt0TfeiF5JaAJrrqqMpRRnvrGAWvESVVKcaEKTL9fF3xzZBMrOG7vLTRW7 AVnSWQ/DjYUNYQEYm0Gx3rUqP8bWd0Dk9iwiT+3B3tB4sMXV83k1+HfLGkyhqR5AzVfCFI nR/z6tlE98+uuYrxdnr/YmlXDaXhFZ4= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=N1xChJFX; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68824a0e747so1236801b3a.1 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=IEjU8YFzF+ll0WOXqJYtfilCPkQoWJVIbhiNwAceIT6QkqXNkxHI36YiUiNLoGhNzN 2T4BaxBcC3o77DDVneaPfIouHLSTBv6Yyq+yJTdWbpS6mH2ey74eJyNTHT8gJ1+J53qx BtFdVQHX0n/ILXJaUkfYpYfFaKYB/QOPJnSssu4vivMnDkiWfKtboTC/jvaFwRY8Y05a SZiDFN/WcoPdg+ZsJcKaCWfbe53lDMWJcce9z9UsvtYMl9/8NQJZCZV/IuEoTrOQpG/t cu4uM6aP/xwqhrXpYKprtxirQh3glGbzfOlIOXv7t0EtFVupeZIolrDywaXeHfvV4sP1 DLVQ== X-Gm-Message-State: AOJu0YzpWQqmHPGw0O0gT1Eved3CnPMldHnJhQCGvJvM/q7gFRTGWzBE spVxE1Xn/KGYsb+Hkeig0F1uRQ== 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 X-Rspamd-Queue-Id: 5AB3F20005 X-Rspam-User: X-Stat-Signature: esjchsahcdzxb8qp6jmsfgocyni9urc8 X-Rspamd-Server: rspam03 X-HE-Tag: 1692848207-634368 X-HE-Meta: U2FsdGVkX1+lYFlSas/k24IPpYr8hK5TgehXYEmORVEQYK1+70yliUjfZnzDwxJ03UAWNg/FtyJcGaie2DvA+h1BkPpv4ekVGmMgp7rmV/Mp/hx5cO6F3deNBbZbf7wCy3yego0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fIMQdvn6iLMZCGBJcbuj/Z0OU1cmuK78MJLnK/7336DqT8uLmdkJJ7mYx6iNUFCi9+XQQRKWNHpTNQZXfqC2IAkudffe7TauTDbxfzeLTvH2vJc66HW9pk30qzYnLeEKYW/msA+96PfjVVdFzlBRqwpehLQTSeTGyRMp+mH4IWZZnulIjRP6hIn6i49rCIo405AxRxInyAErEromNdUZoEZVrY9GXVwcgdp5UxlfoqQFw== 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;