Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2645793pxv; Sun, 11 Jul 2021 21:19:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy24uZbAEnLJm3BMMFuCSAJWeEasc6uqTH41SUkvF0+0N3FgZ921tJX6/xqz8FZCxiur4rg X-Received: by 2002:a92:d990:: with SMTP id r16mr1402081iln.204.1626063563420; Sun, 11 Jul 2021 21:19:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626063563; cv=none; d=google.com; s=arc-20160816; b=UXFMcWT6xmPBmab7Oai39c+wsO8fg32kjJuqI6C+cp+68i5bqa0Av+p1WACCuHn8zf +MtTajm6npeHfV8Wk0ie8JTHDzRqcMytq4DtE59UrlB5Phtf5Le0kZYr7iOL9vHJOfvO grjWCnQ46fRxRY7lPWx4ZdEzreMPDAP2oNSWM3MApphykSrurhLT3dr5ddkkftN6stZV s+U5w43RVICVAUxm4hoeuuC6MCJKcDMpghcT5mbqe+nCDw+f+d8LBz4vOuWaxvU3yEyH dhy44/aZaChyUDvhNopv1JxEWk3tRdyEIXpRwn4XN1ZHzym9T+lQ4aMuCKClH5qZQNPm t/sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+VbWUeKfZMEA+Wd9+U+PmI5IKCEO5A7uc1AvAOcMUeI=; b=rguqetpPpSKAx56ivAOr4spB0I9CwNqa1i5MT+JI6wWGizrlXV+p0rKq0iuvgocQ/3 5kRsO+ESYFkl9P0tQCjMam4xmXR4g6VXkDajf7ZjThM2HM1mdCO7SPfjb4RJowtNTbV5 qUbTXYN9L1i7GworuP+1JybA1vdP5qmTGgU0LD72CG4KOiLy6FTgX8+FmzIE8Zco8otI V+JxB24UqzvhMP0giirXxKD7zzw3xyl0MN2a0ml6O8qJkOuhiINjh9kSUknc5I2R9oXs GQads7MIRyYYlZ1kc++dm29DwDA32xctWyvmXiPAvpcb9GNRJUhiM+4V87uRa7JPcMH3 yChw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pn9cV8zk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i13si18315386ilm.45.2021.07.11.21.19.12; Sun, 11 Jul 2021 21:19:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pn9cV8zk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231874AbhGLEVD (ORCPT + 99 others); Mon, 12 Jul 2021 00:21:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbhGLEVA (ORCPT ); Mon, 12 Jul 2021 00:21:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10AB3C0613DD; Sun, 11 Jul 2021 21:18:13 -0700 (PDT) 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=+VbWUeKfZMEA+Wd9+U+PmI5IKCEO5A7uc1AvAOcMUeI=; b=pn9cV8zkbPWHK7fSr7+K7k1QRa LAFXsV85iFk2ghPGQHuEd53Ouyy/uFBLOf2NpXAAznuhkvCF8xCN0Ct9ZCglYAec4C3ipLE4WUC6M aQFRelE+CfRKnTMmIxV6PXlGpfWHUpNxHe9V4MPKb/r9xN/cqMoUYd9hNKlcTVNAAY5N94MXoZoTI 4sPFGurW4bUsRd+9zP1qSYTQEe5S5sAej/aaw1ny/Q9UV9jcLMlT0SEmuSqFQ1+i+13cn2IOtQFQL GPHVeEBOF40XlrTAH/sYOLS01vvLjfx/3i0z0gEQNOQpRJtKTIYRD5ULamgJ02LgVaAZZuxy7N9IF BpH//qig==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2nNi-00Grha-Jr; Mon, 12 Jul 2021 04:17:33 +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 v13 133/137] mm: Support arbitrary THP sizes Date: Mon, 12 Jul 2021 04:06:57 +0100 Message-Id: <20210712030701.4000097-134-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } /** @@ -269,9 +267,7 @@ static inline unsigned int thp_order(struct page *page) 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); } 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 24c2b4b97176..0c7cf52619bd 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; +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 order) +{ + page[1].compound_order = order; + page[1].compound_nr = 1U << order; +} + #include /* @@ -936,13 +957,6 @@ static inline void destroy_compound_page(struct page *page) compound_page_dtors[page[1].compound_dtor](page); } -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. @@ -980,20 +994,6 @@ static inline int compound_pincount(struct page *page) return head_compound_pincount(page); } -static inline void set_compound_order(struct page *page, unsigned int order) -{ - page[1].compound_order = order; - page[1].compound_nr = 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) { -- 2.30.2