Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10601027rwd; Thu, 22 Jun 2023 02:06:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lMTaw3NyeDOawBdk/k1QYbF8nGvNPaGcn8XUJdZWAbmUPCl5ak/WNuS3HnNf/R+5n8f7J X-Received: by 2002:a9d:6f81:0:b0:6af:a180:3357 with SMTP id h1-20020a9d6f81000000b006afa1803357mr13200526otq.7.1687424814937; Thu, 22 Jun 2023 02:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424814; cv=none; d=google.com; s=arc-20160816; b=wD9i1elLVS4fxg/+fHroDTwhAWm3WCM/O3xoYuKNndW2Juq8MrUNx2TeAzMDNwcFJI UxznuheBPlny/ln5BvkTcnTYBGDOzbrtc0WwfGk+sfGCo4Jql4Zo9EScdGtomVKAs21Z pbzF63Cz+jssIkS7w/dmq+gHT9GKUUxIN3z0X5vXQwQYRCGNxkumnk3VVkALx2wk+vXm emkc4aksKvwd3ParzUYrek6GZqz0hsfSMx4yXRzHxfzUZjDlZIKz9MqnNeSAJFyRLoiE fjo7ILOJTo9aICXQol/Z6gotwzse2a00o0VzD/NO/BZb1bBE15uLczAADX4lb9tgZsau Dn2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YpqAnPCFjvBxCUJyQNRij7IdVYJH6Jib7EICYqtSs4Q=; b=NDhrrdJQZerrQtuOj6Mb/G3XOlTvUeOSmgdCm0Jo7wgU33SkQab3r9nZbZsuW5rvZX 9+VRDyS/lRuODuDo1gXyM2d3aP9QamhlFDYUuKTQEH3LqGBibw95Mctd0qbKEK7tl5km phnNEvc3hJ8k2n9ZNy54KZmkzrpsjWizeu0tUa8DPaKPUtN/i5/Wo4yyadmbppTxchIw ZOY62mq8QWq/VLntLJELPSW2yq0zsAd3DDLwGHfzdpUPHg1QcqGkDoY24UvOSYf3z+pt kiAekT+HaFP3Udp/I4sIhBlPBYo5cm1L+rg6Dh7YsD9t5zOCqFEgiHecMYveAmo2kWO/ BrIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=I9WP6mv1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a638543000000b00553ce42135csi6015778pgd.812.2023.06.22.02.06.41; Thu, 22 Jun 2023 02:06:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=I9WP6mv1; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232128AbjFVJGP (ORCPT + 99 others); Thu, 22 Jun 2023 05:06:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjFVJE0 (ORCPT ); Thu, 22 Jun 2023 05:04:26 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A45349ED for ; Thu, 22 Jun 2023 01:58:12 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b693afe799so2466805ad.1 for ; Thu, 22 Jun 2023 01:58:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424252; x=1690016252; 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=YpqAnPCFjvBxCUJyQNRij7IdVYJH6Jib7EICYqtSs4Q=; b=I9WP6mv1rDRCGtgaLzA9lhBXeFPAHaj8y0iyY2DOjVEWCsT2F7nfNJVwyIikm+kMao zO6QJGdxbeP+Xd2yLUuD3B5OfZQRm3B4q5mm2BLvCFNnuFgYbDreBXTpY911jw5PjLjw 5qBcX7//daeu9fw2bM5v9uWJQ3Yj963JAAdMROcF9Ug6KJW+BwPKjtr4qnEx+svXyNj4 WQtBJXjBe1rX51UFB2Mb+BbnprNNOvKWLYHk9IXF69UQEETABYtrhl0ZHyku4x/+376s ovmIBUSgYXrVJUG8L2WcJE6QBBiCJCq44tzgQbbUxJYU3EpXiLR3t2TzR3wvfdUTA7wG r7SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424252; x=1690016252; 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=YpqAnPCFjvBxCUJyQNRij7IdVYJH6Jib7EICYqtSs4Q=; b=d1dt69IBYBbHuHf9tSKrB+GNvMCH1wsXcILQSCJhz9a8IPwHVxuqLtmARUaQOFyPZX rLJ6kr6zpst5Cchm/2G/TNwm57nxjNGppQ9F/ITrYgj2QISS2/BkXWfIdK2XFeX9OTYm kph1uh6pt0SeuD9JnBYjuce7O2Jtn855RXwVOeKOecYKbKJPJ/4ToL0BFbdq3xyuJnk5 cbYzWLnrGg8kflPUfFwWa5/xVWYK/nOXjcPJXc2dDVp5GYPFPoo16KS1jdZWM1eiJlRm DCL/14pjIQ2MWt6om4TWrvZ34KkRkih6GZmQC1+tPJ9loZI1AygaN0dvIdnN7temJBng h/KQ== X-Gm-Message-State: AC+VfDxWMgr0GCPvKGk4erfxwY1Ile9jC602A52UIwMBym2wvZaC/v+i Trej/di/p0EQKymk7WP4tHsW3Q== X-Received: by 2002:a17:903:32c4:b0:1b3:e352:6d88 with SMTP id i4-20020a17090332c400b001b3e3526d88mr21673124plr.6.1687424251794; Thu, 22 Jun 2023 01:57:31 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.57.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:57:31 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 26/29] mm: shrinker: make count and scan in shrinker debugfs lockless Date: Thu, 22 Jun 2023 16:53:32 +0800 Message-Id: <20230622085335.77010-27-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Like global and memcg slab shrink, also make count and scan operations in memory shrinker debugfs lockless. The debugfs_remove_recursive() will wait for debugfs_file_put() to return, so there is no need to call rcu_read_lock() before calling shrinker_try_get(). Signed-off-by: Qi Zheng --- mm/shrinker_debug.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/shrinker_debug.c b/mm/shrinker_debug.c index 3ab53fad8876..c18fa9b6b7f0 100644 --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -55,8 +55,8 @@ static int shrinker_debugfs_count_show(struct seq_file *m, void *v) if (!count_per_node) return -ENOMEM; - ret = down_read_killable(&shrinker_rwsem); - if (ret) { + ret = shrinker_try_get(shrinker); + if (!ret) { kfree(count_per_node); return ret; } @@ -92,7 +92,7 @@ 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); + shrinker_put(shrinker); kfree(count_per_node); return ret; @@ -146,8 +146,8 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, return -EINVAL; } - ret = down_read_killable(&shrinker_rwsem); - if (ret) { + ret = shrinker_try_get(shrinker); + if (!ret) { mem_cgroup_put(memcg); return ret; } @@ -159,7 +159,7 @@ static ssize_t shrinker_debugfs_scan_write(struct file *file, shrinker->scan_objects(shrinker, &sc); - up_read(&shrinker_rwsem); + shrinker_put(shrinker); mem_cgroup_put(memcg); return size; -- 2.30.2