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,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 8E6FEC433DF for ; Wed, 10 Jun 2020 20:14:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A8AA2074B for ; Wed, 10 Jun 2020 20:14:10 +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="aQpqFIA5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A8AA2074B 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 069A48D000C; Wed, 10 Jun 2020 16:13:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F158B8D0013; Wed, 10 Jun 2020 16:13:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0F0B8D000C; Wed, 10 Jun 2020 16:13:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 85AC78D000F for ; Wed, 10 Jun 2020 16:13:52 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4946C801869A for ; Wed, 10 Jun 2020 20:13:52 +0000 (UTC) X-FDA: 76914403104.17.sofa13_040f18126dce Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 0F74218024DFE for ; Wed, 10 Jun 2020 20:13:52 +0000 (UTC) X-HE-Tag: sofa13_040f18126dce X-Filterd-Recvd-Size: 4603 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Wed, 10 Jun 2020 20:13:51 +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=To8irju2/LINnhXcN1nryanQ2IhjjlZJW8yhv6eYHp0=; b=aQpqFIA5a558mRuswO/tjXDNEn CHb/HxwhlS9KyjDOKbpVv1YyD5U3BJFb0R/HHmy4xtop6G73Q+metDN8dyXElNUyr/i3IP5XFjOsu 6vk2uqzdXcdPm+kEQPcb5ZWvc6AbfXXc6WoXf+te+SKLdkMNgpalGnvRWoGy8fpHp3dkZtVJ5ZKHR +qB5ebtCOIx/ATPsPtQatEc0ORAWmedZC6KVzqk3F08IFBY7Y7EX8xFu8AucLmeA+crs6Nt6dKP/e X7Xm1jeENjj3I0v44tyH7wXU2Gi+tZ+88MDYbxQ5RX/aQx5olU91P22O9yGZVq2wPrgKpXRdH0GkK FFlk/wqA==; Received: from willy by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jj76Z-0003UF-OB; Wed, 10 Jun 2020 20:13:47 +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 v6 13/51] mm: Support arbitrary THP sizes Date: Wed, 10 Jun 2020 13:13:07 -0700 Message-Id: <20200610201345.13273-14-willy@infradead.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200610201345.13273-1-willy@infradead.org> References: <20200610201345.13273-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0F74218024DFE X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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)" 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 bd13e9ac3437..d125912a3e0d 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -282,9 +282,7 @@ static inline struct page *thp_head(struct page *page= ) 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 /** @@ -294,9 +292,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 3fc7e8121216..67b36b141ec7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -668,6 +668,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 /* @@ -879,13 +900,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; -} - static inline bool hpage_pincount_available(struct page *page) { /* @@ -904,20 +918,6 @@ static inline int compound_pincount(struct page *pag= e) return atomic_read(compound_pincount_ptr(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.26.2