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 47C133F3295 for ; Thu, 23 Jul 2026 07:51:11 +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=1784793072; cv=none; b=TMJMjaXkje6+OkUzL2uls2D6nfaQOCFCveuCVVTbxb4va7wZnK2QVzm2mFlLD/r98qFYVtnVgbWEUhrMNUFn5qizsHzY7Erc0wfGW3JM+nGnmDpHd6fbZkB6HTtNmZVTLYypyZz/y4UUpjwewAiv4UL1bQdHQ0BLb0Hjachmyjc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784793072; c=relaxed/simple; bh=CAmrLKoUa6rho0gBNw+JpG1wan7zSLcKFJibxSb/KKI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M2G6Zw78SLohdF6FqnEj94fVQb5BkN8n/xs6wj01Nzc6ebSF3zcV5i0oody8odHuG/GJo5lneDctCObe+gePPGbsAloM19hICVa1WEblEAygwd2OywOuIprIuVK6E6TaKm/Rjpw0gBZTgfFQ8D2vIqET/yV2LkDIWHrDybb00P4= 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=ExCo5UEK; 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="ExCo5UEK" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cbb92868263so608299a12.2 for ; Thu, 23 Jul 2026 00:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784793071; x=1785397871; 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=7DBUAz0DHEFtyZnsL6ARz3oP4Pqf/8loRhE7mS+17IM=; b=ExCo5UEKsvAOwMZHMs1VICDMDZVzVlLiT7I59gW8UYXszbAUO2Vv+g610XxVmU+GNE Y42BoP4gBsj3XPVLg6J2EPtaCtjnTZ7CqRvBXkSEegFYudnc18b/d5Pq/3VN2sifumNZ Gv7JtLMgZUr1Gs4oBoYYHrbwmMly/zTAPKkVpBO73+uG1B4QJNq/1qbYDEIdldPka74/ BSaRigFUE+dMt5g/aNu+FJFzQd3P11BPyU43mTkpsIuUxbU50a0K26mkeavqnYm2vaTp e7aXji/pV4nAZqPdGLu/n462rMeKaZhOqNFu11CIXPmy+kc2L86NYAq6hzNsfvQfNIBF 3r7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784793071; x=1785397871; 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=7DBUAz0DHEFtyZnsL6ARz3oP4Pqf/8loRhE7mS+17IM=; b=FXs8LeukNK6mH7k/eCwUZ+il0f02YfBXXod2BlM/v0cAFwi56gdC5OlwhOBpXM3OYu zNf5g07qdZkms1J5V5ktSjb/8AOr91f+ov8iQMO3s31na//IaSBdZ9vQFJ+IUz8rYSa4 fW4yl0iCmOxorrOConhfgbm2AnWpwOJF0ToJ/7Aq1f+rKw0s4xF52W0uTFFBs4F0pMrV E5ON0O/aY0IZ7Iij5AoXXJYrTyRiIoeCGjlsFKcHjj2YAJzIRw2nKfBn6ku/nCYnHgyP Jg5VeDsxFOoCPawl2lA6Aojf3aY+6ZJaJ+TT7PtYllBa5yacTnDPv+K0UBw8OCh3Sm+0 2rGw== X-Forwarded-Encrypted: i=1; AHgh+RoH6dlT1wgqNovT1B9AD8HPJsGh6zzpAH0J5z9V9WyScBhB7Jzpfd/HufTgwpOZ5Rdv4QEArLa2JrdllDA=@vger.kernel.org X-Gm-Message-State: AOJu0YzVN4kPo2tHfMjThIDVlzYgsHrGbKXMFRU3YUeAGpXsgDIfuJEY DJf9eWTCLgY66fN4SpsQsNBh02HOdtDlKCnPnwxLRRzhSrCcmTlulkEQbX7G3SqOHDL7RG7oz5e vdDGpBZHK2A== X-Received: from dli14-n1.prod.google.com ([2002:a05:7022:28e:10b0:13d:1c1d:bba]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:7008:b0:3c3:8de3:8eee with SMTP id adf61e73a8af0-3c44b222849mr2150120637.61.1784793070348; Thu, 23 Jul 2026 00:51:10 -0700 (PDT) Date: Thu, 23 Jul 2026 00:47:19 -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-16-jyescas@google.com> Subject: [RFC PATCH 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, 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 --- mm/page_alloc_hogger.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index e65aac881ec7..5fe9c545e884 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 @@ -94,6 +95,7 @@ #include #include #include +#include struct dentry *mmdir; @@ -331,6 +333,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". * @@ -501,6 +534,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( @@ -532,6 +566,13 @@ static int __init page_alloc_hogger_debugfs_init(void) if (ret) goto clean_dir; + free_file = debugfs_create_file("free", 0644, 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.229.g6434b31f56-goog