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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 CB1ECC4338F for ; Thu, 19 Aug 2021 15:06:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6DA6C60F11 for ; Thu, 19 Aug 2021 15:06:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6DA6C60F11 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id B75858D0001; Thu, 19 Aug 2021 11:06:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFE766B0072; Thu, 19 Aug 2021 11:06:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99F0D8D0001; Thu, 19 Aug 2021 11:06:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0101.hostedemail.com [216.40.44.101]) by kanga.kvack.org (Postfix) with ESMTP id 7BB6D6B0071 for ; Thu, 19 Aug 2021 11:06:25 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2547A814BDA7 for ; Thu, 19 Aug 2021 15:06:25 +0000 (UTC) X-FDA: 78492156330.32.0E6CB88 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf13.hostedemail.com (Postfix) with ESMTP id C84E3100F6C0 for ; Thu, 19 Aug 2021 15:06:24 +0000 (UTC) Received: by mail-pf1-f172.google.com with SMTP id k19so5784100pfc.11 for ; Thu, 19 Aug 2021 08:06:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WRP4QaaG2BZAUZjQyqy0D7D6eqKZn/t5ewBUMuvwDnQ=; b=fgjovzasfByAdj7b+nK1+ixIaKp2smVLzl8dj2Pd73vlgPoH5aC3SJZb44ssasEbKm T+U4/Ze8J/PxLezM2pOvFXr0kf5+dnfk/xGHyem3ktq3VOUoYAFq/bheXQGOx4ajjdeu +zna3g8/D4Uw4rUgWqdPpPV4xUHeUw/8gg/VuNLsQ7RrT1QKpOOYJeZLXdjP2wsKcj5b qLCF++TY75HV8241PSHgtEdyrTpRskXsHSY/Ff7cpzTXqZgDvVkB1Mh6b3Tgm3vjFuLM yfgIZw+RFqjlZUZvmP8fQ95bCYG2OuqNCNDmr7Zf1mNua+F0dGjMbtqj56YAmP7QXIGw knQA== 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=WRP4QaaG2BZAUZjQyqy0D7D6eqKZn/t5ewBUMuvwDnQ=; b=ZZKq+w/YVojI4bD/+YhHNTkO0uJknffVQ1Sz1tDF/jA8gngQelhAT6c3dWVombV8RG W/uSnrvfUtMX9ugB6t8HUO/KIO+2kBSoS27cUGULeslOpLxYeNyp3IODd7lji+BwqOIb yiTp0Q48IGeTFBdYJ4uOxzJBLM8g7gmXvICEIEjL/HskbZ/1z29IyurY/fnFwVeONuqy Z1SkgEaovbiQUjiZJ76ERnKmfc/qmzvUY+iS32GB9zc6EZi7RwrDSdZNh9q86emHS16l PSroMaHJkhGVGAAOZWIqvMGEeGU8MrBeGzos16NhwOr3O5wPlYGKn1lggbsvy/W80ufa 3gmA== X-Gm-Message-State: AOAM530NIvGLH8zob8gPN3YLy/JiRBONPJHlfA5ng6lSb5r4XSRfdjdi 2UNsyN7lg+drZraThJ5XH1Aj+L5zA+t0gpye46PlUg== X-Google-Smtp-Source: ABdhPJz8lkdiVYrj4P3x1i2Vrmi9AoEo5maSK7RR03IgaBMALT+NVIzESpOO1t4YOJK58xAcD/iJec3E8zUdkOJS9aA= X-Received: by 2002:a63:f145:: with SMTP id o5mr14491018pgk.273.1629385583710; Thu, 19 Aug 2021 08:06:23 -0700 (PDT) MIME-Version: 1.0 References: <20210817033032.76089-1-songmuchun@bytedance.com> <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> In-Reply-To: From: Muchun Song Date: Thu, 19 Aug 2021 23:05:45 +0800 Message-ID: Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) To: Johannes Weiner Cc: Andrew Morton , Roman Gushchin , Michal Hocko , Shakeel Butt , Vladimir Davydov , Matthew Wilcox , LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C84E3100F6C0 X-Stat-Signature: rbw3sepo73mzxzwgehxgq5u3tqj71x98 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=fgjovzas; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf13.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.172 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1629385584-310005 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 Thu, Aug 19, 2021 at 7:16 PM Johannes Weiner wrote: > > On Thu, Aug 19, 2021 at 02:33:37PM +0800, Muchun Song wrote: > > On Wed, Aug 18, 2021 at 3:39 PM Andrew Morton wrote: > > > > > > On Tue, 17 Aug 2021 21:44:36 -0700 Roman Gushchin wrote: > > > > > > > On Wed, Aug 18, 2021 at 12:35:08PM +0800, Muchun Song wrote: > > > > > On Wed, Aug 18, 2021 at 10:16 AM Roman Gushchin wrote: > > > > > > > > > > > > On Tue, Aug 17, 2021 at 11:30:32AM +0800, Muchun Song wrote: > > > > > > > Instead of hard-coding ((1UL << NR_PAGEFLAGS) - 1) everywhere, introducing > > > > > > > PAGEFLAGS_MASK to make the code clear to get the page flags. > > > > > > > > > > > > > > Signed-off-by: Muchun Song > > > > > > > --- > > > > > > > include/linux/page-flags.h | 4 +++- > > > > > > > include/trace/events/page_ref.h | 4 ++-- > > > > > > > lib/test_printf.c | 2 +- > > > > > > > lib/vsprintf.c | 2 +- > > > > > > > 4 files changed, 7 insertions(+), 5 deletions(-) > > > > > > > > > > > > > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > > > > > > > index 54c4af35c628..1f951ac24a5e 100644 > > > > > > > --- a/include/linux/page-flags.h > > > > > > > +++ b/include/linux/page-flags.h > > > > > > > @@ -180,6 +180,8 @@ enum pageflags { > > > > > > > PG_reported = PG_uptodate, > > > > > > > }; > > > > > > > > > > > > > > +#define PAGEFLAGS_MASK (~((1UL << NR_PAGEFLAGS) - 1)) > > > > > > > > > > > > Hm, isn't it better to invert it? Like > > > > > > #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) > > > > > > > > > > > > It feels more usual and will simplify the rest of the patch. > > > > > > > > > > Actually, I learned from PAGE_MASK. So I thought the macro > > > > > like xxx_MASK should be the format of 0xff...ff00...00. I don't > > > > > know if it is an unwritten rule. I can invert PAGEFLAGS_MASK > > > > > if it's not a rule. > > > > > > > > There are many examples of both approached in the kernel tree, > > > > however I'd say the more common is without "~" (out of my head). > > > > > > > > It's definitely OK to define it like > > > > #define PAGEFLAGS_MASK ((1UL << NR_PAGEFLAGS) - 1) > > > > > > > > > > PAGE_MASK has always seemed weird to me but I figured that emulating it > > > would be the approach of least surprise. Might be wrong about that... > > > > IIUC, you seem to agree with the current approach. Right? > > We do use both schemes. PAGE_MASK, as you pointed out. PMD_MASK, > PUD_MASK etc. also *hide* rather than extract the named bits. > > However, we already have a series of masks for page->flags in mm.h > that follow the more common scheme of *extracting* the named bits: > > #define ZONES_MASK ((1UL << ZONES_WIDTH) - 1) > #define NODES_MASK ((1UL << NODES_WIDTH) - 1) > #define SECTIONS_MASK ((1UL << SECTIONS_WIDTH) - 1) > #define LAST_CPUPID_MASK ((1UL << LAST_CPUPID_SHIFT) - 1) > #define KASAN_TAG_MASK ((1UL << KASAN_TAG_WIDTH) - 1) > #define ZONEID_MASK ((1UL << ZONEID_SHIFT) - 1) > > Because of that, I would agree with Roman here and say it probably > makes sense to put the PAGEFLAGS_MASK definition next to those and > follow the "mask everything but" semantics. Thanks for your suggestions. I'll send a v2 patch.