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=unavailable 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 B58C8C4320A for ; Thu, 19 Aug 2021 06:34:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E83161106 for ; Thu, 19 Aug 2021 06:34:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231791AbhHSGew (ORCPT ); Thu, 19 Aug 2021 02:34:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbhHSGet (ORCPT ); Thu, 19 Aug 2021 02:34:49 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E31EFC061756 for ; Wed, 18 Aug 2021 23:34:13 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id j187so4544513pfg.4 for ; Wed, 18 Aug 2021 23:34:13 -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=15LFBoFuuP4d/TgXjeFGT8qoEp2fIp3JE5Jx5/6HQd4=; b=WlIT6qcLWZ7ujuhqd20mOKSFffOebZXPKce/CFAt2PYnng7DPDqrnqq1YPra9isQfk rrh5x4FDEz2sJPik7NPWgXLjs/8NxvcwqyFPJnmCUkfKdYpTvOEl66A9nmyikzHzjtEK kkGXFwgDXoumzIWICuVPacNMFK8FBP1zfqcDp18I1HAioGqO2AqrJu+5F5DVvsvo9quB nl8L/ALRyDwOI/jYNFg5ueDG2tsX+aTJZbKKeRZ1e9SiE/h9ZPB/oQlG4cDbz7qHfth0 KbxreNoCHX78of8H6OmISCBwVZvA5rDl7FjEobrsGR8hw0VoIsU5HBN6WhYBszj9ggdW mGAQ== 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=15LFBoFuuP4d/TgXjeFGT8qoEp2fIp3JE5Jx5/6HQd4=; b=IEvp8NVf/AVAGS0SeNBMcaP+gyl7pMzl3+nHienyJbu+8SiZ9a6ZlxANaElMr21joD y5Ad3q8Zk6NBRIfHQR21LVhTYB8K+PRZHGs1yNUHqtRTRl/FfPF1YC6F2rpQu/odtkGR xAYHlZv8kV2+kwNuBFhoswXpyhtmUMNchn9eY3DBMw3ajopuBpXtwUGHubkZs962ZYW5 ryoi3I1gqJZWye3ijztij+sMVZZ2j2tRCGwkyiecY5VeVEePPuHgUV8c0mzqd8m3j1TU k8zIN6pz1iv90gwQM6KxzqJo+IWMSJpy5V6wCvR6Xm5JoRylWaVk3514o9QPi+lG9xg8 k15g== X-Gm-Message-State: AOAM5307anmx65/3XQX45AFWLEYS6rEGwZmngdInIvJNGYuQ6zlDNJZx j/sQrDejbK0Ih/ldVgTMR8uNQTax3EL3lmI8ejXLlw== X-Google-Smtp-Source: ABdhPJwotcdA2v3SP+h2EqsRy+pChj8lgDWAucmLra2wROM2MbS7834COYbjyI3lgZUHRLNaLOHdO72naBik8NOXQlc= X-Received: by 2002:a63:f145:: with SMTP id o5mr12653784pgk.273.1629354853416; Wed, 18 Aug 2021 23:34:13 -0700 (PDT) MIME-Version: 1.0 References: <20210817033032.76089-1-songmuchun@bytedance.com> <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> In-Reply-To: <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> From: Muchun Song Date: Thu, 19 Aug 2021 14:33:37 +0800 Message-ID: Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) To: Andrew Morton Cc: Roman Gushchin , Johannes Weiner , Michal Hocko , Shakeel Butt , Vladimir Davydov , Matthew Wilcox , LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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 1351CC4338F for ; Thu, 19 Aug 2021 06:34:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A9786610E5 for ; Thu, 19 Aug 2021 06:34:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A9786610E5 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 306246B006C; Thu, 19 Aug 2021 02:34:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B7086B0071; Thu, 19 Aug 2021 02:34:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17E998D0001; Thu, 19 Aug 2021 02:34:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0198.hostedemail.com [216.40.44.198]) by kanga.kvack.org (Postfix) with ESMTP id EF8986B006C for ; Thu, 19 Aug 2021 02:34:15 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A4067180364D1 for ; Thu, 19 Aug 2021 06:34:15 +0000 (UTC) X-FDA: 78490865670.27.3F25F3A Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf25.hostedemail.com (Postfix) with ESMTP id A0327B00E94E for ; Thu, 19 Aug 2021 06:34:14 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id r2so4924592pgl.10 for ; Wed, 18 Aug 2021 23:34:14 -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=15LFBoFuuP4d/TgXjeFGT8qoEp2fIp3JE5Jx5/6HQd4=; b=WlIT6qcLWZ7ujuhqd20mOKSFffOebZXPKce/CFAt2PYnng7DPDqrnqq1YPra9isQfk rrh5x4FDEz2sJPik7NPWgXLjs/8NxvcwqyFPJnmCUkfKdYpTvOEl66A9nmyikzHzjtEK kkGXFwgDXoumzIWICuVPacNMFK8FBP1zfqcDp18I1HAioGqO2AqrJu+5F5DVvsvo9quB nl8L/ALRyDwOI/jYNFg5ueDG2tsX+aTJZbKKeRZ1e9SiE/h9ZPB/oQlG4cDbz7qHfth0 KbxreNoCHX78of8H6OmISCBwVZvA5rDl7FjEobrsGR8hw0VoIsU5HBN6WhYBszj9ggdW mGAQ== 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=15LFBoFuuP4d/TgXjeFGT8qoEp2fIp3JE5Jx5/6HQd4=; b=eEpxl6NGWBxr26w/16ZfR/WkactYfuVMf0/fbN5HKfBNMnYwtAJYStXvVnK4LDBn98 B/V/znIxmsFZYQIQ9oDjw4RRsuIfUCOt62FDNngABcBVrYcX7/iiGTZ/SfYRmG7jw/+t HOwbIAWnHPbWjCt7ufP4yTP8oIQt0515uHeL0TsPDY/jk26Jryyxl50IVqA0S9PwgNDh RHUfzEQOVTyfwiS0+Z3NQNx8iktv9EkSFazuU602YNKZAzg3pDHYtsw4Uk0udEOa3gWO ZRkNMQH+50RjT+sOT1hlWdUdcZNM+XN7/mXdZ1rlB9zXwJOVNrxxoCHLWf7PjR6iXNCs VHNg== X-Gm-Message-State: AOAM533qdsHD/A31iE5aWYlgOxjWrxXsKS4tTkmbbFUHkFvdzlASUjbG mw75fu9qhEiQVqX5WhVS1IXhycv0Hu6a4h6t/TSh1A== X-Google-Smtp-Source: ABdhPJwotcdA2v3SP+h2EqsRy+pChj8lgDWAucmLra2wROM2MbS7834COYbjyI3lgZUHRLNaLOHdO72naBik8NOXQlc= X-Received: by 2002:a63:f145:: with SMTP id o5mr12653784pgk.273.1629354853416; Wed, 18 Aug 2021 23:34:13 -0700 (PDT) MIME-Version: 1.0 References: <20210817033032.76089-1-songmuchun@bytedance.com> <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> In-Reply-To: <20210818003919.5bd008fec6cb0436af2443c4@linux-foundation.org> From: Muchun Song Date: Thu, 19 Aug 2021 14:33:37 +0800 Message-ID: Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) To: Andrew Morton Cc: Roman Gushchin , Johannes Weiner , Michal Hocko , Shakeel Butt , Vladimir Davydov , Matthew Wilcox , LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=WlIT6qcL; spf=pass (imf25.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: A0327B00E94E X-Stat-Signature: k1kux9ottowmy4djg5hhribk5t19tr34 X-HE-Tag: 1629354854-254138 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 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?