[RFC PATCH v2 10/16] mm: Set the selected zone in gfp_t flags
From: Juan Yescas
Date: Wed Aug 05 2026 - 21:19:47 EST
This change sets the selected zone in gfp_t flags.
Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---
Changes in v2:
- Use static for the set_zone_to_alloc_from function.
mm/page_alloc_hogger.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index 9b1eaf3814e1..0e9ac43e9868 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -127,6 +127,34 @@ struct page_alloc {
static struct kmem_cache *req_alloc_cache;
static struct kmem_cache *page_alloc_cache;
+static inline void set_zone_to_alloc_from(int zone_idx, gfp_t *flags_ptr)
+{
+ switch (zone_idx) {
+#ifdef CONFIG_ZONE_DMA
+ case ZONE_DMA:
+ *flags_ptr |= __GFP_DMA;
+ break;
+#endif
+#ifdef CONFIG_ZONE_DMA32
+ case ZONE_DMA32:
+ *flags_ptr |= __GFP_DMA32;
+ break;
+#endif
+#ifdef CONFIG_HIGHMEM
+ case ZONE_HIGHMEM:
+ *flags_ptr |= __GFP_HIGHMEM;
+ break;
+#endif
+ case ZONE_MOVABLE:
+ *flags_ptr |= __GFP_MOVABLE;
+ break;
+ case ZONE_NORMAL:
+ default:
+ *flags_ptr |= 0;
+ break;
+ }
+}
+
/**
* req_page_alloc_write() - Allocates the pages on the requested node, zone,
* order and migrate type. Once the allocation is performed, a file is created
@@ -135,8 +163,10 @@ static struct kmem_cache *page_alloc_cache;
static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
+ struct req_alloc *req = file->private_data;
unsigned long nr_pages_allocs;
unsigned long *allocs_ids;
+ gfp_t flags = 0;
int ret;
ret = kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs);
@@ -148,6 +178,8 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf,
if (!allocs_ids)
return -ENOMEM;
+ set_zone_to_alloc_from(req->zone_idx, &flags);
+
kfree(allocs_ids);
return cnt;
--
2.55.0.629.g250fe7f194-goog