Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2894205rwo; Mon, 24 Jul 2023 03:04:54 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqCrkco5qlsPJ0xt7gULLRZEA75QWSlotAtd7TVMRzrPdZVNNZXmhTBzat99BdgNS/pbGE X-Received: by 2002:a05:6402:645:b0:522:2111:105d with SMTP id u5-20020a056402064500b005222111105dmr4450494edx.20.1690193093974; Mon, 24 Jul 2023 03:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690193093; cv=none; d=google.com; s=arc-20160816; b=0JtXo0Q91pkMuQz86rHTuEhR3Vd+TJ0TBsogXTBhaPD2KPYqCznbWC0VD3i8dReb4q Jq5Qedn4BGOIkbkPzmXcVD/7obm8mlMVLQ62pzGdqAYmRkO3yyHKO7dLC7Op5mKuTMj6 o6OZrLbbMhAKcTAftywBjXX0UrbHCXLSE0/i/etNeQr9tLG4MQWM2N4XP3hwZLvSRuKS WLLNexnwaPkBFpM1dVjAfLkuZbhvhXwzeS5sAH5uRNPVWHFSsxjlws+TA733NTeL1RzQ KaM+MoeqD10iLZ8OfNd9ENNemM2W2B1PfrvRTSHmGALkn9MOi/n7iyiMagEtUpxfFEun 9NZQ== 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=CMESg6KcZ1f/x8j8WNeV/0Ezds9kYbd4Innm/bU0Ooo=; fh=3lDHiAuENCYj3gWFb2bYij2cH/UC7c23rwbOpuSBNc8=; b=FeKS4RQhGjGnEz+EhwnPrBJDmCD2FBe5PPFGXRIqF4Z8hu3Cv0frj91h9c5bS7JuK0 CSixQGnHiFUjAK8ixpex7sO7jetH2BWoJcRl/RCE3eoEMrg3sOxrBItc1YRXV0YY/G/e NievxTM2dHNmTPx28hbhGmsKQQX6N65R11Tl3aMiiBR8YhVe3Kn0XBX+Pytqts4EQ/mi RnMaGxCAU8hWUuaXifsrc1UduO7lKi2puzKeIjIyqq8tX5ztuCsqJxWWetp83xV27pxW a1tKHz9l6DGrxUoAxBnM1KPP2OmYL1zQ77Abuc4S941j/MxxTwDFd5sSJQb7bPJxd984 vm5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=dwKlx1oQ; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 j18-20020aa7ca52000000b005221ee49d01si2605259edt.626.2023.07.24.03.04.29; Mon, 24 Jul 2023 03:04:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=dwKlx1oQ; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-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 S231563AbjGXKCy (ORCPT + 99 others); Mon, 24 Jul 2023 06:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233058AbjGXKCG (ORCPT ); Mon, 24 Jul 2023 06:02:06 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C13B86EA1 for ; Mon, 24 Jul 2023 02:55:10 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1bb85ed352bso2249465ad.0 for ; Mon, 24 Jul 2023 02:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690192457; x=1690797257; 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=CMESg6KcZ1f/x8j8WNeV/0Ezds9kYbd4Innm/bU0Ooo=; b=dwKlx1oQ8gC3FGBisAur+bDXIIsIsnjGtPcpy7zH7OHDzky5UKxSTJ05GXNV3ifxFh uFNY+8ub7jUvRzU2N0mzwWkyUcySnlCtwLD3JQfZApULo5o50SUYvFf7wmqQeUGg+K3w AqzVxAjjzV5PNtSqJauuHxoQULcgDnOjWhlM27zpLCCDDjhxzzb13/oecO1ube7S7m7P 1safwLAq/c10jFTLUU1Xqd0TB13zkKzwSGxlgMOCVqCgGIAn0g9Om1mA4z6ti880Mese Evcqc6hGgzGiGoOdWdO80KWYfeQwXeXM+h1Vq8tuq+SebTbp5eEFtPf8XLS7hjdlVp+9 zxcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690192457; x=1690797257; 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=CMESg6KcZ1f/x8j8WNeV/0Ezds9kYbd4Innm/bU0Ooo=; b=J+9jAtakqgNo9WiLz3hgih56tguCZ5vSqBh4O8imolQeJfTpaXrm67gi1cOKsw6Lw8 4iK6UWRYewEh9++x+Bc/rFaqCQdkvRv2VWKxT7PTw+c3SyRgUigk7IFy2dLIM0QToMIm ITJRK5eUNuyD7BQQpaNTqv+uuTl5uyuKbDJoptA2X8ynf1IePj2pssTTkjQsLyi9CMnC CPp4NVLWSpd47euuN7EsSI0X4KIAxXYCeakUwjznWIC3cRKz4wCwQCSNAVGukx15wrE8 UjFqkpP025682CmhnpxafNrU9yMybWw4FdgWq13flralkcKE+AIKXLrAl7kygz8uHebs 9M1Q== X-Gm-Message-State: ABy/qLZ/+r6D3vJlTRQBSc5Etx84kC4UzjQxjk1+6BIwZlBVaQlf7CQn URMKWCm41LeOjnq7nCvtMtWg9A== X-Received: by 2002:a17:902:dacf:b0:1b8:9215:9163 with SMTP id q15-20020a170902dacf00b001b892159163mr12209813plx.6.1690192456927; Mon, 24 Jul 2023 02:54:16 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id d5-20020a170902c18500b001bb20380bf2sm8467233pld.13.2023.07.24.02.54.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 02:54:16 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.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-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH v2 46/47] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Mon, 24 Jul 2023 17:43:53 +0800 Message-Id: <20230724094354.90817-47-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230724094354.90817-1-zhengqi.arch@bytedance.com> References: <20230724094354.90817-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=ham 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-nfs@vger.kernel.org For now, reparent_shrinker_deferred() is the only holder of read lock of shrinker_rwsem. And it already holds the global cgroup_mutex, so it will not be called in parallel. Therefore, in order to convert shrinker_rwsem to shrinker_mutex later, here we change to hold the write lock of shrinker_rwsem to reparent. Signed-off-by: Qi Zheng --- mm/shrinker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/shrinker.c b/mm/shrinker.c index 744361afd520..90c045620fe3 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -303,7 +303,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) parent = root_mem_cgroup; /* Prevent from concurrent shrinker_info expand */ - down_read(&shrinker_rwsem); + down_write(&shrinker_rwsem); for_each_node(nid) { child_info = shrinker_info_protected(memcg, nid); parent_info = shrinker_info_protected(parent, nid); @@ -316,7 +316,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) } } } - up_read(&shrinker_rwsem); + up_write(&shrinker_rwsem); } #else static int shrinker_memcg_alloc(struct shrinker *shrinker) -- 2.30.2