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=-17.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 3D053C4338F for ; Wed, 18 Aug 2021 07:39:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AFE1E6108B for ; Wed, 18 Aug 2021 07:39:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AFE1E6108B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DA50F6B006C; Wed, 18 Aug 2021 03:39:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D55476B0072; Wed, 18 Aug 2021 03:39:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C43CE6B0073; Wed, 18 Aug 2021 03:39:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id A73616B006C for ; Wed, 18 Aug 2021 03:39:21 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 46DDC181BDCB4 for ; Wed, 18 Aug 2021 07:39:21 +0000 (UTC) X-FDA: 78487400922.01.9B51E0A Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP id EC3756005BB7 for ; Wed, 18 Aug 2021 07:39:20 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id BD05C61076; Wed, 18 Aug 2021 07:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1629272360; bh=uOsjx46pIEb9R/raJK1EVvRJGCZHDt9swlO23X7+9TY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kmtio6ETvuhtdSkDBzspOiKPUJQKbHt16CweehjMBb6GMcri0DqdVPgj+OS6xCjrc 21KWPUclxRyUJKMF7oY+lRyq34gRi2XMxNzvjukosRHBhxbSopzywqMxaNvFhYygR9 rjlt6b+7m0F2VDifHEmpdjZBRBdyDj35J9CQ+MH0= Date: Wed, 18 Aug 2021 00:39:19 -0700 From: Andrew Morton To: Roman Gushchin Cc: Muchun Song , Johannes Weiner , Michal Hocko , Shakeel Butt , Vladimir Davydov , Matthew Wilcox , LKML , Linux Memory Management List Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) Message-Id: <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> In-Reply-To: References: <20210817033032.76089-1-songmuchun@bytedance.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: EC3756005BB7 X-Stat-Signature: 5exkj7offmecrh37t6sbeqi5dx7ikepa Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=kmtio6ET; dmarc=none; spf=pass (imf14.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1629272360-157822 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 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...