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=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, 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 E8BA9C10DCE for ; Tue, 10 Mar 2020 20:17:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7A207215A4 for ; Tue, 10 Mar 2020 20:17:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hsRCaFtO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A207215A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 311976B0007; Tue, 10 Mar 2020 16:17:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C2746B0008; Tue, 10 Mar 2020 16:17:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D8656B000A; Tue, 10 Mar 2020 16:17:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 033C06B0007 for ; Tue, 10 Mar 2020 16:17:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 98D676D67 for ; Tue, 10 Mar 2020 20:17:29 +0000 (UTC) X-FDA: 76580562618.08.tramp09_41606cbeeca0c X-HE-Tag: tramp09_41606cbeeca0c X-Filterd-Recvd-Size: 4547 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 20:17:29 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id h3so1946381ils.3 for ; Tue, 10 Mar 2020 13:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YDZuC9aXQNLUgkPEgFd26hcOZ03KKmu0qAwldkZ3DK8=; b=hsRCaFtOBRMm7wWSiE8fAWUvq0LCN5pGRxof7Z/YVETo4Qzel51/wGo4emnhiOO64C IPpwxxJsIuqbRpUAKo9A6t5Lr2BtwtazA7H/0F2UyGl49fM+ZKaW3bZthSkSrPkL9/OC 1E63YSL5XyQ6PQk5R5Ahl01CPGg7pMc6tUZx+o7odoyLuCivofqkDJ64jXattj4P7yGB taIxYdMK8KnC7ZELlLKYScDaDGhXUTOdYihLfqR9ZGVOh7rBQ4fTeQ7f5ZShccTB3PRk D51h7RQS70OhHt20ii1AEoU+VWDNmfHF2rlmdturKsrMM4HMUQK+1qMZtWC0OAzcP5d8 3upA== 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=YDZuC9aXQNLUgkPEgFd26hcOZ03KKmu0qAwldkZ3DK8=; b=mTcsA4fFhHwACIpb5/GXOzYlwtZZD5V9DhTm9q+1qTKsba6yii+SlKp8Gp2te3+/ke V+7TGL/TKx4U2BJPrKgFLCSPPPLI2xWr9GnnWOS2uRgF3ejt2J6NhqzQ/vduNlh94vLH t/nzuGOgY5blKNou9YQf3kpI2sh6Vwtq8mwWTeB8Q4SpRmpeUBWB+Pt+98zB17iNe7MZ B5hShf7HSg8PbOQi7vVjmhzZC/v6WMQxitfVsFQJwC59KaqlvtFdPYn2i3FBMmLiYXcp OKPqDe3vShu44A2/ix/u94hXhOZ3neKZE53U5KX3wXeS6hkkYDzmmWEDRbZ+uTHs4R/L V+Fg== X-Gm-Message-State: ANhLgQ229/e4LWkyX56SfM2u3guoOrSRHsbWnjQwSgeewz+pLJn34FQl aY41QI13m98FzkLZ7RFen/2a/PENXLxkHrdMxnQ= X-Google-Smtp-Source: ADFU+vs0ScaF2Qm2TZyeEijE2mrwxOUqTRrd7S1JNcwRvLTwe/LJ22OGMRHIDJfFVLMBodkmL7eyAcAGBzzVOv9jkKk= X-Received: by 2002:a92:89d5:: with SMTP id w82mr1107074ilk.95.1583871448271; Tue, 10 Mar 2020 13:17:28 -0700 (PDT) MIME-Version: 1.0 References: <20200310185609.5401-1-willy@infradead.org> In-Reply-To: <20200310185609.5401-1-willy@infradead.org> From: Alexander Duyck Date: Tue, 10 Mar 2020 13:17:17 -0700 Message-ID: Subject: Re: [PATCH] mm: Make PageType more efficient To: Matthew Wilcox Cc: Andrew Morton , Vlastimil Babka , linux-mm Content-Type: text/plain; charset="UTF-8" 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, Mar 10, 2020 at 11:56 AM Matthew Wilcox wrote: > > From: "Matthew Wilcox (Oracle)" > > PageType is a little hard for GCC to reason about, By checking > ((~A) & flag) instead of (flag & (A | MASK) == MASK), GCC can do > better optimisations, saving 652 bytes in page_alloc.o (which is > a heavy user of PageBuddy). > > Signed-off-by: Matthew Wilcox (Oracle) > --- > include/linux/page-flags.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > index 1bf83c8fcaa7..8fc0876e2794 100644 > --- a/include/linux/page-flags.h > +++ b/include/linux/page-flags.h > @@ -725,14 +725,14 @@ PAGEFLAG_FALSE(DoubleMap) > #define PG_table 0x00000400 > #define PG_guard 0x00000800 > > -#define PageType(page, flag) \ > - ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) > - > static inline int page_has_type(struct page *page) > { > return (int)page->page_type < PAGE_MAPCOUNT_RESERVE; > } > > +#define PageType(page, flag) \ > + (page_has_type(page) && (~page->page_type & flag)) > + > #define PAGE_TYPE_OPS(uname, lname) \ > static __always_inline int Page##uname(struct page *page) \ > { \ If I recall all the page type is doing is clearing a single bit to indicate the page type, and only one page type is supposed to be set at a time correct? Is there any reason why we couldn't just do an addition and test? Basically just add the flag + 1 and see if the value rolls over to 0. I would think that would reduce to an even simpler setup since that would be an addition with a test for carry flag or zero.