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.5 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 4B568C433E0 for ; Fri, 29 May 2020 02:58:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 09304207D3 for ; Fri, 29 May 2020 02:58:29 +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="DZKkewFi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09304207D3 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 8F3DA800B9; Thu, 28 May 2020 22:58:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 85549800B7; Thu, 28 May 2020 22:58:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 725B1800B6; Thu, 28 May 2020 22:58:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0067.hostedemail.com [216.40.44.67]) by kanga.kvack.org (Postfix) with ESMTP id 507F780010 for ; Thu, 28 May 2020 22:58:28 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 088214DC8 for ; Fri, 29 May 2020 02:58:28 +0000 (UTC) X-FDA: 76868248296.18.cook06_faacb0e8f135 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id E5388100ED0EC for ; Fri, 29 May 2020 02:58:27 +0000 (UTC) X-HE-Tag: cook06_faacb0e8f135 X-Filterd-Recvd-Size: 6088 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Fri, 29 May 2020 02:58:27 +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=WesdxYoeRXUg+ZMECXLoeThMPi+37PjXeui7ubZ+WWk=; b=DZKkewFiF8lWK4kfrSvmUcK3ue 1kvlJXVXqXq9CgEcN+zxvJ3sA+TIu8LNKUsWEpdhcHBwF+ldWklAg346inrqQc8i9/gkdCzMt+8cs MSm0MpMLmtYSQtlwnZAERTvv64KiuqO6WHkblib9z6Oev1Z4gk3B3k+xcQmNNDi0AOF7bvdmB65f6 iO0mL2KjMRWp7uPiWh0/bF0uuov2UKSWAK0ZnHw4SjrI9o4FzEapW4b/eXAcsbJhysDZhJDMD6ymh YR8nQv28HI39jqvnqYEOnZBQqs9svrBplzojntOLmwuFLUM3aWlZwZnyBotK+HNYA+CZUKg2Q9LoE H4GZWzqg==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jeVE2-0008Pq-M6; Fri, 29 May 2020 02:58:26 +0000 From: Matthew Wilcox To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zi Yan Subject: [PATCH v5 03/39] mm: Allow hpages to be arbitrary order Date: Thu, 28 May 2020 19:57:48 -0700 Message-Id: <20200529025824.32296-4-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200529025824.32296-1-willy@infradead.org> References: <20200529025824.32296-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: E5388100ED0EC X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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) Reviewed-by: Zi Yan --- 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