[RFC PATCH 10/16] mm: Set the selected zone in gfp_t flags

From: Juan Yescas

Date: Thu Jul 23 2026 - 04:00:55 EST


This change sets the selected zone in gfp_t flags.

Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---
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 60dfddf6b441..5c00e9134a66 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -87,6 +87,7 @@
#include <linux/debugfs.h>
#include <linux/gfp.h>
#include <linux/gfp_types.h>
+#include <linux/highmem.h>
#include <linux/kernel.h>
#include <linux/mmzone.h>
#include <linux/module.h>
@@ -127,6 +128,33 @@ struct page_alloc {
struct kmem_cache *req_alloc_cache;
struct kmem_cache *page_alloc_cache;

+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,
@@ -136,8 +164,10 @@ 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);
@@ -149,6 +179,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);
+
return cnt;
}

--
2.55.0.229.g6434b31f56-goog