From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 CCAAC3AD525 for ; Thu, 6 Aug 2026 01:13:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978800; cv=none; b=q6zUbwyqB8erx8OzvDxo/PhWrV9e/PkcW8fzqAb0hfOTlvskACyTO1VIwbb7SrXsLwC5Hg8pZxLhwSAS+FXN5TYYAxN8tBTKFX/oxdWy5z+1QjgITaBrxHvqLBQ6queVdvMW+XXx10q4vGDNDGFzr7hzXyRG5Th6qsLYiV/f/JA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978800; c=relaxed/simple; bh=ZFQ6pRfnvk0QmXMAotWN3dX5JNGHlmrptbSQXVWXPt8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JDqA8RqB0vIKoy5lFQY6YZfG83IsWri5ThEOnql1jcTxcRZajsRwnGqpyeG3j5X4jIzX8owKw2qybfptw+V7WhanNWK9YZHg1W5zyQz9RkvIkhgmoTiQgl3JYSFsKslfNYfcKyeFBGSY7P1x+NFn1LyQwCp7l9QAuZULAmNUEDk= 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=FnUf9GIB; arc=none smtp.client-ip=209.85.215.197 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="FnUf9GIB" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cbb20f82a0eso1952813a12.0 for ; Wed, 05 Aug 2026 18:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978798; x=1786583598; 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=5ajsYv+gmd5fyZphFvjsg6YH/0Wja+j7l623iMcGCo0=; b=FnUf9GIBBkKXcCEJr8Li4z95CAe+5uhTxlrq1K1R4CfhoGZANJsPkB6K240IrAOb+W 8RI0m7BWf7/FNDIO0EIAcsiLYOGyuNfkKj3bTU5U5z1ITdKMPSbjiIpBMchWQ3WF9fF2 +jmjnlAdiaNlsz0fhIY+KTmkA+M5/TnL/ok9bwjDmfTJ3aJ8rOn0TMzjQO39qwQqLOh3 YGMxXxPZ7PJ/tIkY8nfzs+7PsC10yQKHm8GSz8TGevIkKKPuOS4g2RBS/kms74wtNFZg y2GkDhjb2T11X6Yw7RD2pLfFUm1dXEWVg3TaQpr6ycO4TMcO0lkE3k1W1I2OzwR4yeew a6Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978798; x=1786583598; 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=5ajsYv+gmd5fyZphFvjsg6YH/0Wja+j7l623iMcGCo0=; b=r7rwZGkuyQcSS3RVQDqtaEJTme+8Zu+pLCml1SVigdv/NAo/erdbj6J3r3NMmdPtrR RX6nUk8Q0l4swVgGMuc/K1qBYQBKkQHUuWZRCVOxzuVysnTRX+zmKuGqpBEd1F2ehR2h JZA2piOxMBp10JrECRE1jOPhlWchuslc0bs6nr5L0scrzCY7jj+Ud7Ov/cMfmgeztyDC ExEwyfxUQCFNz7TIIdfBWpdlxa0AxLl1EIJpF6nYFg/ZjZOaOKDvrdE8oLVgmWf6lUDU H72GuY51baSTCKMPD7yt10F6yvVZZpxSImr6pZgib3xyXLL0DY6mmnen3yzmSlOseO7q edMg== X-Forwarded-Encrypted: i=1; AHgh+RodxdmMnXW8jlSU3PeYSjrKqygyHstQHIwVEJHFqlywl3hfHYbUf0z26VnFtck+1PKEBx/ErudQVf4FHXs=@vger.kernel.org X-Gm-Message-State: AOJu0YyHxA/3BjEFep4P3o8K1rW/V2RpLm5TpVWem5kTHHrDu2esBUCR pegAQRRGND4Ls74L68eu72BdXIADVRPRatQlNgd1Z2U9PJjRFpUrRKT4nyIrLbJXla304lu5YiX D2IgTNNnmGA== X-Received: from dybrq40.prod.google.com ([2002:a05:7301:46a8:b0:313:f718:830f]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6300:2213:b0:3c0:b943:f984 with SMTP id adf61e73a8af0-3cb85df1920mr13380500637.3.1785978797726; Wed, 05 Aug 2026 18:13:17 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:16 -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-16-jyescas@google.com> Subject: [RFC PATCH v2 15/16] mm: Create the "free" file to release the previously allocated pages 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" This change creates the "free" file and defines its file_operations to release the previously allocated pages. To release an allocation, the user will run: echo > /sys/kernel/debug/mm/free Signed-off-by: Juan Yescas --- Changes in v2: - Set the file permissions to 0200. mm/page_alloc_hogger.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index ce53a17ac790..6a6fbb78513a 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -83,6 +83,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -331,6 +332,37 @@ static const struct file_operations req_page_alloc_fops = { .write = req_page_alloc_write, }; +/** + * free_page_alloc_write() - free the previously allocated pages. + * @file: File where the user is writing. + * @ubuf: Contains the name of the file the user wants to delete and have the + * memory associated with that file freed. + * @cnt: Size of @ubuf. + * @ppos: Current position in the file. + */ +static ssize_t free_page_alloc_write(struct file *file, + const char __user *ubuf, size_t cnt, + loff_t *ppos) +{ + int ret; + unsigned long alloc_id; + + ret = kstrtoul_from_user(ubuf, cnt, 10, &alloc_id); + if (ret) + return ret; + + ret = free_alloc_helper(alloc_id); + if (ret) + return ret; + + return cnt; +} + +static const struct file_operations free_page_alloc_fops = { + .owner = THIS_MODULE, + .write = free_page_alloc_write, +}; + /** * create_nr_pages_allocs_file() - Creates the file "nr_pages_allocs". * @@ -503,6 +535,7 @@ static inline int create_nodes_subdirs(struct dentry *mmdir) static int __init page_alloc_hogger_debugfs_init(void) { + struct dentry *free_file; int ret; req_alloc_cache = kmem_cache_create( @@ -534,6 +567,13 @@ static int __init page_alloc_hogger_debugfs_init(void) if (ret) goto clean_dir; + free_file = debugfs_create_file("free", 0200, mmdir, NULL, + &free_page_alloc_fops); + if (IS_ERR(free_file)) { + ret = PTR_ERR(free_file); + goto clean_dir; + } + return 0; clean_dir: -- 2.55.0.629.g250fe7f194-goog