From patchwork Wed Mar 10 17:45:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12128867 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,URIBL_BLOCKED, 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 9075CC433DB for ; Wed, 10 Mar 2021 17:47:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D11E64EDD for ; Wed, 10 Mar 2021 17:47:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D11E64EDD 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 D348F8D01EF; Wed, 10 Mar 2021 12:47:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B1B8D01ED; Wed, 10 Mar 2021 12:47:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAC7F8D01EF; Wed, 10 Mar 2021 12:47:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 9A3008D01ED for ; Wed, 10 Mar 2021 12:47:30 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 5EFA4181AF5C2 for ; Wed, 10 Mar 2021 17:47:30 +0000 (UTC) X-FDA: 77904696660.21.614C62E Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf01.hostedemail.com (Postfix) with ESMTP id 52E342000380 for ; Wed, 10 Mar 2021 17:46:30 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id w34so10807893pga.8 for ; Wed, 10 Mar 2021 09:46:29 -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=Py/EOd4SfsVAE1wGGKDRwg9/efRB8yrzYfbXqq9sd00=; b=Xpwz5NuPcHO0UONgccK0lxYzdukCMeF0Re0h4f0uNRyBewcR9stOMZVAtRxz61w3Z5 BATO2TMLuqZ8FLGXpMgv9hV89IVkjrs5pMV2bbdKKA4sMJGez7zOY8rg+Usr+I0NDL7a WNfeuaIsyxwsfVOlfaEWD+fI+QZql3ZG6F4QZ6miI/TXrDnK2bFokzxTdh9jXJ0apslx w6WFNjigZFUzJS8ruS63XTqLSeg2C+6pPQUo7MRNxYa9YCLuyRUHGq7oa/5w3/jqnldZ LOr7MlAofEyyLVfsWbZHhlhY2cx6mT2acQeHanKOn215EMFA2SbUfZMjWJv5ZdJUIY9w ChhQ== 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=Py/EOd4SfsVAE1wGGKDRwg9/efRB8yrzYfbXqq9sd00=; b=esEVcVXbOSRVqzi+ZkjweSbSsNCabn+Wp00ER8r4kU5QXSld3C2wn+G4L6tffa8L+0 yVx68Zgb5ty1gz5/UU21+M3IHLAErvpfacRpissaq2+r8esqep+cvBfCeRLlAGckf0gp tnomvXyw3e0GIohhzIV5turYFAmBwXUn05g3cPjIDSRlkpJezESol60U+/aeYkXgJE42 gqEhSs5xydjIZPwYlmIc+vZkY/HdL6pa1QzDi41dCk448iAq+6nE1MfY4eVVDbC0u8QN 6oYmoTdFO5Cu4BmayeNvmQYww9C5zUPM/Y/43HHw91U/B6It0j1LpMOBSYRfagJanUmz jsuQ== X-Gm-Message-State: AOAM532ynh+WlpUo402DehyY9dwGV52HxBIQhMHGrlwQw5uVJRiLh1V+ mw/K1kAWKbZYgCCbI8+mKow= X-Google-Smtp-Source: ABdhPJy2ZsOHvx2Hmu5HfY7PtlhmBiqC9ADbXQxKs8wOp8se+DZgPiNAvxMx83CNwYNWVOw6WhzXtA== X-Received: by 2002:aa7:83cf:0:b029:1ee:f550:7d48 with SMTP id j15-20020aa783cf0000b02901eef5507d48mr4054966pfn.12.1615398389031; Wed, 10 Mar 2021 09:46:29 -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 d6sm145804pfq.109.2021.03.10.09.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 09:46:28 -0800 (PST) From: Yang Shi To: guro@fb.com, ktkhai@virtuozzo.com, vbabka@suse.cz, 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: [v9 PATCH 07/13] mm: vmscan: add shrinker_info_protected() helper Date: Wed, 10 Mar 2021 09:45:57 -0800 Message-Id: <20210310174603.5093-8-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310174603.5093-1-shy828301@gmail.com> References: <20210310174603.5093-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: tugpsumr6djud97qs6p5nzp1i7c8ri79 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 52E342000380 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf01; identity=mailfrom; envelope-from=""; helo=mail-pg1-f178.google.com; client-ip=209.85.215.178 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615398390-327856 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: The shrinker_info is dereferenced in a couple of places via rcu_dereference_protected with different calling conventions, for example, using mem_cgroup_nodeinfo helper or dereferencing memcg->nodeinfo[nid]->shrinker_info. And the later patch will add more dereference places. So extract the dereference into a helper to make the code more readable. No functional change. Acked-by: Roman Gushchin Acked-by: Kirill Tkhai Acked-by: Vlastimil Babka Reviewed-by: Shakeel Butt Signed-off-by: Yang Shi --- mm/vmscan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 7f3c00e76fd1..c0d04f242917 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -192,6 +192,13 @@ static inline int shrinker_map_size(int nr_items) return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); } +static struct shrinker_info *shrinker_info_protected(struct mem_cgroup *memcg, + int nid) +{ + return rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, + lockdep_is_held(&shrinker_rwsem)); +} + static int expand_one_shrinker_info(struct mem_cgroup *memcg, int size, int old_size) { @@ -199,8 +206,7 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, int nid; for_each_node(nid) { - old = rcu_dereference_protected( - mem_cgroup_nodeinfo(memcg, nid)->shrinker_info, true); + old = shrinker_info_protected(memcg, nid); /* Not yet online memcg */ if (!old) return 0; @@ -231,7 +237,7 @@ void free_shrinker_info(struct mem_cgroup *memcg) for_each_node(nid) { pn = mem_cgroup_nodeinfo(memcg, nid); - info = rcu_dereference_protected(pn->shrinker_info, true); + info = shrinker_info_protected(memcg, nid); kvfree(info); rcu_assign_pointer(pn->shrinker_info, NULL); } @@ -674,8 +680,7 @@ static unsigned long shrink_slab_memcg(gfp_t gfp_mask, int nid, if (!down_read_trylock(&shrinker_rwsem)) return 0; - info = rcu_dereference_protected(memcg->nodeinfo[nid]->shrinker_info, - true); + info = shrinker_info_protected(memcg, nid); if (unlikely(!info)) goto unlock;