From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 1D9F03F1ABD for ; Thu, 23 Jul 2026 07:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793065; cv=none; b=JIz+ywK4jFo4RyOMnFJsR4MFokshaKiH3xyTkELZL3oYuIzVF+97yK8SNYIwhJFbc3+UaJogOphakiyZ83A3ude9GEau5G3X3YbIGzhguBwDYVcQ3MHPN/6iCBfCnPQueO4ySwaLTGLtd4vJbuzJoNq2ciFd4d4+olpWT+CYGl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793065; c=relaxed/simple; bh=9w+L1CbicIANDvv7NVICWukpw7jPmYodLJLNjVTP/+8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Omp54KBFwxjzi7xhSxgo0vMU9JUZ8xcH37yudlMHLkB8UM+IsEQCgbOWDlS2cGi1wBTYFiVGzfioiZYvDp0V/ucZxjREOwF6ncnPowvPVZC+4hYo5wzKJG3pvUKb+KHp8a/HJXeNMOZxc8G1Nag30f3NeGWGvR12mWvfy6NU0r4= 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=klbcJkd5; arc=none smtp.client-ip=209.85.216.72 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="klbcJkd5" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38e7621655eso726080a91.0 for ; Thu, 23 Jul 2026 00:51:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784793063; x=1785397863; 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=wF4CarUiD02S5s3G5AQzi1sn1tuKaUMCCFINvnzAblg=; b=klbcJkd5v0VlTUrbSSEdrEFPEp5eK+5zuxla9YSP7mFkVqp0i+kPx1VqLtdvfIL1RC i6KAAYWDKHAgqAq43QtPO0UYo5Wh+RCuieYNtQaHSyHReKA+6lJgGKIEvPcdRuhH0jbA UgPbwNNdkdx1QzkesMfc5QiLuIbb3LeyPFikodkepJupkzf+m19u0JIkgCKDp/QypFBy /psI+ZrddHVMX0p2oORSF35fkh86ySEzT7q3C5NQPg/5ZO2gXQSgk/or87UZ3Ifr1fRE 1+dJyLvm86bj58UeqLYcojNqNQEPuteVxPxd99RKwnFHTBLm0RH4QD5SEAQoYgJzXc1r 5gtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784793063; x=1785397863; 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=wF4CarUiD02S5s3G5AQzi1sn1tuKaUMCCFINvnzAblg=; b=ZYyOInDx2xqLoJdMbrhnwmhEBb2ag4+u8fwDzvbINy+HI+soK4ajIEkOZ6e/jvAkyP 7aTj5PT9syr2DZINweON0Tr6WKi/RDyGBgIf2SdkF5A9SsCW6kZVP3geYyxZHAu24i6M 9Y/bG5bC/3fTnMDFXvc9DGc2/IYf/gJ5gpRpOYkANWGdTfT3+FgioXUSI3/rP/aCdx0Q tDq7q+C8Pv5BDYeTUe99b/DjRXb2pZg0KymtOqWkUaSYvorEZoHiPmkjPR62z/WXuZus NBPyfzL6I6p3Esv17RpdcjqEHkl0bwPXR2b7zzJQJ0+38ylrfT0dPKd6wbNgc3BVbCd4 oBoA== X-Forwarded-Encrypted: i=1; AHgh+Rqk3kRvqjsU9Vy+wiF991kReQILbgomhj/V2GTWXnyRWMHRq5dbmXwLrXtIgpgIc2ywI9v1rnTVPwnWJ1c=@vger.kernel.org X-Gm-Message-State: AOJu0Yzp612DttGcTsppiU224MNxmhASgYtTRDgBPDS83sVTbPESo14R mzHEgGyN5P5Pv+OuTSR7se1S6Eoy9JlijDjgFPZSEjYiuIX7PcNbraQPM92T/fjaQS9UH7DYURP dMHDgof9puA== X-Received: from dlar19-n1.prod.google.com ([2002:a05:701b:21d3:10b0:13c:eacb:77ba]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5823:b0:38e:6bd7:fbbf with SMTP id 98e67ed59e1d1-38ec6a48029mr1828425a91.20.1784793063155; Thu, 23 Jul 2026 00:51:03 -0700 (PDT) Date: Thu, 23 Jul 2026 00:47:18 -0700 In-Reply-To: <20260723074854.1013941-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: <20260723074854.1013941-1-jyescas@google.com> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260723074854.1013941-15-jyescas@google.com> Subject: [RFC PATCH 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, 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 --- mm/page_alloc_hogger.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 203b71a25e64..e65aac881ec7 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -253,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 @@ -294,6 +311,14 @@ static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf, return cnt; free_allocs: + /* Free all the pages 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); -- 2.55.0.229.g6434b31f56-goog