From patchwork Wed Feb 17 00:13:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12090775 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 2D6F8C433E0 for ; Wed, 17 Feb 2021 00:13:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CB2E664DFF for ; Wed, 17 Feb 2021 00:13:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CB2E664DFF 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 654F28D000C; Tue, 16 Feb 2021 19:13:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 604286B007E; Tue, 16 Feb 2021 19:13:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A6F98D000C; Tue, 16 Feb 2021 19:13:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0126.hostedemail.com [216.40.44.126]) by kanga.kvack.org (Postfix) with ESMTP id 2C7336B007D for ; Tue, 16 Feb 2021 19:13:40 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E46BC6D93 for ; Wed, 17 Feb 2021 00:13:39 +0000 (UTC) X-FDA: 77825836158.18.trick57_3e02c2527648 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id B626F100EC663 for ; Wed, 17 Feb 2021 00:13:39 +0000 (UTC) X-HE-Tag: trick57_3e02c2527648 X-Filterd-Recvd-Size: 5794 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Wed, 17 Feb 2021 00:13:38 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id z15so7252675pfc.3 for ; Tue, 16 Feb 2021 16:13:38 -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=nrWTpq2dO7Eg3GTZ90HCf5mhya6dwUv+AMyfdHDY2DA=; b=o0z2F6Qc4S3+vXblyH0mYP/ax8EyOS1mKW7gexinUfzv49fXukNW7QCAIA0ZJO7iTC UFtZo0CfeeWgJA5Kisa28tJcIIP5jkq8NG4R/Xz3dumFOL3PVv10yxHovzM54BYnrwjb 339Ev1AqMok156YI1cCj2582/Nj7Z9RRljbb5+8CVJANnOMYZo3wRD5zxdyYj9e2KysG lunfq90/Zcfbk7OApA2LeuHcdVbYVKvNa+/u2dzBG7OABLCGxhRzaY5Hnk0nnj+aEyWr c6R5Ns4obmv87viI7yUaHvMjcG5TnoKJ7Iq+zOnCtLkd1tTR+2TfCpOBysbFZyVMPiHY V9Ag== 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=nrWTpq2dO7Eg3GTZ90HCf5mhya6dwUv+AMyfdHDY2DA=; b=JFxKabhIm9P4iq9MXmwVkn8OCz9GsvE/8pvvX94FSbO4/yNSag2dfL2xuVBzzGloae KxmXLLZtJVKKUm9CceuFqjQnqSbGyILsX945ZOyKbz+9ayE0B1Wwt58hTjnt82coCDZp gwc10weS+myuOruBWLC26qDcclPCNOQmppDwn2tueLyVLr4AOeDTuOR4Hm8J6UkojWwN 9geqn3pl/uuOml3flQbUkMOJkQ/OOQoh1GwJiaQMOkOHZw4ZCYbqBpXer2EQUOnO66k2 Ffr9rblxI5ETnxNRJGcQ41Me8nIIQQrZaat1Bw2ALkkn9h278izy89EqiOnEU1VXw/1W UhEA== X-Gm-Message-State: AOAM532Rj7oDgoTqdnNATSywTtuCklpLGG2dDPFEb080/JGJCy1Lk8yV W7ErXdZzUBDuWrNPH4mLhBDbC7m8Tcx+yw== X-Google-Smtp-Source: ABdhPJy3A83kV+erXZ8lkFiabZggHE6dNpCc6tIrExHC220czNBuC5EzLT1Qs5H6KpkeBQPb4+gfOA== X-Received: by 2002:aa7:8811:0:b029:1eb:77b1:6e77 with SMTP id c17-20020aa788110000b02901eb77b16e77mr15629198pfo.22.1613520817524; Tue, 16 Feb 2021 16:13:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 16:13:36 -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 04/13] mm: vmscan: remove memcg_shrinker_map_size Date: Tue, 16 Feb 2021 16:13:13 -0800 Message-Id: <20210217001322.2226796-5-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: Both memcg_shrinker_map_size and shrinker_nr_max is maintained, but actually the map size can be calculated via shrinker_nr_max, so it seems unnecessary to keep both. Remove memcg_shrinker_map_size since shrinker_nr_max is also used by iterating the bit map. Acked-by: Kirill Tkhai Acked-by: Roman Gushchin Acked-by: Vlastimil Babka Signed-off-by: Yang Shi Reviewed-by: Shakeel Butt --- mm/vmscan.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 543af6ec1e02..2e753c2516fa 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -185,8 +185,12 @@ static LIST_HEAD(shrinker_list); static DECLARE_RWSEM(shrinker_rwsem); #ifdef CONFIG_MEMCG +static int shrinker_nr_max; -static int memcg_shrinker_map_size; +static inline int shrinker_map_size(int nr_items) +{ + return (DIV_ROUND_UP(nr_items, BITS_PER_LONG) * sizeof(unsigned long)); +} static void free_shrinker_map_rcu(struct rcu_head *head) { @@ -247,7 +251,7 @@ int alloc_shrinker_maps(struct mem_cgroup *memcg) return 0; down_write(&shrinker_rwsem); - size = memcg_shrinker_map_size; + size = shrinker_map_size(shrinker_nr_max); for_each_node(nid) { map = kvzalloc_node(sizeof(*map) + size, GFP_KERNEL, nid); if (!map) { @@ -265,12 +269,13 @@ int alloc_shrinker_maps(struct mem_cgroup *memcg) static int expand_shrinker_maps(int new_id) { int size, old_size, ret = 0; + int new_nr_max = new_id + 1; struct mem_cgroup *memcg; - size = DIV_ROUND_UP(new_id + 1, BITS_PER_LONG) * sizeof(unsigned long); - old_size = memcg_shrinker_map_size; + size = shrinker_map_size(new_nr_max); + old_size = shrinker_map_size(shrinker_nr_max); if (size <= old_size) - return 0; + goto out; if (!root_mem_cgroup) goto out; @@ -289,7 +294,7 @@ static int expand_shrinker_maps(int new_id) } while ((memcg = mem_cgroup_iter(NULL, memcg, NULL)) != NULL); out: if (!ret) - memcg_shrinker_map_size = size; + shrinker_nr_max = new_nr_max; return ret; } @@ -322,7 +327,6 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) #define SHRINKER_REGISTERING ((struct shrinker *)~0UL) static DEFINE_IDR(shrinker_idr); -static int shrinker_nr_max; static int prealloc_memcg_shrinker(struct shrinker *shrinker) { @@ -339,8 +343,6 @@ static int prealloc_memcg_shrinker(struct shrinker *shrinker) idr_remove(&shrinker_idr, id); goto unlock; } - - shrinker_nr_max = id + 1; } shrinker->id = id; ret = 0;