diff mbox series

[RFC,HACKS,08/11] mm/page_alloc: Simplify gfp_migratetype()

Message ID 20250313-asi-page-alloc-v1-8-04972e046cea@google.com (mailing list archive)
State New
Headers show
Series mm: ASI integration for the page allocator | expand

Commit Message

Brendan Jackman March 13, 2025, 6:11 p.m. UTC
This currently uses optimised bit-hacks to avoid conditional branches
etc. For the purposes of the RFC, let's not get bogged down in those
details - temporarily just drop the bit hacking.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 include/linux/gfp.h | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 6bb1a5a7a4ae3392c1cd39cb79271e05512adbeb..23289aa54b6c38a71a908e5a6e034828a75a3b66 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -14,25 +14,20 @@  struct mempolicy;
 
 /* Convert GFP flags to their corresponding migrate type */
 #define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE)
-#define GFP_MOVABLE_SHIFT 3
 
 static inline int gfp_migratetype(const gfp_t gfp_flags)
 {
 	VM_WARN_ON((gfp_flags & GFP_MOVABLE_MASK) == GFP_MOVABLE_MASK);
-	BUILD_BUG_ON((1UL << GFP_MOVABLE_SHIFT) != ___GFP_MOVABLE);
-	BUILD_BUG_ON((___GFP_MOVABLE >> GFP_MOVABLE_SHIFT) != MIGRATE_MOVABLE);
-	BUILD_BUG_ON((___GFP_RECLAIMABLE >> GFP_MOVABLE_SHIFT) != MIGRATE_RECLAIMABLE);
-	BUILD_BUG_ON(((___GFP_MOVABLE | ___GFP_RECLAIMABLE) >>
-		      GFP_MOVABLE_SHIFT) != MIGRATE_HIGHATOMIC);
 
 	if (unlikely(page_group_by_mobility_disabled))
 		return MIGRATE_UNMOVABLE;
 
-	/* Group based on mobility */
-	return (__force unsigned long)(gfp_flags & GFP_MOVABLE_MASK) >> GFP_MOVABLE_SHIFT;
+	switch (gfp_flags & GFP_MOVABLE_MASK) {
+	case __GFP_RECLAIMABLE: return MIGRATE_RECLAIMABLE;
+	case __GFP_MOVABLE: return MIGRATE_MOVABLE;
+	default: return MIGRATE_UNMOVABLE;
+	}
 }
-#undef GFP_MOVABLE_MASK
-#undef GFP_MOVABLE_SHIFT
 
 static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags)
 {