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 86AB1C4338F for ; Wed, 18 Aug 2021 05:33:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EF1BD61076 for ; Wed, 18 Aug 2021 05:33:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EF1BD61076 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 7A1E86B006C; Wed, 18 Aug 2021 01:33:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 72C138D0001; Wed, 18 Aug 2021 01:33:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5CBA76B0073; Wed, 18 Aug 2021 01:33:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0137.hostedemail.com [216.40.44.137]) by kanga.kvack.org (Postfix) with ESMTP id 3E07E6B006C for ; Wed, 18 Aug 2021 01:33:31 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id DB2D98249980 for ; Wed, 18 Aug 2021 05:33:30 +0000 (UTC) X-FDA: 78487083780.24.341BCF1 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf30.hostedemail.com (Postfix) with ESMTP id E8B8DE0085D9 for ; Wed, 18 Aug 2021 05:33:28 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id w8so1067042pgf.5 for ; Tue, 17 Aug 2021 22:33:28 -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=tMoQn8GgqE22a95kT2T9MUT0duyCn/8LEmCKNCJyZFo=; b=J+sLV+tiPa32qkx1/OsnH4ufX2n2jfiG0a1/C5JyPfYE9Y5KwJ51+CD+aJRQHylCeW WaEiLSFc1Bg1pbEly34GABw0BLorhvxoIG7M960wEooFSSbe0aw3FRufek2ogtSyn6hy 6yU6RiNozSR9hqREf8B0Mqw7zJfgsThFInbU++Vkuwof/Vhc2n8cWvebfGPxQCOvjIMa 4citbn0/bosovxhelsZuUOijupOkZUgPPFcg0b7SpFFYvbORN0BA1j/JSBojGjsqUqHt PQ8gV/rLaOnjOOgIV7y235JsizKMi9GGWI69xuzxruvaMRxz+S3WHujuoD89N+Wt65Fb aB1A== 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=tMoQn8GgqE22a95kT2T9MUT0duyCn/8LEmCKNCJyZFo=; b=d/EH+c9DiGxLP0wVibTCDtGw4k4RXsyKAHXfaXyxyB7VyYp35kzIc4DV+EagP8Yic2 S5IhRAPOT0Mlp7iC9mxotQdNKg5fqm4Jv0vAjX4f+wQhAY8MeFrxIzvUN8RuNXEYTEFH ct9dE0NWVfwadyo+GR15uIVciuknFo1S481SHMVpyz5SRgWWW3zpK2/09R0ErcQQ79FS 8LnIhcIOVxZEV4dekFzg+ESCUddJH2Vv2WB+Wfan03MwwUfPKvxg26UigBQa1WYIha1u GvbGVh9mx77Y5S1/XKnVRsLJvDwHRNTFvs2MyKBnucSVWMaakhF7xxEvHSJKsgjn7KpM 5fSw== X-Gm-Message-State: AOAM531E2CNjIz3aqg5Npbx5drx8l/78lkBdB0+dGbv8A6PUvhq7zXQC jpSXRhvTb1FH7LRPWqHc197coQDSG7pb5hNJ7w0rPg== X-Google-Smtp-Source: ABdhPJwcl2oZptZbY58B9GgwmQKrzfimZ0zykOVdtmAqRZxvRzAfp/NOW/WGmwWAyLpXb4VlZSWtYhN0GUltRfjoTvI= X-Received: by 2002:a05:6a00:228d:b0:3e1:aba4:8e3 with SMTP id f13-20020a056a00228d00b003e1aba408e3mr7485738pfe.49.1629264807603; Tue, 17 Aug 2021 22:33:27 -0700 (PDT) MIME-Version: 1.0 References: <20210817033032.76089-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Wed, 18 Aug 2021 13:32:48 +0800 Message-ID: Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) To: Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Andrew Morton , 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: E8B8DE0085D9 X-Stat-Signature: tsajxdc6no4bkmrrfzcmw89yzfzrpahb Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=J+sLV+ti; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf30.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-HE-Tag: 1629264808-762286 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 12:44 PM 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) Got it. Thanks Roman. > > Thanks! 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,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 77F2BC4338F for ; Wed, 18 Aug 2021 05:34:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5873D61076 for ; Wed, 18 Aug 2021 05:34:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237874AbhHRFen (ORCPT ); Wed, 18 Aug 2021 01:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237812AbhHRFeC (ORCPT ); Wed, 18 Aug 2021 01:34:02 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB60C0613CF for ; Tue, 17 Aug 2021 22:33:28 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id k24so1063830pgh.8 for ; Tue, 17 Aug 2021 22:33:28 -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=tMoQn8GgqE22a95kT2T9MUT0duyCn/8LEmCKNCJyZFo=; b=J+sLV+tiPa32qkx1/OsnH4ufX2n2jfiG0a1/C5JyPfYE9Y5KwJ51+CD+aJRQHylCeW WaEiLSFc1Bg1pbEly34GABw0BLorhvxoIG7M960wEooFSSbe0aw3FRufek2ogtSyn6hy 6yU6RiNozSR9hqREf8B0Mqw7zJfgsThFInbU++Vkuwof/Vhc2n8cWvebfGPxQCOvjIMa 4citbn0/bosovxhelsZuUOijupOkZUgPPFcg0b7SpFFYvbORN0BA1j/JSBojGjsqUqHt PQ8gV/rLaOnjOOgIV7y235JsizKMi9GGWI69xuzxruvaMRxz+S3WHujuoD89N+Wt65Fb aB1A== 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=tMoQn8GgqE22a95kT2T9MUT0duyCn/8LEmCKNCJyZFo=; b=ZTBs4Z+DldBSJ2B6kJrFlLY/io0CJqZjLd2OkroUlD+EfE3oqz53KFk80bHS1wZAwY VoYWGnxZp8zEv8j0jRk9FW6EIJxl77duIsGMVsSiFdabx9Vm855d9Omps7v895J3kXiW rB7bnucXNgLBbIOmtj18V050en0uOiPs2CRyaqHPtZil0br3eqBvbOVZprB7tlgl6vTW V+692ReqTKmj0QRXmWqK4Gf7kK7gvLmThzpQFfs96SNiKJ28KtRbjRRf4lHkL4mJHHGh mA59UZCiAu6CERCB+n54v3w9B0D9T0Sz9OU9zEVNCK674UGjMb3iwOhdK83ASz6rWYaT Vn0w== X-Gm-Message-State: AOAM533P8MjlNpM0hP/kiYfu8+UgAY/gms5mmW0RSvzafRAyk7IbnAJv UxJBuGqOIvarmiKyuQdwegE+lgX93e+Hyhj4Y8pRuw== X-Google-Smtp-Source: ABdhPJwcl2oZptZbY58B9GgwmQKrzfimZ0zykOVdtmAqRZxvRzAfp/NOW/WGmwWAyLpXb4VlZSWtYhN0GUltRfjoTvI= X-Received: by 2002:a05:6a00:228d:b0:3e1:aba4:8e3 with SMTP id f13-20020a056a00228d00b003e1aba408e3mr7485738pfe.49.1629264807603; Tue, 17 Aug 2021 22:33:27 -0700 (PDT) MIME-Version: 1.0 References: <20210817033032.76089-1-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Wed, 18 Aug 2021 13:32:48 +0800 Message-ID: Subject: Re: [PATCH] mm: introduce PAGEFLAGS_MASK to replace ((1UL << NR_PAGEFLAGS) - 1) To: Roman Gushchin Cc: Johannes Weiner , Michal Hocko , Andrew Morton , 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 12:44 PM 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) Got it. Thanks Roman. > > Thanks!