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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 82DC9C07E96 for ; Thu, 15 Jul 2021 05:26:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3D49B61362 for ; Thu, 15 Jul 2021 05:26:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D49B61362 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 8A4C28D008D; Thu, 15 Jul 2021 01:26:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 87BD68D0065; Thu, 15 Jul 2021 01:26:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 743868D008D; Thu, 15 Jul 2021 01:26:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 5255B8D0065 for ; Thu, 15 Jul 2021 01:26:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 436AA21949 for ; Thu, 15 Jul 2021 05:26:58 +0000 (UTC) X-FDA: 78363688116.19.2B1AAE8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id F25FF60019B0 for ; Thu, 15 Jul 2021 05:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Ih/jlD7ckEePIBEtEqyFyU6U7BAhpCSlbvNH37tyxh8=; b=b5rnLKVPTKcdrUswNACQ1OF639 khSgUwMgJl4M56i7DmZ/XLOZkViWJMkzRhKIR0uTmb2cjoU+70iJGXEPYICdT15E25jAHUe3+vsn9 XwYSQB71/JuWB+a9AhbBXDlreLEpCOv2fpDEy4ZoJcuMUDam3hEfl4AzCkvlor0lEJU5Pk6udYd4H /ns3NoEm6AlN+uU1eK2xobpBk5tx7mxtIvbr4G7SZN5yhQTrv6hFb/d6jd42+WeoPGHhh/SPjLSqd sRVyWJs+z77/t0t41+aE19FpbraOGg+QZDu2H5rMKHTKRYWiu8up4xyqx+qFpErxJ07ePAP6mrHHY Zvg9DeNg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3trx-00315s-Bv; Thu, 15 Jul 2021 05:25:47 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v14 134/138] mm: Support arbitrary THP sizes Date: Thu, 15 Jul 2021 04:37:00 +0100 Message-Id: <20210715033704.692967-135-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=b5rnLKVP; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam02 X-Stat-Signature: 4pm5n4g43fonen97cgnm84rmhimbfmz7 X-Rspamd-Queue-Id: F25FF60019B0 X-HE-Tag: 1626326817-325358 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: Use the compound size of the page instead of assuming PTE or PMD size. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/huge_mm.h | 8 ++------ include/linux/mm.h | 42 ++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index f280f33ff223..b70318fe7863 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -257,9 +257,7 @@ static inline spinlock_t *pud_trans_huge_lock(pud_t *= pud, static inline unsigned int thp_order(struct page *page) { VM_BUG_ON_PGFLAGS(PageTail(page), page); - if (PageHead(page)) - return HPAGE_PMD_ORDER; - return 0; + return compound_order(page); } =20 /** @@ -269,9 +267,7 @@ static inline unsigned int thp_order(struct page *pag= e) static inline int thp_nr_pages(struct page *page) { VM_BUG_ON_PGFLAGS(PageTail(page), page); - if (PageHead(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 99f5f736be64..df1f4c4976df 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -715,6 +715,27 @@ 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; +} + +/* Returns the number of pages in this potentially compound page. */ +static inline unsigned long compound_nr(struct page *page) +{ + if (!PageHead(page)) + return 1; + return page[1].compound_nr; +} + +static inline void set_compound_order(struct page *page, unsigned int or= der) +{ + page[1].compound_order =3D order; + page[1].compound_nr =3D 1U << order; +} + #include =20 /* @@ -937,13 +958,6 @@ static inline void destroy_compound_page(struct page= *page) compound_page_dtors[page[1].compound_dtor](page); } =20 -static inline unsigned int compound_order(struct page *page) -{ - if (!PageHead(page)) - return 0; - return page[1].compound_order; -} - /** * folio_order - The allocation order of a folio. * @folio: The folio. @@ -981,20 +995,6 @@ static inline int compound_pincount(struct page *pag= e) return head_compound_pincount(page); } =20 -static inline void set_compound_order(struct page *page, unsigned int or= der) -{ - page[1].compound_order =3D order; - page[1].compound_nr =3D 1U << order; -} - -/* Returns the number of pages in this potentially compound page. */ -static inline unsigned long compound_nr(struct page *page) -{ - if (!PageHead(page)) - return 1; - return page[1].compound_nr; -} - /* Returns the number of bytes in this potentially compound page. */ static inline unsigned long page_size(struct page *page) { --=20 2.30.2