diff mbox series

[RFC,03/12] mm: Export HPAGE_PXD_* macros even if !THP

Message ID 20231116012908.392077-4-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/gup: Unify hugetlb, part 2 | expand

Commit Message

Peter Xu Nov. 16, 2023, 1:28 a.m. UTC
These macros can be helpful when we plan to merge hugetlb code into generic
code.  Move them out and define them even if !THP.

We actually already defined HPAGE_PMD_NR for other reasons even if !THP.
Reorganize these macros.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 include/linux/huge_mm.h | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Comments

Christoph Hellwig Nov. 23, 2023, 7:23 a.m. UTC | #1
No way to export macros :)

I'd say define, but other might have better ideas.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Mike Rapoport Nov. 23, 2023, 9:53 a.m. UTC | #2
On Wed, Nov 22, 2023 at 11:23:57PM -0800, Christoph Hellwig wrote:
> No way to export macros :)
> 
> I'd say define, but other might have better ideas.

Make HPAGE_PXD_* macros visible even if !THP
 
> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
Peter Xu Nov. 23, 2023, 3:27 p.m. UTC | #3
On Thu, Nov 23, 2023 at 11:53:04AM +0200, Mike Rapoport wrote:
> On Wed, Nov 22, 2023 at 11:23:57PM -0800, Christoph Hellwig wrote:
> > No way to export macros :)
> > 
> > I'd say define, but other might have better ideas.
> 
> Make HPAGE_PXD_* macros visible even if !THP

Sounds good, thanks both!

Besides, I do plan to introduce a new macro in the next version to mean
"THP || HUGETLB", so as to put PxD code segments into it and not compile
when unnecessary (!THP && !HUGETLB).

Currently what I had is:

config PGTABLE_HAS_HUGE_LEAVES
	def_bool TRANSPARENT_HUGEPAGE || HUGETLB_PAGE

I didn't use something like CONFIG_HUGE_PAGE because it's too close to
HUGETLB_PAGE, even if generic and short enough.  Please speak if there's
any early comments on that, either the name or the format. For example, I
can also define it in e.g. mm/internal.h, instead of a config entry.
diff mbox series

Patch

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index fa0350b0812a..ec463410aecc 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -64,17 +64,19 @@  ssize_t single_hugepage_flag_show(struct kobject *kobj,
 				  enum transparent_hugepage_flag flag);
 extern struct kobj_attribute shmem_enabled_attr;
 
-#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
-#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
-
-#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 #define HPAGE_PMD_SHIFT PMD_SHIFT
 #define HPAGE_PMD_SIZE	((1UL) << HPAGE_PMD_SHIFT)
 #define HPAGE_PMD_MASK	(~(HPAGE_PMD_SIZE - 1))
+#define HPAGE_PMD_ORDER (HPAGE_PMD_SHIFT-PAGE_SHIFT)
+#define HPAGE_PMD_NR (1<<HPAGE_PMD_ORDER)
 
 #define HPAGE_PUD_SHIFT PUD_SHIFT
 #define HPAGE_PUD_SIZE	((1UL) << HPAGE_PUD_SHIFT)
 #define HPAGE_PUD_MASK	(~(HPAGE_PUD_SIZE - 1))
+#define HPAGE_PUD_ORDER (HPAGE_PUD_SHIFT-PAGE_SHIFT)
+#define HPAGE_PUD_NR (1<<HPAGE_PUD_ORDER)
+
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 
 extern unsigned long transparent_hugepage_flags;
 
@@ -254,13 +256,6 @@  static inline bool thp_migration_supported(void)
 }
 
 #else /* CONFIG_TRANSPARENT_HUGEPAGE */
-#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
-#define HPAGE_PMD_MASK ({ BUILD_BUG(); 0; })
-#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
-
-#define HPAGE_PUD_SHIFT ({ BUILD_BUG(); 0; })
-#define HPAGE_PUD_MASK ({ BUILD_BUG(); 0; })
-#define HPAGE_PUD_SIZE ({ BUILD_BUG(); 0; })
 
 static inline bool folio_test_pmd_mappable(struct folio *folio)
 {