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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 C827CC10F27 for ; Wed, 11 Mar 2020 13:21:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A9A321D7E for ; Wed, 11 Mar 2020 13:21:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RxYWpJge" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A9A321D7E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 345ED6B0003; Wed, 11 Mar 2020 09:21:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 320D96B0006; Wed, 11 Mar 2020 09:21:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 259BC6B0007; Wed, 11 Mar 2020 09:21:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 0CEE36B0003 for ; Wed, 11 Mar 2020 09:21:19 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E9FC98248076 for ; Wed, 11 Mar 2020 13:21:18 +0000 (UTC) X-FDA: 76583142636.11.base34_7fca4354e4525 X-HE-Tag: base34_7fca4354e4525 X-Filterd-Recvd-Size: 3908 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Mar 2020 13:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FfCcLsPHdUtrDitd68ZafFlotuoFLWbJPCeQRCxIP1E=; b=RxYWpJge4P4rvXc4XR/2Q4HpnY q+FZLKDGRvfc7mi3tBcCzbCFsQUiE9sWYp2gHe3SUEgMJDuP57MmfOrKVQXuDp/KZ9HnIB/z1xgVj 53K/wDUdgD76cw8/GgzefQcy0KHx4ty9mjbdTB1CprEqO6uW+YkmY7KFKLBLsoD7Va5zHxIaxRDp4 a/0Ix4BV09SB41fJ/I4zCIr0AUc6HZrM/Uln5R5qQBuiKHi/3V5AU0wUIvNRbKqP5n3O02m1muacW MSHQIPyUYr0ustSeVXTtzw4k7OUg14wx+1ZFXO5YJ1cMkYqYmR9fSFQBNb64o3HsFPq12Jx3Nu3cs YM3ml3Jw==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jC1IQ-0002J4-Ps; Wed, 11 Mar 2020 13:21:14 +0000 Date: Wed, 11 Mar 2020 06:21:14 -0700 From: Matthew Wilcox To: Andrew Morton Cc: Vlastimil Babka , linux-mm@kvack.org, Alexander Duyck Subject: Re: [PATCH] mm: Make PageType more efficient Message-ID: <20200311132114.GE22433@bombadil.infradead.org> References: <20200310185609.5401-1-willy@infradead.org> <20200310181027.232cff5b00600e1f056a4177@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310181027.232cff5b00600e1f056a4177@linux-foundation.org> 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 06:10:27PM -0700, Andrew Morton wrote: > On Tue, 10 Mar 2020 11:56:09 -0700 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). > > > > ... > > > > --- 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)) > > + > > `flag' should be parenthesized here. As should `page' if one is even > more paranoid. I suppose so. The thing is, the flag name isn't specified by the user; users say 'if (PageBuddy(page))' and the flag gets expanded through PAGE_TYPE_OPS. We also don't need to worry about the user doing 'if (PageBuddy(page++))' as it'll expand into a call to static __always_inline int PageBuddy(struct page *page) { return PageType(page, PG_buddy) } > I tried this: > > --- a/include/linux/page-flags.h~mm-make-pagetype-more-efficient-fix > +++ a/include/linux/page-flags.h > @@ -731,7 +731,7 @@ static inline int page_has_type(struct p > } > > #define PageType(page, flag) \ > - (page_has_type(page) && (~page->page_type & flag)) > + (page_has_type(page) && !(page->page_type & ~(flag))) Mr Boole would like to let you know you misapplied his rules of algebra. ~flag is going to expand into 0xfffffff7f and then gcc will figure out the expression as a whole is always false, and so no page is ever a buddy page, and .. > and page_alloc.o shrunk by 6782 bytes, half of it in > get_page_from_freelist(). Something crazy is going on. gcc-7.2.0.