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=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 76605C433E0 for ; Fri, 15 May 2020 13:17:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2C9A620709 for ; Fri, 15 May 2020 13:17:03 +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="td/O+zfm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C9A620709 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 85B5890000C; Fri, 15 May 2020 09:17:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B0238E0005; Fri, 15 May 2020 09:17:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C5F690000D; Fri, 15 May 2020 09:17:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 503188E0005 for ; Fri, 15 May 2020 09:17:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 110B8180AD806 for ; Fri, 15 May 2020 13:17:02 +0000 (UTC) X-FDA: 76819003884.27.moon85_5a750f0dc4d50 X-HE-Tag: moon85_5a750f0dc4d50 X-Filterd-Recvd-Size: 6023 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 May 2020 13:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=n+nEZyido/DxHe/n1547nGNhqWH1ViJvKc/xC6MlKVQ=; b=td/O+zfmxpLo/MrXYYDpm9YR7t DHh0UbDLqOSyVakWYeqflEpWUwsRRZdJdboX0UOxtO4uddNwi+pMLamucxbcA1AFOPrmXF1y0R7JO +jMDHJtSLbo9tf2WAb2vCzkjxvIwJySsyPHvSh8sAkFcWWBwdXXwf5kpsZWAjvCSCxTC9N0hrZDsA CT7PaPeBDfJXhvfv3V6xMoFqSxojbKbRfpnT4skSwzwcxb+UpknT/lcXRINb4oj9kGE+sjIbo3aGD +5EqYIh7UnhrjdHwbXvknml0fhjzlKzl7Z8unM9AQvccJswAhHwd98RAJGEV/2QusLA8TDGBZtBUs zLQnRpWQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jZaCy-0005Tq-Dm; Fri, 15 May 2020 13:17:00 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 03/36] mm: Allow hpages to be arbitrary order Date: Fri, 15 May 2020 06:16:23 -0700 Message-Id: <20200515131656.12890-4-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200515131656.12890-1-willy@infradead.org> References: <20200515131656.12890-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: "Matthew Wilcox (Oracle)" Remove the assumption in hpage_nr_pages() that compound pages are necessarily PMD sized. Move the relevant parts of mm.h to before the include of huge_mm.h so we can use an inline function rather than a macro= . Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/huge_mm.h | 5 +-- include/linux/mm.h | 96 ++++++++++++++++++++--------------------- 2 files changed, 50 insertions(+), 51 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index cfbb0a87c5f0..6bec4b5b61e1 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -265,11 +265,10 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t= *pud, else return NULL; } + static inline int hpage_nr_pages(struct page *page) { - if (unlikely(PageTransHuge(page))) - return HPAGE_PMD_NR; - return 1; + return compound_nr(page); } =20 struct page *follow_devmap_pmd(struct vm_area_struct *vma, unsigned long= addr, diff --git a/include/linux/mm.h b/include/linux/mm.h index 581e56275bc4..088acbda722d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -671,6 +671,54 @@ int vma_is_stack_for_current(struct vm_area_struct *= vma); struct mmu_gather; struct inode; =20 +static inline unsigned int compound_order(struct page *page) +{ + if (!PageHead(page)) + return 0; + return page[1].compound_order; +} + +static inline bool hpage_pincount_available(struct page *page) +{ + /* + * Can the page->hpage_pinned_refcount field be used? That field is in + * the 3rd page of the compound page, so the smallest (2-page) compound + * pages cannot support it. + */ + page =3D compound_head(page); + return PageCompound(page) && compound_order(page) > 1; +} + +static inline int compound_pincount(struct page *page) +{ + VM_BUG_ON_PAGE(!hpage_pincount_available(page), page); + page =3D compound_head(page); + return atomic_read(compound_pincount_ptr(page)); +} + +static inline void set_compound_order(struct page *page, unsigned int or= der) +{ + page[1].compound_order =3D order; +} + +/* Returns the number of pages in this potentially compound page. */ +static inline unsigned long compound_nr(struct page *page) +{ + return 1UL << compound_order(page); +} + +/* Returns the number of bytes in this potentially compound page. */ +static inline unsigned long page_size(struct page *page) +{ + return PAGE_SIZE << compound_order(page); +} + +/* Returns the number of bits needed for the number of bytes in a page *= / +static inline unsigned int page_shift(struct page *page) +{ + return PAGE_SHIFT + compound_order(page); +} + /* * FIXME: take this include out, include page-flags.h in * files which need it (119 of them) @@ -875,54 +923,6 @@ static inline compound_page_dtor *get_compound_page_= dtor(struct page *page) return compound_page_dtors[page[1].compound_dtor]; } =20 -static inline unsigned int compound_order(struct page *page) -{ - if (!PageHead(page)) - return 0; - return page[1].compound_order; -} - -static inline bool hpage_pincount_available(struct page *page) -{ - /* - * Can the page->hpage_pinned_refcount field be used? That field is in - * the 3rd page of the compound page, so the smallest (2-page) compound - * pages cannot support it. - */ - page =3D compound_head(page); - return PageCompound(page) && compound_order(page) > 1; -} - -static inline int compound_pincount(struct page *page) -{ - VM_BUG_ON_PAGE(!hpage_pincount_available(page), page); - page =3D compound_head(page); - return atomic_read(compound_pincount_ptr(page)); -} - -static inline void set_compound_order(struct page *page, unsigned int or= der) -{ - page[1].compound_order =3D order; -} - -/* Returns the number of pages in this potentially compound page. */ -static inline unsigned long compound_nr(struct page *page) -{ - return 1UL << compound_order(page); -} - -/* Returns the number of bytes in this potentially compound page. */ -static inline unsigned long page_size(struct page *page) -{ - return PAGE_SIZE << compound_order(page); -} - -/* Returns the number of bits needed for the number of bytes in a page *= / -static inline unsigned int page_shift(struct page *page) -{ - return PAGE_SHIFT + compound_order(page); -} - void free_compound_page(struct page *page); =20 #ifdef CONFIG_MMU --=20 2.26.2