From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 904F63AFD1A for ; Thu, 6 Aug 2026 01:13:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978792; cv=none; b=Si9DDJj4gxkLlk+5vba2+H/rT2msBkVmKojMC8KsYAlawJjToMtGIsx0GthHZcEml+1qNcJsA7DbMqcHkOuOwp7ArytuMSsIvZ+DeeGu3YiOo4FK2JGEOmLZRF2X6829OkRDy+zqYaFkFUbSDOaLxbfJVzaZUe+4nLGUhwoVEN8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978792; c=relaxed/simple; bh=5gHIvxqFQvumt3U90vdAuMMmbgtFQoTy41zteD/IviY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ahcwjIAniMLv4kS2f0D+9GjoWuOPuCbA4etkHV954pIfEFaH1FgWYqH3t/0YQLwlOZjElyK//uprIH9If/9sDTWvi3Pt9bfM9HpG/gG95VvWiH7K4reCv3J3cBLZy44MiXtTxi4efpA0bNJ+uVL/nUcIq/ksw82LwUHqk6XvfOU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jyescas.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=X/j5OP6L; arc=none smtp.client-ip=209.85.214.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jyescas.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="X/j5OP6L" Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2cc7e86e7c5so27249925ad.3 for ; Wed, 05 Aug 2026 18:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978791; x=1786583591; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=HbcXiPsVSBDPrbHN1PRmrnXCwheSgE1vSd0rMiKNUOI=; b=X/j5OP6LFdSorQWI/MhecmJ81RkFgci0qceLjH13ksbjpMfyfEwlDpHpvlB0gC6kyb m/WXSxpR2C0DI2r7K17PsamJxiLYQ/LBn9j4JytJwUbnsgd3iNn83NOmQGYqk9BXgfiI wizn+SRmlL4AZ1fbTulYrAoNtf8Q4N81ZIoKKHjCu6AyPB81lOeWhG3dDF8FiRVZ7iI6 OccXJh+7j1JqNoRvEgXJp6IG4gGU/SqYBTiqw5tB7/l6CFDEhopwjZF8JrvtlkscoPLF 6rriRd0oG4uw1Phxuo748Lcv8GSMARnN/kw7AF59I4o3sSv/H56cv1N9tjPhJXYpbh9/ H0ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978791; x=1786583591; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HbcXiPsVSBDPrbHN1PRmrnXCwheSgE1vSd0rMiKNUOI=; b=PfHApPOnsLXiLhvz5m8INAHioIxycRs+lL13itSXEZIPsTIt4PHRK+taI+e5L0FqS/ AJEyjG9O9+oSpnfY+IkFlFo4eqyz6C6a5WumAoBzj6PINz/hJbRScVLVYatv11cmskV3 BTUvYsoEG2XMNw2iwmB7PTqcXqpItBQDKSvzOng42rT7icCogAbbFQuUBSzi+yMzXoUX 8V/6MUz9n98uJunUS/uJdxPZPT8PlL2KxRUuQ3fUbR/DCfGCkU+3XE622ZCkWtYgbZG9 mBoJvF/Ja9+zgxHIDF5SVxboo5QV1q0IrkKgaDmR1KY8c94Hf/ZV/zkTKJ1uvJA3NLrR bvqg== X-Forwarded-Encrypted: i=1; AHgh+RoyoGbm5viC3+4wR3ljDy3LaBalSN+fjgeKez07ekTSJ7IoaDlcZH5s7PIdWc6i9Ow7R04IQ9f2ixRoAhM=@vger.kernel.org X-Gm-Message-State: AOJu0YzuUa3ywBmHY84eIAkl9FMGnpK34v0lSF2jDE77QUhbnqCSR/z9 hvfzUvfxoFRhsp6YrM4hoUdsVfLAi2XgZuq/9oqN06nXs+uCyDjOCwpqRWUqVwxnXG6Owd6ka1P t5bdZDp1dkg== X-Received: from dlbeg29.prod.google.com ([2002:a05:7022:f9d:b0:13d:2475:4300]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1c0a:b0:380:105f:8ffd with SMTP id 98e67ed59e1d1-3903c5dc172mr9737267a91.16.1785978790622; Wed, 05 Aug 2026 18:13:10 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:15 -0700 In-Reply-To: <20260806011048.517229-1-jyescas@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806011048.517229-1-jyescas@google.com> X-Mailer: git-send-email 2.55.0.629.g250fe7f194-goog Message-ID: <20260806011048.517229-15-jyescas@google.com> Subject: [RFC PATCH v2 14/16] mm: Free pages, remove files and clean cache when one alloc fails From: Juan Yescas To: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , open list , "open list:MEMORY MANAGEMENT - CORE" 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 , "open list:MEMORY MANAGEMENT - CORE" Content-Type: text/plain; charset="UTF-8" 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 --- 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 #include #include +#include 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