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 03C92C10DCE for ; Tue, 10 Mar 2020 21:51:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A73AA2071B for ; Tue, 10 Mar 2020 21:51:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YT8vOzoX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A73AA2071B 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 3B55B6B0003; Tue, 10 Mar 2020 17:51:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 365AD6B0006; Tue, 10 Mar 2020 17:51:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 27E7F6B0007; Tue, 10 Mar 2020 17:51:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 0A31E6B0003 for ; Tue, 10 Mar 2020 17:51:03 -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 D5A168248047 for ; Tue, 10 Mar 2020 21:51:02 +0000 (UTC) X-FDA: 76580798364.24.chain98_919cd7fe8312 X-HE-Tag: chain98_919cd7fe8312 X-Filterd-Recvd-Size: 5545 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 21:51:02 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id w9so14412832iob.12 for ; Tue, 10 Mar 2020 14:51:02 -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=0wxZaiCezG+BAB2hGw5K3mQHkU6FV99F1HwD3yPo4CA=; b=YT8vOzoXbD+q4ZLfHY2OWIt+usk1YWRew+nt/dOiSxBpBoKt4N8i8AcVgRG+d3Qz3z j3zRwweKee2PQBJ2ZtV+nSuedhQoLWuplb79y+gfSp/A1+P0XH8APJKr8v14i/DC6zLK xdvW3FQB+DhN4vmcb31RR98oqtAPoEO2pBTn4xINo2BH4eJQ9fKIXEOxKcbY1R5GADSP xS0oqIWFIYK7FNGLPv+MtA8gFKTlIVCvaKHYyhlGAA8jjmQQLsQiwAtq718SEPuzH4iQ aQ94FDcpz2xC6PMNFlDWns3YU1qPfnRAbTvfFDg/JwCY4avojipDiHgM/Dup9BrhMU3g LseA== 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=0wxZaiCezG+BAB2hGw5K3mQHkU6FV99F1HwD3yPo4CA=; b=KUlMTtXWtrzKLAdYVcvhryUvmoVuZltmlzFCJtvlo/PHwSUdC1wtqzcpIBLSHwWrnu tgeF5q+gs7IdU8Xg5fN9F0nP9JhJCIRWwGD2dLBy2gFV82oJWSOzT0FOzRb0GhOHAcxn wN18nJwm2h9NYFUNvFb81ueiG1vnj8zOTfiBGcAXUtzBh4sBPpGgj+MC8kGEZcmsbgaP 5mc+W8ScoeaaKfLClNiQetuPqd/kH2DpC7e3mITsy/xAbZy1tGc2q8giviEOPrrTXSQT X3+jLkkXU2SJrEAvMvpTboXcLCC80Jdps8qWe49A/tbJrR4uXMExjijai1iKy2FlXRfH d8gQ== X-Gm-Message-State: ANhLgQ3XPXI1CvXPmnlCtrEM106YP3xGsc+8xbQaV96EGvG/bnzC86Gm LaZcYAMAt3cZAURKZSwPYf0d+j9f+s3iFBhx+E4= X-Google-Smtp-Source: ADFU+vsvVSBrqywzIKK1ZhmztQczKXvDw/58nwyms0oGM+X6kpMvn9zgJCocGDSBVf2oddWWltfVLVWyt5Q3AjEpqWo= X-Received: by 2002:a5e:8c0d:: with SMTP id n13mr121973ioj.138.1583877061449; Tue, 10 Mar 2020 14:51:01 -0700 (PDT) MIME-Version: 1.0 References: <20200310185609.5401-1-willy@infradead.org> <20200310203732.GC22433@bombadil.infradead.org> In-Reply-To: <20200310203732.GC22433@bombadil.infradead.org> From: Alexander Duyck Date: Tue, 10 Mar 2020 14:50:50 -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 1:37 PM Matthew Wilcox wrote: > > On Tue, Mar 10, 2020 at 01:17:17PM -0700, Alexander Duyck wrote: > > On Tue, Mar 10, 2020 at 11:56 AM Matthew Wilcox wrote: > > > 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) > > > - >From what I can tell this is the only consumer of PAGE_TYPE_BASE. Since it is removed you can probably remove that definition as well. > > > 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)) > > > + You can probably spare a cycle or two here by testing for "!(page->page_type & flag)". That way you avoid the extra bit flipping since the compiler can just handle the result of the AND op as it sees fit. > > > #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. > > I think we already allow for both PageKmemcg and PageTable to be set > on the same page. I don't want to stop people from being able to do > combinations like that in the future. Okay, i wasn't aware of that. So that prevents us from simplifying this further.