All of lore.kernel.org
 help / color / mirror / Atom feed
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, ljs@kernel.org,
	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 v2 14/16] mm: Free pages, remove files and clean cache when one alloc fails
Date: Wed,  5 Aug 2026 18:09:15 -0700	[thread overview]
Message-ID: <20260806011048.517229-15-jyescas@google.com> (raw)
In-Reply-To: <20260806011048.517229-1-jyescas@google.com>

When one of the requested allocations failed, do

- free the pages that were previously allocated as part of the request.
- remove the files that were created as part of the request.
- clean the kmem cache.
- Erase the struct page_alloc objects from the xarray that were inserted
as part of the request.

Signed-off-by: Juan Yescas <jyescas@google.com>
---

Changes in v2:
	- Remove comment about the future implementation.

 mm/page_alloc_hogger.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index a70c924e4172..ce53a17ac790 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -93,6 +93,7 @@
 #include <linux/nodemask.h>
 #include <linux/printk.h>
 #include <linux/slab.h>
+#include <linux/xarray.h>
 
 static struct dentry *mmdir;
 
@@ -252,6 +253,23 @@ static int make_alloc(struct req_alloc *req,
 	return ret;
 }
 
+static int free_alloc_helper(unsigned long alloc_id)
+{
+	struct page_alloc *pa;
+
+	pa = xa_erase(&allocs_xa, alloc_id);
+	if (!pa) {
+		pr_err("The alloc_id %lu was not found!", alloc_id);
+		return -EINVAL;
+	}
+
+	__free_pages(pa->page, pa->req_alloc->order);
+	debugfs_remove(pa->alloc_dentry);
+	kmem_cache_free(page_alloc_cache, pa);
+
+	return 0;
+}
+
 /**
  * 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
@@ -293,10 +311,15 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf,
 	return cnt;
 
 free_allocs:
-	/*
-	 * A proper clean up of the pages and page_alloc allocations will
-	 * be done in a follow up patch of this topic.
-	 */
+	/* Free all the pages and resources previously allocated. */
+	for (int j = 0; j < i; j++) {
+		int ret2 = free_alloc_helper(allocs_ids[j]);
+
+		if (ret2)
+			pr_err("Unable to free pages associated with file %lu",
+			       allocs_ids[j]);
+	}
+
 	kfree(allocs_ids);
 
 	return ret;
-- 
2.55.0.629.g250fe7f194-goog


  parent reply	other threads:[~2026-08-06  1:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06  1:09 [RFC PATCH v2 00/16] Page Alloc Hogger Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 01/16] mm: Page Alloc Hogger module Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 02/16] mm: Define structs for allocation requests and store allocations Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 03/16] mm: Define the caches for the structs req_alloc and page_alloc Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 04/16] mm: Define function to create a dir for each online node Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 05/16] mm: Define function to create a dir for populated zone Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 06/16] mm: Define function to create a dir for each page order Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 07/16] mm: Define function to create a dir for each migrate type Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 08/16] mm: Define function that creates the "nr_pages_allocs" file Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 09/16] mm: Read the nr_pages_allocs value given by user Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 10/16] mm: Set the selected zone in gfp_t flags Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 11/16] mm: Sets the migrate type " Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 12/16] mm: Define the make_alloc() function Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 13/16] mm: Create the file associated with an allocation Juan Yescas
2026-08-06  1:09 ` Juan Yescas [this message]
2026-08-06  1:09 ` [RFC PATCH v2 15/16] mm: Create the "free" file to release the previously allocated pages Juan Yescas
2026-08-06  1:09 ` [RFC PATCH v2 16/16] mm: Release resources when the page alloc hogger module exits Juan Yescas
2026-08-06  5:22 ` [RFC PATCH v2 00/16] Page Alloc Hogger Andrew Morton
2026-08-11 18:04   ` Juan Yescas
2026-08-06  9:48 ` Lorenzo Stoakes (ARM)
2026-08-06 11:17   ` David Hildenbrand (Arm)
2026-08-11 18:25     ` Juan Yescas
2026-08-11 18:20   ` Juan Yescas
2026-08-11 18:25     ` 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=20260806011048.517229-15-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=ljs@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.