From patchwork Wed Feb 17 00:13:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12090781 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 91840C433DB for ; Wed, 17 Feb 2021 00:13:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2837964DFF for ; Wed, 17 Feb 2021 00:13:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2837964DFF 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 AE83E8D000F; Tue, 16 Feb 2021 19:13:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A6FFA8D000D; Tue, 16 Feb 2021 19:13:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9149D8D000F; Tue, 16 Feb 2021 19:13:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0034.hostedemail.com [216.40.44.34]) by kanga.kvack.org (Postfix) with ESMTP id 71C758D000D for ; Tue, 16 Feb 2021 19:13:46 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3F44F180AD820 for ; Wed, 17 Feb 2021 00:13:46 +0000 (UTC) X-FDA: 77825836452.06.pain21_440244e27648 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 1EBCE1005D00A for ; Wed, 17 Feb 2021 00:13:46 +0000 (UTC) X-HE-Tag: pain21_440244e27648 X-Filterd-Recvd-Size: 5345 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Feb 2021 00:13:45 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id n10so7323773pgl.10 for ; Tue, 16 Feb 2021 16:13:45 -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=HSn3NqB9VD7rWht7Szy8nfdBgp8H6px/y36iWOtZRrk=; b=ogEtLEdngbkvDqPH+9k1j7lFEVEQ8Pd5ZYB0zf2c1AslkcEufULjGU+i0U3pl1UYk5 f5/W8fn/VgbPSXrYB+U0zZqI7wvw86WUOM2p19OmoYw+vgFqPHM2qKOUPJEAcb8sUB22 kOoR1jsGwnef7/cE1UjbwbmpYWZxsN+UkULCCzH5TJODl+B/r+ckbYkYXit2GDJGzHbG qtT9ePpxLmGZl2AOhwlO7uq0KPS3ucBzM7w/wpl1nUhVZ7onoGk/fIc75IYZWtOMBpAZ d0/5bkkS60b2K7Iwd8Eiso8NX9jLDCbHZ+XAwisXEb77hIatNJMA3UWwh7iPHdPdbhsz Yslw== 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=HSn3NqB9VD7rWht7Szy8nfdBgp8H6px/y36iWOtZRrk=; b=GSupmH2nuPoKTlnpLSGt4mq1xMoNZbaTmi/1ab7oYbdtr+DPTIV56sY3f6EWwWN1Lc IXwdns5TcXnO6p59zNA7X+oK1vxHns6lT5LYScn7ezsi9EZicoowVAue/+0UA0iEG+K3 LM5Bqxc0kUeEAHsmLzdn8mcSVwPSdoQ31hYBqu2Yh4MYrM631Qan04GyK+hRaEddkV/+ lr5bTI9Io60VCHY1oKVJ619fowtho09iXnGdLQ1aHSIsGN3xGzBqJ1Z44vgjMyz5EPU/ e7pZ8Ifb6hkp21HyixQuQ9EpF3Y9y+N6OBPwYJWKPBYMM+MD0LIqni0WDZQ+lpgi40Iz DtGQ== X-Gm-Message-State: AOAM530HbctSX8hOHrJOGtSro/dmp1SKc2YqVWepfvMzysV6f/bEIB1F JHyhNwTJfyeGlOSOvpn4EZA= X-Google-Smtp-Source: ABdhPJwZEecYz6LkZS+2+ihMK2GWDVgJ6bjhlNP1SYaJC1fdnuVWtBc+oQ3w2THvYZWNwjTWlxlzXQ== X-Received: by 2002:a63:cf06:: with SMTP id j6mr21192416pgg.195.1613520824890; Tue, 16 Feb 2021 16:13:44 -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 y12sm99220pjc.56.2021.02.16.16.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 16:13:44 -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: [v8 PATCH 07/13] mm: vmscan: add shrinker_info_protected() helper Date: Tue, 16 Feb 2021 16:13:16 -0800 Message-Id: <20210217001322.2226796-8-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210217001322.2226796-1-shy828301@gmail.com> References: <20210217001322.2226796-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. Acked-by: Roman Gushchin Acked-by: Kirill Tkhai Acked-by: Vlastimil Babka Signed-off-by: Yang Shi Reviewed-by: Shakeel Butt --- mm/vmscan.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index c94861a3ea3e..fe6e25f46b55 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); } @@ -673,8 +679,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;