Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp776309ybg; Wed, 10 Jun 2020 13:26:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4I29ZBUWhcQ0GJoje4S6MI+byHV755Dm2sHk6CBsnPLXyToCWMgBaRZ5vGWkWk8OGKUtM X-Received: by 2002:a05:6402:6cc:: with SMTP id n12mr3904388edy.266.1591820790208; Wed, 10 Jun 2020 13:26:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591820790; cv=none; d=google.com; s=arc-20160816; b=nh532N/1/RvCopJDCI1Ry6Yvwbb9W2621U0yGcKyZgvc5u3nGUJCMOlIt2DSBQT41J XaTIhjGLLv6/obFJEG+sopJ5cJpLlSKJgk/uqASp99t8hmE8JwOtOJCkjHET5k+Tepqi 0XW7NMsCG09xmuLrSI+kjzXvZ8mLFqkPjzyCYNQiT1GQDCNAo2ZAnlzYzhMAI88iOahQ qF+uxQ8KFTix0SAlSmG0g3UDi2HeXIGXXhJswb3YTP6HGmCs6cXbCx4GmoyGcT6cax6a J+uHiVhY8iJVxNx4M2eXxLeS4uXMXGnHaXEHoNvDb8aJgEl8zGjWYIv/CWd7UggGFwh5 pnPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=To8irju2/LINnhXcN1nryanQ2IhjjlZJW8yhv6eYHp0=; b=zLYUT+V+YrvGAiBfpGvLREqMbQTG9+/DtJdp6nH3etFYQextcaO5MfJC6HwUK2j84x kDUWKowj7Q6RuzB7pP2KJQYjMRdCycLfHmBdrY8JWJWihzLlmj+P92ujM/fa2FjOj7rW KThOoUTFDn9/RuYvM58ooZkaFCfulZ4E1Ot8d0Ste7zwvtKWWJOUG40J2aYYCDxhEKz7 17w7mK3Vu6NKHE2QOR3LAesrPsxzTa15W6zJaEB3xePaBaOE83HTxx6B3pNm7VYlpWW5 qiSoBbdh4Q2B+zxr6c8DFGP2uxf6S1CIcX+n1kV3pmMKjwy9ur2Ru/vk6NOJ2F+B0RXM ArLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aQpqFIA5; 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 g14si636012ejo.587.2020.06.10.13.26.07; Wed, 10 Jun 2020 13:26:30 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=aQpqFIA5; 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 S1727816AbgFJURf (ORCPT + 99 others); Wed, 10 Jun 2020 16:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730527AbgFJUNs (ORCPT ); Wed, 10 Jun 2020 16:13:48 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCBF9C08C5C7; Wed, 10 Jun 2020 13:13:47 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } /** @@ -294,9 +292,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 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; +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 /* @@ -879,13 +900,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; -} - static inline bool hpage_pincount_available(struct page *page) { /* @@ -904,20 +918,6 @@ static inline int compound_pincount(struct page *page) return atomic_read(compound_pincount_ptr(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.26.2