From: Juan Yescas <jyescas@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
open list <linux-kernel@vger.kernel.org>,
"open list:MEMORY MANAGEMENT - CORE" <linux-mm@kvack.org>
Cc: jyescas@google.com, android-mm@google.com, fvdl@google.com,
tkjos@google.com, minchan@google.com, dskiba@google.com,
open list <linux-kernel@vger.kernel.org>,
"open list:MEMORY MANAGEMENT - CORE" <linux-mm@kvack.org>
Subject: [RFC PATCH 12/16] mm: Define the make_alloc() function
Date: Thu, 23 Jul 2026 00:47:16 -0700 [thread overview]
Message-ID: <20260723074854.1013941-13-jyescas@google.com> (raw)
In-Reply-To: <20260723074854.1013941-1-jyescas@google.com>
The make_alloc() is the core function that performs the allocation.
The tasks of this function are:
- Call the Buddy allocator to make the allocation.
- Store the details of the allocation in struct page_alloc.
- Insert the struct page_alloc in an xarray using the allocation id
as key.
If something fails during the allocation, the pages and cache
will be freed.
Signed-off-by: Juan Yescas <jyescas@google.com>
---
mm/page_alloc_hogger.c | 71 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 71 insertions(+)
diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index d91f49880f8d..7f6eebdd5197 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -97,6 +97,18 @@
struct dentry *mmdir;
+/**
+ * atomic_long_t allocs_file_seq - Represents the naming sequence used for
+ * allocation files.
+ */
+atomic_long_t allocs_file_seq = ATOMIC_INIT(0);
+
+/**
+ * allocs_xa - Represent the xarray that contains the actual allocations perform
+ * by this driver.
+ */
+static DEFINE_XARRAY(allocs_xa);
+
/**
* struct req_alloc - Represents the requested allocation
* @node_idx: The Node index to allocate from.
@@ -174,6 +186,47 @@ inline void set_migrate_type_to_alloc_from(int migrate_type, gfp_t *flags_ptr)
}
}
+static int make_alloc(struct req_alloc *req,
+ gfp_t flags, unsigned long *alloc_id)
+{
+ struct page_alloc *pa;
+ struct page *page;
+ char new_alloc_name[12];
+ int ret;
+
+ page = alloc_pages_node_noprof(req->node_idx, flags, req->order);
+ if (page) {
+ pa = kmem_cache_alloc(page_alloc_cache, GFP_KERNEL);
+ if (!pa) {
+ ret = -ENOMEM;
+ goto free_pages;
+ }
+
+ *alloc_id = atomic_long_inc_return(&allocs_file_seq);
+ ret = xa_insert(&allocs_xa, *alloc_id, pa, GFP_KERNEL);
+ if (ret)
+ goto free_page_alloc;
+
+ snprintf(new_alloc_name, sizeof(new_alloc_name), "%lu",
+ *alloc_id);
+
+ pa->req_alloc = req;
+ pa->page = page;
+ } else {
+ return -ENOMEM;
+ }
+
+ return 0;
+
+free_page_alloc:
+ kmem_cache_free(page_alloc_cache, pa);
+
+free_pages:
+ __free_pages(page, pa->req_alloc->order);
+
+ return ret;
+}
+
/**
* 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
@@ -183,10 +236,12 @@ 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 alloc_id;
unsigned long nr_pages_allocs;
unsigned long *allocs_ids;
gfp_t flags = 0;
int ret;
+ int i;
ret = kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs);
if (ret)
@@ -200,7 +255,23 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf,
set_zone_to_alloc_from(req->zone_idx, &flags);
set_migrate_type_to_alloc_from(req->migrate_type, &flags);
+ for (i = 0; i < nr_pages_allocs; i++) {
+ ret = make_alloc(req, flags, &alloc_id);
+ if (ret)
+ goto free_allocs;
+
+ allocs_ids[i] = alloc_id;
+ }
+
+ kfree(allocs_ids);
+
return cnt;
+
+free_allocs:
+
+ kfree(allocs_ids);
+
+ return ret;
}
static const struct file_operations req_page_alloc_fops = {
--
2.55.0.229.g6434b31f56-goog
next prev parent reply other threads:[~2026-07-23 7:50 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 7:47 [RFC PATCH 00/16] Page Alloc Hogger Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 01/16] mm: Page Alloc Hogger module Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 02/16] mm: Define structs for allocation requests and store allocations Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 03/16] mm: Define the caches for the structs req_alloc and page_alloc Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 04/16] mm: Define function to create a dir for each online node Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 05/16] mm: Define function to create a dir for populated zone Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 06/16] mm: Define function to create a dir for each page order Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 07/16] mm: Define function to create a dir for each migrate type Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 08/16] mm: Define function that creates the "nr_pages_allocs" file Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 09/16] mm: Read the nr_pages_allocs value given by user Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 10/16] mm: Set the selected zone in gfp_t flags Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 11/16] mm: Sets the migrate type " Juan Yescas
2026-07-23 7:47 ` Juan Yescas [this message]
2026-07-23 7:47 ` [RFC PATCH 13/16] mm: Create the file asociated with an allocation Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 14/16] mm: Free pages, remove files and clean cache when one alloc fails Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 15/16] mm: Create the "free" file to release the previously allocated pages Juan Yescas
2026-07-23 7:47 ` [RFC PATCH 16/16] mm: Release resources when the page alloc hogger module exits Juan Yescas
2026-07-28 19:29 ` [RFC PATCH 00/16] Page Alloc Hogger David Hildenbrand (Arm)
2026-07-29 0:36 ` Juan Yescas
2026-07-30 7:50 ` Lorenzo Stoakes (ARM)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260723074854.1013941-13-jyescas@google.com \
--to=jyescas@google.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=android-mm@google.com \
--cc=david@kernel.org \
--cc=dskiba@google.com \
--cc=fvdl@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=minchan@google.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=tkjos@google.com \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox