Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp234204pxb; Wed, 18 Aug 2021 00:41:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXcZ0HjuDop6/3Iiws7QfFZg73KwPRiMMEfhSeJjFkO1bPO/Q/JJ0FtQAq5WZLrBBPC+X/ X-Received: by 2002:a02:2a07:: with SMTP id w7mr6786242jaw.96.1629272503263; Wed, 18 Aug 2021 00:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629272503; cv=none; d=google.com; s=arc-20160816; b=E1BmNy+BYfAU6mCx0KUHpIiFEAYx+2H5+tbxl5qYMOX7oA79ykOe5f+8NfCE+gkeFc EdNN53LDlCluSLJmklALyxyT0V3Nube1EvKQzcRsKGLdE6o5wvVdA37aQfHaxBYZ+WzL aD8E249PD+SZzH1Jy5mCtmbsHQDMhLToPnPz7WvLdKxIsH2H3oQP0hYOFNx0MGmiUqqj XQG+/xLnB44m30gU6i6E4iyw6L9dR22LwjwrKf5Uqfs8AUxTVXoKEMZtcD6FG98lvGDz W6R/FqqdcJYfzTB8vvMUTWuQ7nVfra/WG8ZyZjfcfX+0emGFWXIikGskpDdo9OguunCv V8Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0CCunxkweuUFzA0/U2onqvHP4gnwDm/CwlJzts8P2zU=; b=Ogx4Qelq8qafWJ6fQIjUi5IBm5xc70USfePMR009cNMT8cXdaeEs4+2uklRQEfxBIU nKQ/b3zVBHEodCerOpLyZAvfF7ebGaagu7e0Kr7PnQ2MPRbwn9MAv9UOy05wbfVo1ysI H5rHIscx98uz5RXzWS6PL9j+LXvQ/bP8RmHX8mlsm/4ADYzY2awW4//JHCTV/xssqpwh TLtIP9wxhvBhV3zkBfH8gCzIWo4K6ioLhHbdk2l7nl3mbPTLA/GJxAmLSQrD5U00s/o3 o6hqXdaUUBRzKeV2Ys7gt2PCj2/d9E6E+eAEK64enKTN/DegLI1tJ3HyhNPmKw3vAQs9 GIdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=kmtio6ET; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si5304017iot.103.2021.08.18.00.41.32; Wed, 18 Aug 2021 00:41:43 -0700 (PDT) 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=@linux-foundation.org header.s=korg header.b=kmtio6ET; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239061AbhHRHjy (ORCPT + 99 others); Wed, 18 Aug 2021 03:39:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:44398 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239059AbhHRHjy (ORCPT ); Wed, 18 Aug 2021 03:39:54 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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...