From patchwork Tue Jan 5 22:58:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12000461 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0196C433E0 for ; Tue, 5 Jan 2021 22:58:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5B71D22E00 for ; Tue, 5 Jan 2021 22:58:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B71D22E00 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D57838D00BC; Tue, 5 Jan 2021 17:58:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB6478D006E; Tue, 5 Jan 2021 17:58:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA1E48D00BC; Tue, 5 Jan 2021 17:58:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id A0A838D006E for ; Tue, 5 Jan 2021 17:58:52 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6E5F78245571 for ; Tue, 5 Jan 2021 22:58:52 +0000 (UTC) X-FDA: 77673238104.17.bread06_4d08f8a274dc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 5610E180D0185 for ; Tue, 5 Jan 2021 22:58:52 +0000 (UTC) X-HE-Tag: bread06_4d08f8a274dc X-Filterd-Recvd-Size: 5563 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Tue, 5 Jan 2021 22:58:51 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id v3so535755plz.13 for ; Tue, 05 Jan 2021 14:58:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bGybKTjA83xTJvlWZhj7XA4Wdp0i+ARI2lQlbpxX72o=; b=WcWzs+V8qDAX9mVXmv3EA0qhcUeTJb8tzF5h/PgGmz/7fhFhkASM0MgxImZPsN7TCl ayyFUhw9DKlf0jB9LjqOE4VgsW3d7zH0i33HZT+qjY4/KX6MDGSGIBdrTze8RvbPO5mX +OLlz+mgARD35P5CzIlMgXAmAhGF0/fG6jQWTVDrzhSTQS+P3Vw1rr+Nk5R2eDmWgKhG VHHr/frUx53Sd+RvHB0oqMWMynhxVqUEIPRSbcq2rLhFuUFRy0UMihlwdFuogdtAYVGz kJnNkoMEMiRzxwPy7ijGjt353m0GTeIb23w5FsZlpg2mDqFWJQ/0yfy0jl6SJchwBWy2 9I1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bGybKTjA83xTJvlWZhj7XA4Wdp0i+ARI2lQlbpxX72o=; b=nuYDZpNYA71/rqagcypwv+ba1HnTXH6+je95P8ATcQ1P7s2DIRd5HVm7xcC6y3g6F9 c88KF0B3+0o/MzP2OBwYIzsMQ3RMu8wleoGXukfHqa1qzl5y2pCj6YEX27ZtVTi7zuMi YULFl28Qu8CcX3jYU4AZ64t9H7/ItP08mSSBkb6rviL9t3e+9zCt77JqejnMbvFeV4j7 1uCQ4ipGxRablACgd0A0FSKAWdTsn9rtpRh0Y60shWYaN7HASiOTk3TiMkPxk3N8b8DH WjBEax6CwnfkqrwV2m7xduWJiFKKMCjFVR8MmRqjn3dlxf0Bc7p4edPRyxSWG1Wnv9Bg yEeg== X-Gm-Message-State: AOAM530l8adVLWvgvUoOEKEEIHpWA5hms7ciizBxxN66a6jAWGfNvl+q UvtcvddLAc2ZS6Ha0H4v/1U= X-Google-Smtp-Source: ABdhPJzP2qgztI07SHedDB/qQDrkBM+TAdRyMKBnnsus28kMHVYBpk9b+kGQ5ZTyANOp1Uxn8YT1lg== X-Received: by 2002:a17:902:a983:b029:dc:2564:91f2 with SMTP id bh3-20020a170902a983b02900dc256491f2mr1671677plb.46.1609887531190; Tue, 05 Jan 2021 14:58:51 -0800 (PST) Received: from localhost.localdomain (c-73-93-239-127.hsd1.ca.comcast.net. [73.93.239.127]) by smtp.gmail.com with ESMTPSA id fw12sm244233pjb.43.2021.01.05.14.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jan 2021 14:58:49 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, shakeelb@google.com, david@fromorbit.com, hannes@cmpxchg.org, mhocko@suse.com, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v3 PATCH 03/11] mm: vmscan: use shrinker_rwsem to protect shrinker_maps allocation Date: Tue, 5 Jan 2021 14:58:09 -0800 Message-Id: <20210105225817.1036378-4-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210105225817.1036378-1-shy828301@gmail.com> References: <20210105225817.1036378-1-shy828301@gmail.com> MIME-Version: 1.0 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: Since memcg_shrinker_map_size just can be changd under holding shrinker_rwsem exclusively, the read side can be protected by holding read lock, so it sounds superfluous to have a dedicated mutex. This should not exacerbate the contention to shrinker_rwsem since just one read side critical section is added. Signed-off-by: Yang Shi --- mm/vmscan.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9db7b4d6d0ae..ddb9f972f856 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -187,7 +187,6 @@ static DECLARE_RWSEM(shrinker_rwsem); #ifdef CONFIG_MEMCG static int memcg_shrinker_map_size; -static DEFINE_MUTEX(memcg_shrinker_map_mutex); static void memcg_free_shrinker_map_rcu(struct rcu_head *head) { @@ -200,8 +199,6 @@ static int memcg_expand_one_shrinker_map(struct mem_cgroup *memcg, struct memcg_shrinker_map *new, *old; int nid; - lockdep_assert_held(&memcg_shrinker_map_mutex); - for_each_node(nid) { old = rcu_dereference_protected( mem_cgroup_nodeinfo(memcg, nid)->shrinker_map, true); @@ -250,7 +247,7 @@ int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) if (mem_cgroup_is_root(memcg)) return 0; - mutex_lock(&memcg_shrinker_map_mutex); + down_read(&shrinker_rwsem); size = memcg_shrinker_map_size; for_each_node(nid) { map = kvzalloc(sizeof(*map) + size, GFP_KERNEL); @@ -261,7 +258,7 @@ int memcg_alloc_shrinker_maps(struct mem_cgroup *memcg) } rcu_assign_pointer(memcg->nodeinfo[nid]->shrinker_map, map); } - mutex_unlock(&memcg_shrinker_map_mutex); + up_read(&shrinker_rwsem); return ret; } @@ -276,9 +273,8 @@ static int memcg_expand_shrinker_maps(int new_id) if (size <= old_size) return 0; - mutex_lock(&memcg_shrinker_map_mutex); if (!root_mem_cgroup) - goto unlock; + goto out; memcg = mem_cgroup_iter(NULL, NULL, NULL); do { @@ -287,13 +283,13 @@ static int memcg_expand_shrinker_maps(int new_id) ret = memcg_expand_one_shrinker_map(memcg, size, old_size); if (ret) { mem_cgroup_iter_break(NULL, memcg); - goto unlock; + goto out; } } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); -unlock: +out: if (!ret) memcg_shrinker_map_size = size; - mutex_unlock(&memcg_shrinker_map_mutex); + return ret; }