From patchwork Thu Jul 27 08:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13329384 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 19A84C0015E for ; Thu, 27 Jul 2023 08:15:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF9B2900003; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA7F38D0001; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92233900003; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7B73E8D0001 for ; Thu, 27 Jul 2023 04:15:37 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 484541204EC for ; Thu, 27 Jul 2023 08:15:37 +0000 (UTC) X-FDA: 81056682714.30.D503040 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf21.hostedemail.com (Postfix) with ESMTP id 6B7BF1C0009 for ; Thu, 27 Jul 2023 08:15:35 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j4pDVeMc; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 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=1690445735; 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=X5ij/O+E/bk/tTzX9mgxwiCynzBHcXx4EKtI9EsHayo=; b=BpeO3eHemQbyCSZNB8AqCaicaS58AfDTuuS0MtBH+RIyNZcG7aPEF9x2V1ItZwUjw2Jyx1 NJYghpmkJnyReGFrrGj2p6i+ZEu8C35F76efQDqDGs9ZEUy0U4eKO1l/wzekOaB1/4V7CQ 4+0yD9Q+H1rlYZxGWf3HsrkCxxblM/0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690445735; a=rsa-sha256; cv=none; b=p/ACMCY/PPmaSbXYDVKax5+tJx/iBsm4wkZq41xHSDpBGbfdzLWttqTuq7NRzmk2C2BoY4 ve34MA20hX4nvv0R1tooBOXHd4sBgjoh1POf8X7b9gzggarjyQiwL17mxE5sFyPl5Hj2xD WCOYr2/ARnAmhcIBuJLiFH1xx28Ylec= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=j4pDVeMc; spf=pass (imf21.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-66d6a9851f3so168977b3a.0 for ; Thu, 27 Jul 2023 01:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445734; x=1691050534; 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=j4pDVeMcXcw7i7IAx1DNlz6iKEYUEIabVz59nN5q7bAhCS1y2gOKuzdzTgG4j/dBwO H4HIbZq+pOLjZVM5UGP2bbBpIOa2ebzQlUp84F0j/JFisMPJqEmZ2hJuFivDCiuZb9qk P5NgTQLX0gtg3X+vGmP6/3oCCgeQ9FljDUkAtb6pQhQ/VT+3lIzONbNoOLFITLjS+g+5 Vjj6M2H3z3FRG2iT9u3T7VH/LPW2zOuTNtSoF+jLae0SEMd2/P/I3VxNY7Hl9q3RH2MH NSqRY7EFleJMoWuU3X7ly6d0/rJ15DhvMCCJQ4sCCtoszhR0yDF7rbG/n/mEuDtWN3AJ wtVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445734; x=1691050534; 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=ZKManSnH1pI4+jt78CYNm6imlITpUOxdXue0LsJChP643vN9oEb2Lm6NNUL8dBdWzY y9/xAxilnKBZaLTPZmfr0UtNdNQwKZDkgrNiu+QZdwdOjPoa+k7nEO65mck3QJ97K6QD a1tUg2A7ZalMCkSGlDXn+9/sFFO9UcyDZKqGjsTDOe/x4MP7xgmyY7kR9VciN0B861MZ XfYuL3XP+N1d9ntLnWsBVCf5IScQt3NmG9SgKmbAkV5CD7YCMTdYN/Y5geqLFScH8+e+ LUUQ7q+hEzyEjsDTOjnUPtG91/XdO29SoNC7XpaYaz4UFPyu3UplbysZFDV6fnBfVZiz 8r1g== X-Gm-Message-State: ABy/qLYIFVyeWzQQAgxGwS58+0poaTHJwoOIg18Y66FUKMzY3pQ0ASDC xFUCEdmn2jsH0FpiCk7Rbns5Qw== X-Google-Smtp-Source: APBJJlGCk2Vrs4jG84R1mGLjwsvlQmrr2Zz0KCmUr/tZ9etimLEYhkynVpF/d5AFiEeYea7/v2C0Wg== X-Received: by 2002:a05:6a20:7d87:b0:12e:f6e6:882b with SMTP id v7-20020a056a207d8700b0012ef6e6882bmr6451328pzj.1.1690445734330; Thu, 27 Jul 2023 01:15:34 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:15:33 -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 v3 48/49] mm: shrinker: hold write lock to reparent shrinker nr_deferred Date: Thu, 27 Jul 2023 16:05:01 +0800 Message-Id: <20230727080502.77895-49-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6B7BF1C0009 X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Gll9iqcsn+b8qGbHpl817jrZ/O4/0nOhLk565IO6qeox5fB0L00Nd6DUU70/dudlDYgLuiy3dkyn7JpQfiUDS6x0SwZuyu/VlkHXnoqs9sJlvjtfXe5e/SuLrk/GJtIag15g0N77BLhVYq9cWWVeKLQ5FW+SCbYSc6TgPwdtrpSQ3sZF0mv9wYqa57oKKNDb/SQOVnsEQ5MD/HZ0w15/h3Zva1gwU5LrwVrgAX2unPhhu/1ArO9D8CwulguMI1r0SYUJRd+xuEznQVcM62wfOOLg9HXWz+U4+rUJW8MVekt6psCFWIYFY7evpdhy99iPkW2D9/zSEMr9Wa0/TmPj1z+ojlmwKKbRZrpR59UXQGQgNiP13+6VGJrzsx1nrHE0s4VtDUtdSo7YGZzmco8bejyIIFckmibJ5IvpixSPdj5VQrX6lHlKJ53rBTQGq5dTxCKeiDU/JievCIQVlhtq2o7aqG+c5qAklNmGRIBEODxEmfs6mE/PW1Pu2kW5l1VZWDfaOrlBENFmR6GpjWUtgFgaWoYxu0eXCbpDrxiFT+vkC20XksxpdApW/DabqCa3CwuBSKEW45EM= 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: 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)