Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1951359pxb; Fri, 29 Jan 2021 09:09:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHeioO4HkAqZKddmOxyHPgb0zSSXt/0ILtlPaLzRpigikSmjT1GTEy0MtNJ117XTVvN+3b X-Received: by 2002:aa7:d6cf:: with SMTP id x15mr6286480edr.336.1611940162682; Fri, 29 Jan 2021 09:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611940162; cv=none; d=google.com; s=arc-20160816; b=jXjg1Y3rBjdPj/v4QEIJAe6agHyZ9Hvo8dzaiA1uTFTb7xtHUYmXipzQjDFlR23wpA ayYhIh9Cz3NLXQpA88ygJti43JTgrrNl4x8oS7uTh8zKsYz2lWXJyBDyD+NSTdZbMvJm zLNhmtNW7U1tl1PKDDHuCsSozL5f4K1tVHmkidTMnhBvgteT8p3iAA2F7uDplzzEQnFr N3AQRQFE2/EhgZDQMCZKQ8eOXrdqtkOxf4Jw+8OzGawizJw4GeVqXRxGiiDDmx60/hcE D1/IRgzOylnE1TUFoOZYtWL4eOM3KVi326jR7z8/8SIO1RSc6wzkqudJDTyX3roBAX0p dSzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=sjU1ft3CFBesr8MYGZFVFpiy1HInqyD6mtninlntO/8=; b=ccRcVFbiLxqNjCI4Bd2acUpJpdArcB2Xpof0g5EsD0POR44IDL8+xL/44cnWglanyC L5fLbHTlsBFf9QGmdo/0ov77yP5qV/scresX4t9u2lsZaSF/YyrqFaMvkqg7jYayhXTd HlfRQcpbwCrpDtdazZLMuQgkcqgMX3lj8UCcWTbapb5JLLBsXkeeoTeA9Dj5QQBtvvwn Tybx/yHtE+2ZctpdKlL59ApJT27tQOaDlvY0Rnxx6y/ZwESBAKsf2fG4lfJs+j0nyT6H 5SPZzM1sz5SR3lXIomnd4R4yWmKuUbKD6BY4ArEF6IKgmGrPKCE3zz2JUA2reO/57gXe wDbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UNyGZ0gK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p8si5499248edm.503.2021.01.29.09.08.58; Fri, 29 Jan 2021 09:09:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UNyGZ0gK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231533AbhA2RG0 (ORCPT + 99 others); Fri, 29 Jan 2021 12:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbhA2RGX (ORCPT ); Fri, 29 Jan 2021 12:06:23 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBA1EC061573; Fri, 29 Jan 2021 09:05:42 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id ox12so14106703ejb.2; Fri, 29 Jan 2021 09:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sjU1ft3CFBesr8MYGZFVFpiy1HInqyD6mtninlntO/8=; b=UNyGZ0gKDZ5PJ0jlRi0rzX54uMKknI6+9o8e1gk8IhssVjwg+I8vBFqp9cJlxpLsQ7 Fn4t/zjEBE2eSb2hQStKvrS0377E8mqSxoYj6V8h/K474cqAQewOC7pb3SEVdgKcWDqa EAtyqtPJibedl0AeVa0vxdrYvQLClvm5ShiEThAywr7jQ25eQ2Q7Y+9Jhevd4nXQuLQo zKqk4vT1VOEIoXuQaGWcFj1UNdSFbKfB8lt83r6qj1QvYO1pKyYNJu8c1p+/UAnNWB4S 8a5djwz21voP7TEEZQt3wyEnD1ov2t/l0PlhobdWmuo2NzPok+WX3Mjyso5HeyF0cR3I N3Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=sjU1ft3CFBesr8MYGZFVFpiy1HInqyD6mtninlntO/8=; b=T3Z7d6EC/lYCUUT3f8Cenau1GQOVG/G/pQJvqKfbIBTbAeEzGPCWUBj5zT1UAjLKWk TYfcyCwQMFFr5LOeZcwrDCcPGwFuBjLNQ+w08JCpt7qBVuA90Pe/yiBTxlBtEXZbw/5V LXXzJ+pWlIdVHW+LgpSsSMpS0NZUEw64wUnOtBoaOmHFBK/QLWzLrda68HgGyxtd6sdu m83QFmNRBrYK3yH+v6H12tYLCnr4M5aA+c9rdWlRj2LV0cWF/B9Kzdx4VmMcPUpF9uoQ 2YPcwojAWbeIBAD9INTxc2Hfe1rlbUWX4HsTpE5KJGJE+gkFjw+aQiRdpR7i5aqwKtGq o+OQ== X-Gm-Message-State: AOAM530H12BSBy/FeD8RsoxOp1oYHcjft4ZDObx0eU42EjD1s4DImifA y9ycGEq7PhPJiJq4BoZHk1EHHLAYagjMGFGYWM0= X-Received: by 2002:a17:906:94d3:: with SMTP id d19mr5429345ejy.383.1611939941556; Fri, 29 Jan 2021 09:05:41 -0800 (PST) MIME-Version: 1.0 References: <20210127233345.339910-1-shy828301@gmail.com> <20210127233345.339910-5-shy828301@gmail.com> <255b9236-3e0b-f6f6-4a72-5e69351a979a@suse.cz> In-Reply-To: From: Yang Shi Date: Fri, 29 Jan 2021 09:05:30 -0800 Message-ID: Subject: Re: [v5 PATCH 04/11] mm: vmscan: remove memcg_shrinker_map_size To: Vlastimil Babka 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 29, 2021 at 3:22 AM Vlastimil Babka wrote: > > 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. OK, will replace back to DIV_ROUND_UP(). And, a helper macro is introduced in patch #6, will add that helper in this patch and use DIV_ROUND_UP() in the helper. > > >> > >> > 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.