From patchwork Tue Feb 9 17:46:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12078699 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 AF8DDC433E0 for ; Tue, 9 Feb 2021 17:55:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2E8A064EC0 for ; Tue, 9 Feb 2021 17:55:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E8A064EC0 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 ADFBC6B006C; Tue, 9 Feb 2021 12:55:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB6496B0071; Tue, 9 Feb 2021 12:55:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CC6D6B0072; Tue, 9 Feb 2021 12:55:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 876146B006C for ; Tue, 9 Feb 2021 12:55:04 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 53C9A18484A07 for ; Tue, 9 Feb 2021 17:55:04 +0000 (UTC) X-FDA: 77799480528.05.step50_2014d7a27609 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 399FC1803F9CD for ; Tue, 9 Feb 2021 17:55:04 +0000 (UTC) X-HE-Tag: step50_2014d7a27609 X-Filterd-Recvd-Size: 5300 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 17:55:03 +0000 (UTC) Received: by mail-pj1-f45.google.com with SMTP id t2so2118102pjq.2 for ; Tue, 09 Feb 2021 09:55:03 -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=LtIT/XRubfZjNifW2/Wx2dvhH4DsCPssoQQ3vaxaswY=; b=f3P7M8G1BnqPYIthcB/2g5SI/aoPY7wzYvH+tH6KFpKU5R0eDTwdhWH4K18kqBhQBm XbCd824CFY/j+gg3m2xEUdnUS5o6nQz6BWqdkgk3U9hKkri6rEZgztlxI2/o1pFw4QEV F1dkb13u/1T1/e3Zn4VRnoVyrGu40vkPWClywRVJWbo1dmwoh3pb5CjJLQ7tBGD9OaXG fcm+jIdzMevEaJ1fiTUGdiyu1euBYSgbAo9WOlqfqiDfrXkiJY1EH/7sLk04XoZcyVek LAUq4qdKGqd53x2AQKGySFtwoAsFh/Kuoy89afStR91jCBE5MGcOcO96HLpOVVsJUr+e NBeA== 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=LtIT/XRubfZjNifW2/Wx2dvhH4DsCPssoQQ3vaxaswY=; b=Zyxkne0yoMVhewAmrJNl+R52iWN0fwdnGjoV4e6jV6vd1hVoZWp6E5Y2KSxm6HoUGw DyLzFw55xLPV7P21pxRykLU69e2wpc5kzPZGqSWrpT56Eq1PfMVrd/tBwMtp9Se4Gu91 BIPnpyOAuVB2Akt/C0TN/yIHkEXce8Xg6R3aYl0zveuS+YUvyr2WvqNynlxKCaAWzv4w R8SLzkTrxIQZd71yCwfRjWJDzl+5VfXzJOHGoA4lcnEAQumv+QdSaotZMCsU7qQJz6AA rxKqYvihdWbjJDszRguL4sdZKYwTJvpAnYSI23pFg+rOYdLpuYY52fHfTsTorAc4mMM8 QmUA== X-Gm-Message-State: AOAM532HTrevtx2969o3iKpGJRGfwENAppx/rwH2LEQZwvNt+woPSFeT snuq7b45bl8pX7lQAKi6b08UTXN9lTcilw== X-Google-Smtp-Source: ABdhPJwn2hQAiH23fVtXQpzqorHAVfhxl9TB10b0gI+9q594PYZIw32xabvZJWQNOW1EMGNWJo+64A== X-Received: by 2002:a17:902:c404:b029:e2:cb8e:6b78 with SMTP id k4-20020a170902c404b02900e2cb8e6b78mr13868552plk.3.1612892837299; Tue, 09 Feb 2021 09:47:17 -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 j1sm22260929pfr.78.2021.02.09.09.47.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 09:47:16 -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: [v7 PATCH 06/12] mm: vmscan: add shrinker_info_protected() helper Date: Tue, 9 Feb 2021 09:46:40 -0800 Message-Id: <20210209174646.1310591-7-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210209174646.1310591-1-shy828301@gmail.com> References: <20210209174646.1310591-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: 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. Signed-off-by: Yang Shi Acked-by: Roman Gushchin Acked-by: Kirill Tkhai Acked-by: Vlastimil Babka Reported-by: kernel test robot --- mm/vmscan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9436f9246d32..273efbf4d53c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -190,6 +190,13 @@ static int shrinker_nr_max; #define NR_MAX_TO_SHR_MAP_SIZE(nr_max) \ (DIV_ROUND_UP(nr_max, 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 void free_shrinker_info_rcu(struct rcu_head *head) { kvfree(container_of(head, struct shrinker_info, rcu)); @@ -202,8 +209,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; @@ -234,7 +240,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;