From patchwork Thu Mar 11 19:08:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12132527 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 87C5DC433E0 for ; Thu, 11 Mar 2021 19:09:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06B9364E60 for ; Thu, 11 Mar 2021 19:09:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06B9364E60 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 5DC968D02EA; Thu, 11 Mar 2021 14:09:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 58D638D02B2; Thu, 11 Mar 2021 14:09:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 391E68D02EA; Thu, 11 Mar 2021 14:09:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 13EA98D02B2 for ; Thu, 11 Mar 2021 14:09:16 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id C42B55DF8 for ; Thu, 11 Mar 2021 19:09:15 +0000 (UTC) X-FDA: 77908531470.05.DC310B6 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf24.hostedemail.com (Postfix) with ESMTP id 2E84EA0009FD for ; Thu, 11 Mar 2021 19:09:11 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id q12so225541plr.1 for ; Thu, 11 Mar 2021 11:09:15 -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=m2bLEDF9fLJ0ubUMCl5gxJ4ENWjURCD7GlteN0I+Pn0=; b=Mi6pTvW8VJpVzzmhCHBU6uqews5NbK1wW8i7GWTUtcQJm40tQfsU3q/4i1dMSxHChA fk6MOedbmi4Dz8b7j7f1wh094bz8Tx5NrY7UsuzP2ASxI72pn0IuoBBVuMk43qFKPe8C 1cZA14u5QtwgFBzSURdke1P3WrCzExGbRVN1esGKANq6X5K9sbVyb3V7XoqeNexexucz FPYL/JPcPEexxog48emnyY+vMOIt9v1CyZKrbKjjc4BFkKUTaiNbT3hhy29DxT0AdsAK Rzk+DWX1+6urZv54JXCIQfJ7IxTYAkD9RnK4LQFq1LcW0b8nwp6SP+d25idwc3fprVC+ Iv3w== 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=m2bLEDF9fLJ0ubUMCl5gxJ4ENWjURCD7GlteN0I+Pn0=; b=djRazStONl0XHkCswZIsV94/DA9iNhdHSeHj08IrA5RwDboJ0rceSKOotLGsdHRu66 /xX7Mz/bnXik1AZn2yxwljC4L0ZZytguGzja4PQTzjVCi2/AgFTs8aDMGG+mVDXSQKvi FFhiZ5uAIW8gUDavCBa64IvXJ7vvPQylJgGG5P0jqC0V/slGmwPGzNwxfa11WeD5cw50 PuCakYKxTTyPkt251t2eB1NpRnDRyHlRyQ7qdltL4qwjT8Ic5sNEyh4nKimhV2BigZp0 F+8MpGLg+3h75ThS0xVujrCJxQ/nu9scHbKMLlttioaxcSNPEZE/2e/mrV2jBhnaRM+B YYkw== X-Gm-Message-State: AOAM530TPL3JzUrbmViXBpge8WWffK90di76/X/5Tpoyh5g7sYP+ESk4 uO4Ll7vWo1aUrQQDLkgNRgvwxefcVXDmFg== X-Google-Smtp-Source: ABdhPJy6nmhaP70hLjuP7UUkSI2vRg+R6cLVH31ME6nZFnyfjO/2L99AjBImPmBY4M11zbaB7ha1TA== X-Received: by 2002:a17:90a:fd0b:: with SMTP id cv11mr10319170pjb.183.1615489754458; Thu, 11 Mar 2021 11:09:14 -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 t12sm2999111pfe.203.2021.03.11.11.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Mar 2021 11:09:13 -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: [v10 PATCH 07/13] mm: vmscan: add shrinker_info_protected() helper Date: Thu, 11 Mar 2021 11:08:39 -0800 Message-Id: <20210311190845.9708-8-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210311190845.9708-1-shy828301@gmail.com> References: <20210311190845.9708-1-shy828301@gmail.com> MIME-Version: 1.0 X-Stat-Signature: unaywezdodzm8m9rb967drynw14ui9rw X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2E84EA0009FD Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=mail-pl1-f170.google.com; client-ip=209.85.214.170 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615489751-821130 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 7fdfdacf9a1f..ef9f1531a6ee 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) { @@ -201,7 +208,7 @@ static int expand_one_shrinker_info(struct mem_cgroup *memcg, for_each_node(nid) { pn = memcg->nodeinfo[nid]; - old = rcu_dereference_protected(pn->shrinker_info, true); + old = shrinker_info_protected(memcg, nid); /* Not yet online memcg */ if (!old) return 0; @@ -232,7 +239,7 @@ void free_shrinker_info(struct mem_cgroup *memcg) for_each_node(nid) { pn = memcg->nodeinfo[nid]; - info = rcu_dereference_protected(pn->shrinker_info, true); + info = shrinker_info_protected(memcg, nid); kvfree(info); rcu_assign_pointer(pn->shrinker_info, NULL); } @@ -675,8 +682,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;