From patchwork Wed Mar 10 17:45:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12128817 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 33475C433E0 for ; Wed, 10 Mar 2021 17:46:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CCF1264F1D for ; Wed, 10 Mar 2021 17:46:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCF1264F1D 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 6CD918D01E4; Wed, 10 Mar 2021 12:46:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 658BA8D01D5; Wed, 10 Mar 2021 12:46:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F77A8D01E4; Wed, 10 Mar 2021 12:46:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id 35DFC8D01D5 for ; Wed, 10 Mar 2021 12:46:25 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E425E181AF5C2 for ; Wed, 10 Mar 2021 17:46:24 +0000 (UTC) X-FDA: 77904693888.29.4098911 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf21.hostedemail.com (Postfix) with ESMTP id 9A75FE005F1C for ; Wed, 10 Mar 2021 17:46:22 +0000 (UTC) Received: by mail-pf1-f173.google.com with SMTP id t85so7296398pfc.13 for ; Wed, 10 Mar 2021 09:46:24 -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=8qnm1r39F1+nLF2q+MJEWtJZ2OA03LbHXXfmJXBg/bU=; b=bQha59oGw/ATUzMVQxON9irQJ6V4Iq4VT34my0MPRxVqoD3pc3R7GOZ4Ihw9+D3w7J QbcWdPEOKc7kLp9evqhFteAsW6sH5UhtJNH9G8COXvScubfZr5yqOEPqb6FpdRZ1d7z7 IH68e2svWzJIzb+jG1kbN/SK5aHjP1dtN9op49wnjmKxIzjTUusOBvm5SD52yI2sOXN4 LCEZYzkLc1103vE/bmiPc59xEU2imubQ8rKnH7rx2ssNjYyNBPTQy2XSHdGOLD/e/qQV UbBghQvT4rK1Hea+MZEy2+QfEqswO7+A4Vj4uIq2h9AMIUk5AzoqbOzCpuTf62uCGU/D A9lw== 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=8qnm1r39F1+nLF2q+MJEWtJZ2OA03LbHXXfmJXBg/bU=; b=HxRunU0o33IpIxxK4+kSJVWcf8zwzB1H75/1tbOmnpjhacu1TxTheqEKlUKq3TVHVO g4PzKo9ixl3Zi2uRI884SKw/nL+E2XBTzea9gWryX9lH+Rq9hVDNwn4S0QNj+4F0VvRG NZ0Hy6LR/JcbgV58Xw7P1IBbHLqSXTLbpouQfeyRyMhjvssp3+hF9OVeXb5mUb+ZLLTq fM8FMyc0BZQYs85S90FYh1MV7FZdJedPSYspSx4b21k58dGTSY4CFM5FzTivs9w0EIAn CDPSDtDPZidflB5zr6UCbjY/+xWGY/xu3soOU5uQ7wN1NKv5E8Y8FbarGlmRtHSbHdrb D8Tw== X-Gm-Message-State: AOAM532wFOGGCDzoosj6eSOwd5BwOzUadAVLkll1C6na1pZdYGPQrWic SVzOBWsfriEUBDNV0yD1tfA= X-Google-Smtp-Source: ABdhPJzBn8tAF3hvcNEKpLzZbv6EQt380V9sSRJOIaoGi/hfNxA10rSwz5p+lofpE1kxGrEMUTQNhg== X-Received: by 2002:a65:6642:: with SMTP id z2mr3695109pgv.214.1615398383207; Wed, 10 Mar 2021 09:46:23 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 09:46:22 -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 04/13] mm: vmscan: remove memcg_shrinker_map_size Date: Wed, 10 Mar 2021 09:45:54 -0800 Message-Id: <20210310174603.5093-5-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: 5aebkth3znwq5nyg88kogu6qbafbciqc X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9A75FE005F1C Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf21; identity=mailfrom; envelope-from=""; helo=mail-pf1-f173.google.com; client-ip=209.85.210.173 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615398382-135163 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 Reviewed-by: Shakeel Butt Signed-off-by: Yang Shi --- mm/vmscan.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 75fd8038a6c8..bda67e1ac84b 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;