Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2892137rwb; Mon, 7 Aug 2023 05:20:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqTtFmb1/I7Hh1xS72nacJ+8eMbVLa0qedqeEwZHADq7SgTkkxlawr5nxzL5wnZRmg/lzD X-Received: by 2002:a17:90a:9318:b0:268:4498:ad68 with SMTP id p24-20020a17090a931800b002684498ad68mr8470015pjo.19.1691410843553; Mon, 07 Aug 2023 05:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691410843; cv=none; d=google.com; s=arc-20160816; b=Nq8jYInD89qUlneslobKrAIqocunSaFnsi8TNgQX8KI66fKxL1MAj+1zb8I/iKUzjO nhQZ7JSEwrPFr98lM+VE2uymfB6X+bqCHrTZXoQUNCxI4XRedzusNxpjSislYw3YvpXl +FOqmoDFnezRy1KPc5a1jA2tiJO26/li3x8PgVsCPfzn0adxoudk79jVnv7p1a5zvwIa sRMHKm0FN0p0sXhJ8lLmsxsiGnrNzsi32m9T/K5qOMrqmyGHiuAEo1hihL9za7kGyWKH rOZowFe0CE+voX+X8af05NAFWcz9jepNJhPxZloNL3pcZhEktVJYxUXuhBxqcQtUBbxq 7Mew== 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; fh=LQnZnJgbwA2rofRvgLxtxvFjbWmQSZR0bRTgn+flB4A=; b=0ohnd5snTw9eHYI9KbsngZvwvOfvhOt7dbN34KpX/Gq8OVEef7RNnBqJMGVoaJ/zMq swTpFO7dwcMOHEHWLWu6TnRBgMSDvigwOxMEN1bYpgxXH5/lHihoz9B5s0LG9YuGJDb0 CSTi2qzrQSfDnMJ5YryB9jximhHAhVxIjHZg34pePBCWC3hmNn4fUsNqOV9KZm/44pYc JIAhzizOnzAaXnkpKHrk8vi9IUtJX3x95P2g+/nNfQfnQARRmso+RD4QheZ2Dqhxn7y8 QK048AAciBXji9x29kHtOOH/WQxQTP01Br5v6pzioMw+su2lgWN6DiydnPVx1JP5MxUa 18Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=HMartYQi; 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 i6-20020a17090ad34600b00263ba5d7088si8736856pjx.48.2023.08.07.05.20.29; Mon, 07 Aug 2023 05:20:43 -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=HMartYQi; 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 S232571AbjHGLYL (ORCPT + 99 others); Mon, 7 Aug 2023 07:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbjHGLXy (ORCPT ); Mon, 7 Aug 2023 07:23:54 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBA9F4EDA for ; Mon, 7 Aug 2023 04:21:12 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-76cf9cf65feso24048185a.0 for ; Mon, 07 Aug 2023 04:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1691407221; x=1692012021; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=HMartYQiEgZccrg3fbIeq3/265dD7a57xGkX+O552CwOXG4i0Ez6uGnVSsKuKG2L7x goXygN4ESqwcWJRR2kZEJxK7v16XbOKFNYqEPQIzBNakNaSBzRYRGWgB1FwYT4TbQIkB yXt0DVCejvu+T6XSnzjYBgR2ZxbCcT0p+73ZzydRYNQlpApqUKJT7t+RhKlXgmxYefCS eXaMFUbYPO9F9mRtYSHNGmh57jLxNZJj/D878b1TZxqUPQNTbOulBj6hBwjcPirNvbBL snbpcwC6JH3Ya1vqDc/i3aXRof/JsMfJR34DpPV7JlLMFDGArmo3Hc9zisC26InIRLmR 9oxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691407221; x=1692012021; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=FycHBc9Y7m9hTJ9zETDJXw1g8vohxkBGqYZgsaX3pycqv+/twml0Xi+xuosefx1iWO ChvQ08XS6x7whv/tXx3JLFWIC2bI4DYaVtoczX63GI8ww1FapZmp1+zn86OeboNwIPcA IeBC3TX3PPju0zQyldtSAlrwmiWg681Ylui1M17iBAoR+oPw8D3fM1fYuH61dU88meRB 09Mu1XxxWY4gJiZrkqyPcnJaEiyW4oVjU1Lqche79rsFLVPrYUGBVfZ2LH8O+IXrXB0A ymu7JfwKLREtte4+yioOHMN4YddQAyKvRma7WzbVAs0FsImkPEefCR/ES3NTO+LAVu8h 4+bg== X-Gm-Message-State: ABy/qLYShN048xbMSv4sH51HLLMo1LixW2iRswfXu3yYD/ZT1zXgRC9N oJLsJN/NDUv5qLQ8nGNSJWeV1YD4yoQG1IXpKPc= X-Received: by 2002:a17:90a:9c3:b0:269:41cf:7212 with SMTP id 61-20020a17090a09c300b0026941cf7212mr4973775pjo.4.1691407200010; Mon, 07 Aug 2023 04:20:00 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id y13-20020a17090aca8d00b0025be7b69d73sm5861191pjt.12.2023.08.07.04.19.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 04:19:59 -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, simon.horman@corigine.com, dlemoal@kernel.org 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 v4 47/48] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Mon, 7 Aug 2023 19:09:35 +0800 Message-Id: <20230807110936.21819-48-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230807110936.21819-1-zhengqi.arch@bytedance.com> References: <20230807110936.21819-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_BLOCKED, SPF_HELO_NONE,SPF_PASS 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 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 fee6f62904fb..a12dede5d21f 100644 --- a/mm/shrinker.c +++ b/mm/shrinker.c @@ -299,7 +299,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); @@ -312,7 +312,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