From patchwork Thu Feb 23 13:27:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13150329 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 36A93C61DA4 for ; Thu, 23 Feb 2023 13:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDE506B0081; Thu, 23 Feb 2023 08:28:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8E606B0082; Thu, 23 Feb 2023 08:28:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B30196B0083; Thu, 23 Feb 2023 08:28:23 -0500 (EST) 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 A30B56B0081 for ; Thu, 23 Feb 2023 08:28:23 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6BDB8160248 for ; Thu, 23 Feb 2023 13:28:23 +0000 (UTC) X-FDA: 80498635686.21.DDD0E69 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf17.hostedemail.com (Postfix) with ESMTP id 9AF9540010 for ; Thu, 23 Feb 2023 13:28:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=P9pp+ZyM; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677158901; 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=B8oNy9C+Y/zmSEnFHZueuiP36FW/sue7PAxuyUaJKNA=; b=kSsLI9DhpKy5L6zOcWfdFlKy1w+PC+lFMp4ceUrd9g0e8jqxb4AugTVEDP893Hc3h96725 agzj8jBphqM9m8b6rWOMi8IiAeW9cHdKhxawaCjCMQUYI5XnLxQHw36CQ7NSZKSY9zA35E hms8IbEudDyKK+qW2CjeJ0K4IH/tZ7g= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=P9pp+ZyM; spf=pass (imf17.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677158901; a=rsa-sha256; cv=none; b=kLHFvJu4zMa6bQ5puXJiVJDNakTALuwvuyG6RwiU7W52AGWK6nsdFaOoUTvTboBl4ZgDg1 NYxTltIJ02sHBJvzbPFeIeWgCLdEHWPRQbIr9VQZU8Tat9MCXSEN+iVT3PxgC7pQZQVGyE wWdSYYp5ByDcZm6UJPyTO5nJ3BQYNLE= Received: by mail-pf1-f180.google.com with SMTP id b20so6677638pfo.6 for ; Thu, 23 Feb 2023 05:28:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1677158900; 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=B8oNy9C+Y/zmSEnFHZueuiP36FW/sue7PAxuyUaJKNA=; b=P9pp+ZyMjawowl2CXNZ8AfWA4FDgA5DbRRV8Xgup0TXSnw3gGKc4YOluAUAPyTi+8N Eowu4hN9SdqhC2D6NScYL5anKi0WPpJZ/kDZVTjDQu+/GSTSXQemisE6KgdRU/vueJCH m5Z2d5bsrBDjNoX+11dfufhV13nj8waePZO9KexhDHGlwIWF2Eic+82YX2EcOzsUP/aF sdp2wkR1m8GXzkKkL1ndWZsnYALrWwQQa3JIsN3tgm5LwRWjlG9XLi3n5hjONfp4f/gx actRJ9hq1VYMZLcfQYjdow3np6b8hCQxlhtnE9rDWirXh8AxOKVOLv1vhYi0fp0ratLL LzNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677158900; 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=B8oNy9C+Y/zmSEnFHZueuiP36FW/sue7PAxuyUaJKNA=; b=ScjJH/YYIU3azHIBcjAZh5nKJNHUDFZcXFJUnZ0n27bn8zo6iHaOrkoKeOZbZu25+P 3z9z6WON/2jGGLVL+XOv25VqK+EzapPdjRIJytQxX5bHoaG7dWznP98/beQeM3cuUD6O 4MAkvYzc4wxiK/swyvJdAUMUCxOIwd2lPEHuLEcZ22wXzEOiWxptut1VppUw7VY+y+2M lCzEos1V2JJc3r31B+KoTJdakVBTxJayioeiBCJJYbf8A15V13OTmkvgNGtDJqTP4YLj tigBuKxJYxwio6Ie1fGT9siNeBqU+c+lAWk5dIA6gicBXTx9Kwsj0u+WSi5o1KuuL22G OeOg== X-Gm-Message-State: AO0yUKV90v8SAiZDMvdRYrYIqu9343bM3wzEoOtox90QSosaYppFwXfq 9PSEUZBaZT8JfXJTvENcEhmDvg== X-Google-Smtp-Source: AK7set/qxxKJpUWiKsq4lL0Upj2vUZx+VL5loQcaP10700XUcw0lQhPoWvn8hF2CG9W/WlEr4c7i8A== X-Received: by 2002:a05:6a00:2e83:b0:5d9:bfc9:a4f with SMTP id fd3-20020a056a002e8300b005d9bfc90a4fmr3754231pfb.3.1677158900390; Thu, 23 Feb 2023 05:28:20 -0800 (PST) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id g18-20020aa78752000000b005a9bf65b591sm3848591pfo.135.2023.02.23.05.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 05:28:20 -0800 (PST) From: Qi Zheng To: akpm@linux-foundation.org, tkhai@ya.ru, hannes@cmpxchg.org, shakeelb@google.com, mhocko@kernel.org, roman.gushchin@linux.dev, muchun.song@linux.dev, david@redhat.com, shy828301@gmail.com Cc: sultan@kerneltoast.com, dave@stgolabs.net, penguin-kernel@I-love.SAKURA.ne.jp, paulmck@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH v2 5/7] mm: vmscan: hold write lock to reparent shrinker nr_deferred Date: Thu, 23 Feb 2023 21:27:23 +0800 Message-Id: <20230223132725.11685-6-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230223132725.11685-1-zhengqi.arch@bytedance.com> References: <20230223132725.11685-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 9AF9540010 X-Stat-Signature: 8ex3b7ygdp7ipit1dn6m6pcm6tannwxx X-HE-Tag: 1677158901-225673 X-HE-Meta: U2FsdGVkX1+6NJVpXRn/oSNU3nUot7Yj71CaFskqKmN/XKciWOTKHVQyPFy+pyR2WO5aaR9Qkzk2JxDaYv4PL/atOWBg68MNR4Tuu+/Lt1/usOCs9Q1i8WtdqqrgwLRpnGzUgX8/JNuOAfjxMYW43s2rjUjWFxdTcRi5yNuMnVXBGwaTR9ZnzB/MmwLo1LOPsaYF9OrCVNrJIF8fRsjK/bliJTmLviPy+Qf1t1EDXl8wBlA5v3eF8jSeM8Tu5du/7pW9ODj6AoyTLufGJ1cZZ7LYB7IL4fi4nw1U88HX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J5geVIp1Wetdg4e21bPnaNJXreGmJpjouVHDhcderyz/148BZm5yIvNXUi03COOEsnXDhQ6pFm4RBL0z4DkqqOeffeT973WWVsuXdCd4 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/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 25a4a660e45f..89602e97583a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -450,7 +450,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); @@ -459,7 +459,7 @@ void reparent_shrinker_deferred(struct mem_cgroup *memcg) atomic_long_add(nr, &parent_info->nr_deferred[i]); } } - up_read(&shrinker_rwsem); + up_write(&shrinker_rwsem); } static bool cgroup_reclaim(struct scan_control *sc)