From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 6DEF1C433DB for ; Fri, 29 Jan 2021 11:22:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 78B8D6505F for ; Fri, 29 Jan 2021 11:22:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 78B8D6505F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 99DC36B0005; Fri, 29 Jan 2021 06:22:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 927B26B0006; Fri, 29 Jan 2021 06:22:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EF6E6B006C; Fri, 29 Jan 2021 06:22:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0189.hostedemail.com [216.40.44.189]) by kanga.kvack.org (Postfix) with ESMTP id 650BB6B0005 for ; Fri, 29 Jan 2021 06:22:08 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 20115180AD811 for ; Fri, 29 Jan 2021 11:22:08 +0000 (UTC) X-FDA: 77758573536.08.berry64_2117a93275a7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 049001819E773 for ; Fri, 29 Jan 2021 11:22:07 +0000 (UTC) X-HE-Tag: berry64_2117a93275a7 X-Filterd-Recvd-Size: 3226 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 29 Jan 2021 11:22:07 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 24A79AC48; Fri, 29 Jan 2021 11:22:06 +0000 (UTC) Subject: Re: [v5 PATCH 04/11] mm: vmscan: remove memcg_shrinker_map_size To: Yang Shi Cc: Roman Gushchin , Kirill Tkhai , Shakeel Butt , Dave Chinner , Johannes Weiner , Michal Hocko , Andrew Morton , Linux MM , Linux FS-devel Mailing List , Linux Kernel Mailing List References: <20210127233345.339910-1-shy828301@gmail.com> <20210127233345.339910-5-shy828301@gmail.com> <255b9236-3e0b-f6f6-4a72-5e69351a979a@suse.cz> From: Vlastimil Babka Message-ID: Date: Fri, 29 Jan 2021 12:22:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 1/28/21 10:22 PM, Yang Shi wrote: >> > @@ -266,12 +265,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 = (new_nr_max / BITS_PER_LONG + 1) * sizeof(unsigned long); >> > + old_size = (shrinker_nr_max / BITS_PER_LONG + 1) * sizeof(unsigned long); >> >> What's wrong with using DIV_ROUND_UP() here? > > I don't think there is anything wrong with DIV_ROUND_UP. Should be > just different taste and result in shorter statement. IMHO it's not just taste. DIV_ROUND_UP() says what it does and you don't need to guess it from the math expression. Also your expression is shorter as it simply adds + 1, so if shrinker_nr_max is a multiple of BITS_PER_LONG, there's an extra unsigned long that shouldn't be needed. People reading that code will wonder whether there was some non-obvious intention behind that, and possibly send cleanup patches. >> >> > if (size <= old_size) >> > - return 0; >> > + goto out; >> >> Can this even happen? Seems to me it can't, so just remove this? > > Yes, it can. The maps use unsigned long value for bitmap, so any > shrinker ID < 31 would fall into the same unsigned long, so we may see > size <= old_size, but we need increase shrinker_nr_max since > expand_shrinker_maps() is called iff id >= shrinker_nr_max. Ah, good point.