From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 5E61A3A6EE9 for ; Thu, 6 Aug 2026 01:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978671; cv=none; b=O4iaexJVHIwzo3Rtk8z+zyuittlVofOs4QlDQFST5T7SYLUfzYl1jnMTrqfqjxt4gYGDdqzaPr6qBWW00bb5xUeEyz+3o6TUPZsPUKXENTreNHVwrRci5OX0VkxgdwOCBj1F0IitV2hwpvvwDuTjiUYqoUVNQZymbjmwP//SEEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978671; c=relaxed/simple; bh=Vy8A71qsL16PzVXck8lTWsRtkfvzZQTzE7M1TN7synE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=LOcs0XM68j5fl1uYEeng4KDoJOKpWbiDjGLwKEpWcGB9nLn80sgtBSjuY/0mOdM/QSr3o3PDC/OyGDV/RqZXkAM2F0UvcGSIGMgK4i80i/hrPrvYboLxQbHGugggYLhI/xJSkYdzRjrSAzrvfFiBdNzkv0J+JZoJRN8rX3j+1Co= 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=FdJLPBvx; arc=none smtp.client-ip=209.85.216.70 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="FdJLPBvx" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-38ea32e57e2so2756501a91.1 for ; Wed, 05 Aug 2026 18:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978670; x=1786583470; 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=4V9Y8fDSG8MVV4W0n0bDz/rhN/ammIKgNJCb1TELSuA=; b=FdJLPBvxFvQ2Ws1YHVfGmvqjbT7jizf30osItQP+qRkbo92ySpu7YnXr2LFvWKyMZ/ RIPqPNGKo/6oPH6+T6jer1qB6sudTIrFh7nZM7JnxomhJdenKfFeLCK0mdLlWHe+6YYg 5t33qe7guGiYGfphkAN8FYgGkrhaCSQBq5l241w9QJ+FIPZv2sjtoC+Vih48pBxLoIth tlsoulx0GvU2XvsaiFjCsLT6FA9dzY4LSp5l/DkBgEcUzT9oUa6CWKX/ETNq4d0Cs5x5 eENVcvOKQ/HT2HM6pQfBH0t/DBrz6B5Y1GjrBjnL8jXqAxYtJ6JzoP8bTITbWxpVv8fQ RTAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978670; x=1786583470; 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=4V9Y8fDSG8MVV4W0n0bDz/rhN/ammIKgNJCb1TELSuA=; b=DkSD3x5HngubXiiGjMAmCK0j0xddqLjAaaSb70oDJPWwGwQH4IjdHS66r+OgqOGFiv HcTfBYvYthbPr+O4fKm8ta80eAhsTYzcNBe0LD1iDFiZYRMkFCuoUyVVbeDRqzR7GdMS tOCEx7BiwWoE4WXo9DvP4idQIqSXo/sjpfDIMNuEa+K1ykicRbC3WPAFTQvLk3A68Kgx yID/sx0TmP6hD+umK6FtyVHCd1tRnx5P1gAnY7DiblXBlXlrgv/WKbeC7YHMbC1qtaux kqAozcXWxXF29K2H0NubO9eBrBu1ev0p213rB2FIya5zPgLm/aPgT881bH3ihfXvrmTV ZF5Q== X-Forwarded-Encrypted: i=1; AHgh+RqRX//0q1AWVLNi7AACswWYsynVNgmD6k57O5fQGj+K7nhN5fZ05cMM9bJsY/3wF9dVel6pl04ffzJfhZk=@vger.kernel.org X-Gm-Message-State: AOJu0YwDqGE+gLbNNlrszeFlDQzDqhiLZqkHsrErf4HFKjrqXM8xT1Vr 8XrijB+1XmSmdckQvCLZyeGJOHPXoKAq6I1/UqZL5RRPddiB1q9QzyL/6r+Zf081Y3ueQgOnTfT hIlaTV//EjQ== X-Received: from dly27-n2.prod.google.com ([2002:a05:701b:205b:20b0:13d:1da6:85cf]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4d84:b0:381:5bd6:eb19 with SMTP id 98e67ed59e1d1-3903c5dfd9amr10541054a91.18.1785978669221; Wed, 05 Aug 2026 18:11:09 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:02 -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-2-jyescas@google.com> Subject: [RFC PATCH v2 01/16] mm: Page Alloc Hogger module 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch contains the skeleton for the Page Alloc Hogger. It creates the "mm" dir that will be the base directory that will contain the "free" file and the "node-" dirs. Signed-off-by: Juan Yescas --- Changes in v2: - Change to a tristate module. - Fix typos - Use static for the mmdir declaration. mm/Kconfig.debug | 12 +++++ mm/Makefile | 1 + mm/page_alloc_hogger.c | 115 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 mm/page_alloc_hogger.c diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 7638d75b27db..bad8a606152c 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -309,3 +309,15 @@ config PER_VMA_LOCK_STATS overhead in the page fault path. =20 If in doubt, say N. + +config PAGEALLOC_HOGGER + tristate "Alloc pages from different nodes, zones, migrate types and orde= rs" + depends on DEBUG_FS + help + Say Y to alloc pages from different nodes, zones, migrate type and + orders using the debug fs filesystem. This helps to generate memory + pressure easily. This is useful to debug memory reclaims issues, + OOM triggers, page migration issues, etc. + + If in doubt, say N. + diff --git a/mm/Makefile b/mm/Makefile index 2d0570a16e5b..b48f2ac6ee80 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -133,6 +133,7 @@ obj-$(CONFIG_IDLE_PAGE_TRACKING) +=3D page_idle.o obj-$(CONFIG_DEBUG_PAGEALLOC) +=3D debug_page_alloc.o obj-$(CONFIG_DEBUG_PAGE_REF) +=3D debug_page_ref.o obj-$(CONFIG_DAMON) +=3D damon/ +obj-$(CONFIG_PAGEALLOC_HOGGER) +=3D page_alloc_hogger.o obj-$(CONFIG_HARDENED_USERCOPY) +=3D usercopy.o obj-$(CONFIG_PERCPU_STATS) +=3D percpu-stats.o obj-$(CONFIG_ZONE_DEVICE) +=3D memremap.o diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c new file mode 100644 index 000000000000..1d31e981920e --- /dev/null +++ b/mm/page_alloc_hogger.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Page allocator DebugFS Interface + * Author: Juan Yescas + * + * This module allows to make page allocs per node, zone, migrate type + * and order using the DebugFS filesystem. + * + * When this module is installed and the debugfs is mounted, the "mm" dire= ctory + * will be created in /mm" directory. Under this dire= ctory, + * there will be subdirs to select the nodes, zones, orders and migrate ty= pe. + * + * For example: + * + * /sys/kernel/debug/mm/ + * |-- free + * `-- node-0 + * |-- zone-DMA + * | |-- order-0 + * | | |-- migrate-HighAtomic + * | | | `-- nr_pages_allocs + * | | |-- migrate-Movable + * | | | `-- nr_pages_allocs + * | | |-- migrate-Reclaimable + * | | | `-- nr_pages_allocs + * | | `-- migrate-Unmovable + * | | `-- nr_pages_allocs + * | |-- ... + * | | + * | `-- order-9 + * | |-- migrate-HighAtomic + * | | `-- nr_pages_allocs + * | |-- migrate-Movable + * | | `-- nr_pages_allocs + * | |-- migrate-Reclaimable + * | | `-- nr_pages_allocs + * | `-- migrate-Unmovable + * | `-- nr_pages_allocs + * `-- zone-Normal + * |-- order-0 + * | |-- migrate-HighAtomic + * | | `-- nr_pages_allocs + * | |-- migrate-Movable + * | | `-- nr_pages_allocs + * | |-- migrate-Reclaimable + * | | `-- nr_pages_allocs + * | `-- migrate-Unmovable + * | `-- nr_pages_allocs + * |-- .... + * | + * `-- order-9 + * |-- migrate-HighAtomic + * | `-- nr_pages_allocs + * |-- migrate-Movable + * | `-- nr_pages_allocs + * |-- migrate-Reclaimable + * | `-- nr_pages_allocs + * `-- migrate-Unmovable + * `-- nr_pages_allocs + * + * Usage: + * + * 1. To trigger the allocation, navigate to the debugfs path corresponding + * to your target node, memory zone, allocation order, and migration ty= pe, + * then write the requested allocation count to nr_pages_allocs. + * + * For example, to make 3 allocs of order 9, Migrate Type Movable, + * Zone Normal and Node 0, run: + * + * $ echo 3 > /sys/kernel/debug/mm/node-0/zone-Normal/order-9/migrate-M= ovable/nr_pages_allocs + * + * 2. For each allocation created, a corresponding file named sequentially + * (1, 2, n) will appear in that directory. + * + * $ ls /sys/kernel/debug/mm/node-0/zone-Normal/order-9/migrate-Movable/ + * 1 2 3 nr_pages_allocs + * + * 3. To free the allocation, write the allocation file name in /sys/kerne= l/debug/mm/free. + * For example, to release the 2nd allocation run: + * + * $ echo 2 > /sys/kernel/debug/mm/free + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include + +static struct dentry *mmdir; + +static int __init page_alloc_hogger_debugfs_init(void) +{ + mmdir =3D debugfs_create_dir("mm", NULL); + if (IS_ERR(mmdir)) { + pr_err("Unable to create mm directory\n"); + return PTR_ERR(mmdir); + } + + return 0; +} + +static void __exit page_alloc_hogger_debugfs_exit(void) +{ + debugfs_remove_recursive(mmdir); +} + +module_init(page_alloc_hogger_debugfs_init); +module_exit(page_alloc_hogger_debugfs_exit); + +MODULE_AUTHOR("Juan Yescas"); +MODULE_DESCRIPTION("Module to alloc pages to generate memory pressure"); +MODULE_LICENSE("GPL"); --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 3E6C53ACA40 for ; Thu, 6 Aug 2026 01:11:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978706; cv=none; b=Cmk0YH2EILqk2PPUGt7yz9MdAfXBt29fX+ZNiTJldm1eEzQBzfjJL4ORLjGyjlrsBq7lRZrX2dGdKc4w4LvCOOwglizZ8Ugn11FayeC1RhBYtkCdHwnO4Gffiy8/tnLPislbgTmtTMwd+7rpCQYAdZ92hZ+xWgiH7ZnOcKnGgEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978706; c=relaxed/simple; bh=5AaApttVqbmS2RB38bffwjxMG95ohL6u4K18dqLzr2Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pHJy3FdXRwrQjQY69nj+3SOyBPfyqqMJH2UWRD5m3jqR0ngohtxO4ilkRGofXbXRiXxJPnOyYY7ozDgEllqKi7Llutsv0VWg/jkwppyTLqqqnzzUhkH0aNVIJlzPaDBlPvTIqdtQC7PTQ7ti4HoNk8dSpvBo4Vf8DYk1zEZqpXY= 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=FCz0YAeo; arc=none smtp.client-ip=209.85.216.71 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="FCz0YAeo" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38e475f83a2so2571546a91.1 for ; Wed, 05 Aug 2026 18:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978704; x=1786583504; 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=v2eQsWE6/2RUaKCIRrlhYiV3zZI+x2OroGpQf2kxf/g=; b=FCz0YAeocwurYxB4UqtLlYsgPfLNiuOJBpcTZGzeUQY3ohLhm7JbjSuRtXEBz00PZd 7wZ8EhoG40B7rl5N2iyPf6Do3l9KgoLwdDkrKcd9x0U+c5KdXt+vW+j/qwnuTeRxdijR uzTzB9EGKxCfsc+0i1oY6Wi7o5guwMBSDFziis7TdrCWrq/cCN6MQJqtokQfC5Jta+eh VajQHDL3rfIoYoWUX1sIkwtpOrFALdyZkgpH6MV5+dm67BtqkAN0vjxqBGaJ3UpX0pdE jxLjF05589UDM8OVZuIIIwl+tnyyLSKrHtTrvRpmvU7/STjBaNvil0ZbkLGNirssITAA rYBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978704; x=1786583504; 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=v2eQsWE6/2RUaKCIRrlhYiV3zZI+x2OroGpQf2kxf/g=; b=LgV5i4PVtxN97MVEqGUU88YQ4pjNYXah0zm5GHCCEldOaI7xUv8kwokX0gJaOrqTLA 7UdtQgQ3wG3wcDYevRRSQkxbEwp86LfxKVvl2DLYsg8ASedMirf3jIMdfcQU3JWhVFMZ Hyjae3EjwLZ7J596wNqV0Hxc6tcdm+07sFINtblFllEO76oVbsHOHHmlghROYq9NxOSG e4rgD5qYbKPRJqWx1tM1Hb9sI9XmknU5JLv7pTRB2izU3h8UasNq7o6KklCrUbf+bnlN xsA7HYeLorq6JWgchSNuo2oGkTAeoIjDnyQXzhV+x7NWZeo81rgZysra+lBuOVSmDaWk 0PlA== X-Forwarded-Encrypted: i=1; AHgh+RpgQg5wanNOKOwjO0sn58ZTV9dtiDx9Z45cL0OjwaHsJkkS/RIu/VL5IFaiWTSZqG61CyIvBGdsNY7gLW8=@vger.kernel.org X-Gm-Message-State: AOJu0YzH9ZdM/28eFhEhQWu7CrC1IePCAYv3PHzhaAe+1CA2AdnJjSXv NuGGhDlbLqPXLeBrtbsr/dVTkXaRs+yLc8LBQGITWl6VWmFnHVhoKqgEAY+thB4jCzgUDeQX/Oh CaRNCDvTm8Q== X-Received: from dloo4.prod.google.com ([2002:a05:7023:a44:b0:13d:1fe2:b775]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3a8d:b0:38e:57a3:f218 with SMTP id 98e67ed59e1d1-3903c5b9f70mr9731131a91.13.1785978704313; Wed, 05 Aug 2026 18:11:44 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:03 -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-3-jyescas@google.com> Subject: [RFC PATCH v2 02/16] mm: Define structs for allocation requests and store allocations 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change introduces the next structs: - struct req_alloc to keep the request info for the allocation. - struct page_alloc to store a pointer to the page that was allocated, the request info and the file that represents this allocation. This file will be used to free the allocation when it is not longer needed. Signed-off-by: Juan Yescas --- Changes in v2: - Fix comment block. Add an extra * at the beginning. mm/page_alloc_hogger.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 1d31e981920e..caeb2e5e8579 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -91,6 +91,34 @@ =20 static struct dentry *mmdir; =20 +/** + * struct req_alloc - Represents the requested allocation + * @node_idx: The Node index to allocate from. + * @zone_idx: The Zone index to allocate from. + * @order: The Order of pages to allocate. + * @migrate_type: The Migrate type to allocate from. + * @parentdir: The parent dir where the file representing the alloc was cr= eated. + */ +struct req_alloc { + int node_idx; + int zone_idx; + int order; + int migrate_type; + struct dentry *parentdir; +}; + +/** + * struct page_alloc - Represents the page allocation. + * @page: The pointer to the page(s) allocated. + * @req_alloc: The details of the allocation. + * @alloc_dentry: The pointer to the file that represents the allocation. + */ +struct page_alloc { + struct page *page; + struct req_alloc *req_alloc; + struct dentry *alloc_dentry; +}; + static int __init page_alloc_hogger_debugfs_init(void) { mmdir =3D debugfs_create_dir("mm", NULL); --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 332C23AB47E for ; Thu, 6 Aug 2026 01:11:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978713; cv=none; b=fXIwIOMYh4WXg9SABfL/HyGnQ6fJyZmLrYjfmprh9JJr0zlo/Cl7ysCXQkF9IEBj6bG29BhDvkkhoKymBcUhs+JNIjB2S8bOG7PWyZBYMHySj81wP2O0lq94g5iM6GHIvIgrQ3M+gIJNxsrtWMD2i1Z9rShtBa75MdRuSNsq3yc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978713; c=relaxed/simple; bh=DrsM1A0c0oXFvXGMr4YkYD74KwdjvSxrMPaIgTNExyw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=KkBzGtiDvsAY8wiG3IHy4YPagZbx48jUbkS56oEY6LLUO3FuYTU8hQCS0qNBw7oRVDM1o5FxUbzJL5AzowcH0mG1gzHkgw8YF1NDMnPPSi51s1N/kAKoWuA6z/ZXfCN/g15BwhUHZp2kD0XfT38XL+KSBl3QkIaVG7KEnNH8dIQ= 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=NI6kUYmI; arc=none smtp.client-ip=209.85.215.198 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="NI6kUYmI" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c89704da8c7so2440585a12.0 for ; Wed, 05 Aug 2026 18:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978711; x=1786583511; 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=MHXuMtbWju/rmVGPj2ANhVgDVgcL2e8ZMo4e+wRd2rA=; b=NI6kUYmIgoOa/PViMVSTuiP0BBuSGjsOmbrqY3Ylrqo3IkxromLn16CPsn3wgOozXj he4wmPpeuzah9b26sLqXtE6jxVolZLXrobIVjCYDhbj2cYK5J92v5sILxj0HtmGjDikv DhDYUpDU/EVnwhiZbcBoH91JuaTTGGoSU8DzUxz23a2bwNAjG/waWOckdut1o0f13XZW vh6Ydfb/wrT+pf4hQvLApyZAsgm4OZuTMUrThj8Or3zYfhz8pU0Cn6TWeX2UKSK7ewxD hk33QoXJNsQiW+E4jGIO0JS+0Cn/qd4bkem49oSc0cu7IA9KKU30KdeZDpl7qxekeaKW VcZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978711; x=1786583511; 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=MHXuMtbWju/rmVGPj2ANhVgDVgcL2e8ZMo4e+wRd2rA=; b=PUQ/grlPxA7VgVTNsypzl7FHcbgE4fo0Y11IiHghdvb6vgXq1TqEjk4szJGfpH2F5w pV8MuaFnnOBcpFz8nEpc6EuU+TmuSO3tsXPs/8gLe4E32DC04uNgv/QJdO6r+xOU04yg v8sUJL+ozsaZPuE+4pdoLkb15WrlLtWOQb+CdB0IX8WY2c9ogfi74BWPveQFXDjekORS g0YRz8l9VxtAQyi9tnQPxwHPktQOHilVe+joCyWxeG6E7hbeJmOdOt39bwfre4rmni// 8I6ylNFttksz89m0bh4TnQg8CjmbJBuflWpFheu1YJ27W7Xf928HREZA6o2cuQHQWEop JrxA== X-Forwarded-Encrypted: i=1; AHgh+RoIq0XQtwFHASTanIK8XXGjiq/5MCG09m7e94+GEWvQ36C0l4fDlHjGXiu2f9jYv1ldCBx6AuWkqrV2cKM=@vger.kernel.org X-Gm-Message-State: AOJu0YxqOFtT/5yU8KUeqJAuiXES4tirHmjMRMiRVmHSRNGiImOZJw3L zhAvTNCgfunAQRqrxYuvfr8vDpxErQeb5SkO2G6Nc1ckstbpyUzPblRmLrxCt70RTAueXyOpKsO CUr4qlzHTUg== X-Received: from dyaw6-n2.prod.google.com ([2002:a05:693c:4146:20b0:30f:c4be:bef4]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:164a:b0:3c3:a08d:5b44 with SMTP id adf61e73a8af0-3cb85ef9234mr13893240637.23.1785978711382; Wed, 05 Aug 2026 18:11:51 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:04 -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-4-jyescas@google.com> Subject: [RFC PATCH v2 03/16] mm: Define the caches for the structs req_alloc and page_alloc 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change defines and initializes the caches for the structs req_alloc and page_alloc. Signed-off-by: Juan Yescas --- Changes in v2: - Use static for the kmem_cache variables. - Use \n for the pr_err messages. mm/page_alloc_hogger.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index caeb2e5e8579..175f479c487b 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -85,9 +85,12 @@ =20 #include #include +#include +#include #include #include #include +#include =20 static struct dentry *mmdir; =20 @@ -119,20 +122,55 @@ struct page_alloc { struct dentry *alloc_dentry; }; =20 +static struct kmem_cache *req_alloc_cache; +static struct kmem_cache *page_alloc_cache; + static int __init page_alloc_hogger_debugfs_init(void) { + int ret; + + req_alloc_cache =3D kmem_cache_create( + "req_alloc_cache", sizeof(struct req_alloc), 0, + SLAB_HWCACHE_ALIGN, NULL); + if (!req_alloc_cache) { + pr_err("The req_alloc_cache couldn't be created\n"); + ret =3D -ENOMEM; + goto error_exit; + } + + page_alloc_cache =3D kmem_cache_create( + "page_alloc_cache", sizeof(struct page_alloc), 0, + SLAB_HWCACHE_ALIGN, NULL); + if (!page_alloc_cache) { + pr_err("The page_alloc_cache couldn't be created\n"); + ret =3D -ENOMEM; + goto clean_req_alloc_cache; + } + mmdir =3D debugfs_create_dir("mm", NULL); if (IS_ERR(mmdir)) { pr_err("Unable to create mm directory\n"); - return PTR_ERR(mmdir); + ret =3D PTR_ERR(mmdir); + goto clean_page_alloc_cache; } =20 return 0; + +clean_page_alloc_cache: + kmem_cache_destroy(page_alloc_cache); + +clean_req_alloc_cache: + kmem_cache_destroy(req_alloc_cache); + +error_exit: + return ret; } =20 static void __exit page_alloc_hogger_debugfs_exit(void) { debugfs_remove_recursive(mmdir); + kmem_cache_destroy(req_alloc_cache); + kmem_cache_destroy(page_alloc_cache); } =20 module_init(page_alloc_hogger_debugfs_init); --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (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 76AC83AB5DA for ; Thu, 6 Aug 2026 01:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978720; cv=none; b=omwhBu5/YOp1fBggSg8PoamPL8xo0CZZez9prNb3pe/wRf3FxmCAQJtdLUOhnRU7Ok9T53ZETm8xHxmEcUyz5f/djISlMIWfLmJafsPEgVaYCFxd0fDxDFQchgnkvqxfQ0toglsrMSbfpWzMTC3ciQozY0U7KLUBK6nw79AY5Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978720; c=relaxed/simple; bh=g4X1bLLZJWf+noFw4Ba/QxuDdXTsFijZGV55D7RQReE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=VdhIDMnYo8tWIefstHNLG+pZ6roXoDEHmV4A4Clyi0hxf0KWBoEtYOPZjQuObTMp2Xz8alVZWGH0vBRDKjZi52PSJw31KANBFdpLA7yPKROMt9i1F/qDaquxRyWYIUaMmXfB5jcAFT0Ka0fR/e8G5fprHA/Dgz6XCySPg8M/EYg= 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=DDhUHyPB; arc=none smtp.client-ip=209.85.215.199 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="DDhUHyPB" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cb4bd11ddf8so1707914a12.3 for ; Wed, 05 Aug 2026 18:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978719; x=1786583519; 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=76HG6LbYfiqFkSfWGWloaRFtKjCX3Ei98IA8lOxBOao=; b=DDhUHyPBcI8MRw2dcTvOmoiZtdPb1cNpvLrpQ62ODh3i769fBaWSCQR89l+9Hc1E6R 0XssGq+GSe8WDOo08phNR/ZSZ0MIfi4nxS/wzVPEoc7gjgZvd5gh3QljNNdXq3cb98g1 voYXBf7MBDgfHU45omubZuMije3Xz17V9ylzLWAALpGQJuVJPUGxDm5n/1Rfzvi6ocMi C2I7KJeBjTJbGAuuJ9BXZbp+yk1ApMoU97j+iWJYm85AtMlh5zOonNL0M4TeUi6We46W DlkjOKTFRKXEJOAslas9NypD5UT6bHBPIFQw8Ed5ntyIoZms9GmButM4SRUJvbCWVp0D 3Osg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978719; x=1786583519; 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=76HG6LbYfiqFkSfWGWloaRFtKjCX3Ei98IA8lOxBOao=; b=J8diMah1yRxiXCj8KpyMooxZieZndof6aUez3TrfoosmZ4XQ4jXbLqvNYpndcjGrH0 5A3wpTXJI9B93mvSaSqjBb7XyKD9L8I7rA+3uwZdVqqvosGUCqJ9hIU+t5fct2r4XuS4 IFot7Imigag7sipp8dbhk/g+M5wt3tYAU6Tu5aQR3u/WDg4YkazrpBhEKXNmx0mdkQ+x s/Ez/BlErj5iFnqX4h71UVxfFWd7sy6wmnZW5fxmSlzOYuh7m5+ocZohBJ6xYrtf9K3M MdebLrsN53Qm3gp3JElEjDvlXi3wl4hd6BBKQq9pRnLbpB8rdYVkbSUK79pW107yyQvL FZQQ== X-Forwarded-Encrypted: i=1; AHgh+RqdUzkF2JicprlvK6/ddHqO5V+UqiCocnNALnfyJ7n8OGOaLw0A4mf7sUIHN0VPTV6HIIcWR5mgz0t3hTA=@vger.kernel.org X-Gm-Message-State: AOJu0YzlsBqQMPF8m0Sg89Yp27gbV0y80sFzSmKrCRP2/RrvP/ZkrnOK Z9rmoRPfg3bUgfuixNEzq9yBNxwxjJroBbPbHdkEhTZlBT+GjLpbWyrfAs9cDg637YvxdV3jm/F ccDpC5IdNTQ== X-Received: from dltt12.prod.google.com ([2002:a05:701a:c96c:b0:13b:92c7:dcf7]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:7f9a:b0:3c3:875d:c538 with SMTP id adf61e73a8af0-3cb85dbce51mr12099734637.8.1785978718458; Wed, 05 Aug 2026 18:11:58 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:05 -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-5-jyescas@google.com> Subject: [RFC PATCH v2 04/16] mm: Define function to create a dir for each online node 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change creates a directory for each online node in the system. Signed-off-by: Juan Yescas --- Changes in v2: - Fix comments. - Use for_each_node_state(nid, N_MEMORY) instead. mm/page_alloc_hogger.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 175f479c487b..5765ecc43567 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -89,6 +89,7 @@ #include #include #include +#include #include #include =20 @@ -125,6 +126,26 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 +/** + * create_nodes_subdirs() - Creates a directory for each node that contains + * memory. + */ +static inline int create_nodes_subdirs(struct dentry *mmdir) +{ + struct dentry *nodedir; + int nid; + char dirname[12]; + + for_each_node_state(nid, N_MEMORY) { + snprintf(dirname, sizeof(dirname), "node-%d", nid); + nodedir =3D debugfs_create_dir(dirname, mmdir); + if (IS_ERR(nodedir)) + return PTR_ERR(nodedir); + } + + return 0; +} + static int __init page_alloc_hogger_debugfs_init(void) { int ret; @@ -154,8 +175,15 @@ static int __init page_alloc_hogger_debugfs_init(void) goto clean_page_alloc_cache; } =20 + ret =3D create_nodes_subdirs(mmdir); + if (ret) + goto clean_dir; + return 0; =20 +clean_dir: + debugfs_remove_recursive(mmdir); + clean_page_alloc_cache: kmem_cache_destroy(page_alloc_cache); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 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 934963BB693 for ; Thu, 6 Aug 2026 01:12:06 +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=1785978727; cv=none; b=KrG7GR2BO7NmFeVMFSdryghD3iX8HefhnjOzv8qNqrSuW7luGmztV1CfMv4jj3HLbCqioIYNGviluc+KfFNwUp2NFCJ2G5Z7lozhoVXY7UMXqeZxhACcz+AgoGVxcDE9/t3AJHA4L5FSNDxmwY8R+c1DFEAIT4VAkm5hrEhLLAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978727; c=relaxed/simple; bh=oA6KMU/tTZ7Iaatxo4FA4Ou6R4KKrl+H8HaLX0yIX28=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BV/ylP5dPyAl+YJBbd+SuvVftXbA8Om73bciOJVBYaLfEg5jOcu2x908+9boeZSe6wnsGcKi5VQmaK0MfNkCiM1sPZNBJaseUWlX8fZZNPSn1Fmudu7c0I+KcivWv28BWIlTAj35PFEKxy+YIeYT5n1SviXDKLRl7h9vT8s8IFg= 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=ricwGQMQ; 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="ricwGQMQ" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38ec0f510a9so3547381a91.2 for ; Wed, 05 Aug 2026 18:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978726; x=1786583526; 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=8g9EMe09F+Ayx5LYmfEKiyWcm3g2pLNQKJ+H2xPNgqI=; b=ricwGQMQ1u4fEvgeNsYHw4GDsjyEiUdDyv/VbeccH9SwlCtbut1wzdm2MqgX8c44QM EdKcPxbykJSHI+TWIWMIZMDNgQtdR1Hc8uMkwoPlHNUndjXOlSHIzmOt+oiUCGhA1KmG PmCu4OUxavCUGtRTtBn17Jwn6AiIWs70fDahyW7Uvhg9xjSHDRzOet3C2avBgHtlOzzv 7YMvSQfnJgj56/c4BBRLScZdi3+HZ2lChZCkZk6bvqMc6xLWhP9IlLlEmUf96iRD3IiI qnUVuMjrpmSEgm4nRhboBjwXGJPVaORRNiHq5NmfENC+XZDpdJxTNWJPzcbd/z3j8sTD wIDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978726; x=1786583526; 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=8g9EMe09F+Ayx5LYmfEKiyWcm3g2pLNQKJ+H2xPNgqI=; b=KdLjwomdF41fMX6H/q8qL41HInzD7BdscMcqusU9vOJihmiamuSy4ex8QpXQ5Oim4L 9jn2qHfzAeGNbdIK/RGELR6WbBWTpKaIcvpWkB3w1Vlf0HMHXASKD34m5J0kUowHfIXp leEOLc94GuRChWChMCC8jZlb+u0CKeWdSlbIjWbYxJBvib18CvBKGxqBrnpPJFmDblmJ ZEsNrZSHPi8jEN70AykwuIgZoLnx/Gysdf3IscFue551UC62NBTK2y3xFUdD8t+UzLNp RIG7tNuB20ia7yAb4DYYWXvGDkXmZL0kDiDUfNU6fZdiaT5M2G4VkeqFpFzlZIp7FarF ygxg== X-Forwarded-Encrypted: i=1; AHgh+Rqvf0olcRFeLEi+Qruoj2XlswHRqr88mtPzJr9L/7YLqaHaZSstOi6Twl2s/zSZ0JpeIXi2Yp4VuSA9NGc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+Ez8Gb2Or6KIuGCzzkE8pF2BJzvIcvUNggt3AyPCszRmW2bws Atu5wOLI5PMDW1vdXLF0LAVIFYQN76/cf419oQ5KvL4nGl+Jvtp4EI04MdTTKvxwuYWTDzYoklc yqu7SEkkzLA== X-Received: from dlah18.prod.google.com ([2002:a05:701b:2612:b0:13f:a0ee:666f]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:c88e:b0:38e:488f:7068 with SMTP id 98e67ed59e1d1-3903c5373b4mr12668555a91.2.1785978725605; Wed, 05 Aug 2026 18:12:05 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:06 -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-6-jyescas@google.com> Subject: [RFC PATCH v2 05/16] mm: Define function to create a dir for populated zone 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change creates a directory for each populated zone in the node. Note: ZONE_DEVICE pages won't be exposed in this driver due they are not managed by the Buddy Allocator. Signed-off-by: Juan Yescas --- Changes in v2: - Update comments. - Remove unused variables. mm/page_alloc_hogger.c | 46 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 5765ecc43567..e8944080e82e 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -88,6 +88,7 @@ #include #include #include +#include #include #include #include @@ -126,21 +127,62 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 + +/** + * create_zones_subdirs() - Creates a directory for each populated zone in= the + * node. + * + * Note: ZONE_DEVICE pages won't be allocated using this driver. The main = reason + * is because they are not managed by the Buddy Allocator or CMA allocator. + */ +static inline int create_zones_subdirs(struct dentry *nodedir, + struct pglist_data *pgdata) +{ + struct dentry *zonedir; + struct zone *zone; + struct zone *node_zones =3D pgdata->node_zones; + char dirname[24]; + + for (zone =3D node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { + if (!populated_zone(zone)) + continue; + + /* ZONE_DEVICE pages won't be allocated using this driver. */ + if (zone_is_zone_device(zone)) + continue; + + snprintf(dirname, sizeof(dirname), "zone-%s", zone->name); + zonedir =3D debugfs_create_dir(dirname, nodedir); + if (IS_ERR(zonedir)) + return PTR_ERR(zonedir); + } + + return 0; +} + /** * create_nodes_subdirs() - Creates a directory for each node that contains - * memory. + * memory. Once that the node directory is created, it creates a directory= for + * each zone in the node. */ static inline int create_nodes_subdirs(struct dentry *mmdir) { struct dentry *nodedir; - int nid; char dirname[12]; + int nid; + int ret; =20 for_each_node_state(nid, N_MEMORY) { + struct pglist_data *pgdata =3D NODE_DATA(nid); + snprintf(dirname, sizeof(dirname), "node-%d", nid); nodedir =3D debugfs_create_dir(dirname, mmdir); if (IS_ERR(nodedir)) return PTR_ERR(nodedir); + + ret =3D create_zones_subdirs(nodedir, pgdata); + if (ret) + return ret; } =20 return 0; --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) (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 C40083A8741 for ; Thu, 6 Aug 2026 01:12:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978735; cv=none; b=D4xamr9rTy1Tu/J874jpH36XYCe/BQMmFLvB9Zx05ajsTOkzIgZsyncKSwHk6V+d+RzF/JMPPkcNIf0TVl5wFMbPZ3WqagclOmXO5bxvqtF4QiOnglv9bt8YKQE9KAFhZf6FbvmRvtMYx8CPyoDm4Vr63FSH+nbWH+X4Z/cxF+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978735; c=relaxed/simple; bh=qgImI5oP4HyJzPd4CWrdreK296JQSWdnEnvHbKGXZdE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fb8a7ITfvTLSsbDTtU9mwaRdxH9aV2uC4md5kUHs/3P+ujtCZOl5N1rzYUobkgttTcnv/uW0qp/nom6nMYPQWO2yVJVX2r4HtCe0mCPQ8jNHSVU9mkpye0aOnd5yt07dxkhwXyJyJxwhX84FfZyE8ZSrLtPlFeRDD+8GOcSQ/Us= 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=kpd+3xTb; arc=none smtp.client-ip=209.85.216.71 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="kpd+3xTb" Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-38dbf293831so3180843a91.3 for ; Wed, 05 Aug 2026 18:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978733; x=1786583533; 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=DoxO0tzkkRxeSpf9e1eNsTCkLzdHL150fG3Ixk6g9Us=; b=kpd+3xTbyOCl93VOG1SLuxcqhiboAoQBeVFg3gq/zOajWROCDUMApLtklouHi0biQP l6Oosv8/2uzfuNJg2ENn00pH1ufiyjBP+eLGFMzfrsWEDcEsGw5YBKkA0bqNdd7SBS1d JgYYrnYDmlM1MSfQUeFLXuyDVSWumhcAypAucRelxfRppjaEjiaCDsMpahVovQDLU01R oTOUBbRnNATZUtOkiNR1lhm0ls0YkDLMLHI/++1dSbR5eYoS4a7Rdb1k4uZVT5SmlaZp /nJSQwX3u8ts6a/5UxeiY8xLjR5uavgJTHb8HKQyClPkx++TU+Mh5HwSLP3h2MBYASxh IAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978733; x=1786583533; 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=DoxO0tzkkRxeSpf9e1eNsTCkLzdHL150fG3Ixk6g9Us=; b=TOH7Gd8rkftNlvRxw9X8brIrRwsjU2K524orSKBoDaa5zhmv5ashUtivFdv5WiUKRq TnvECXxgw1oAQPjOYzdqoxPow5FB2MISLVHZsuzgt3KN1Jf6OGxrs5Mq9nl06O+pTPEK KTOLZwD5tAhnEIX+w1gBJG849fVPfiEk9JEwAqWsglwp1WLuqu/UeU9Ysssim2o333mW JUb5PC5kwCLoLvgoEonVavKvyhWgb9T5Nkcv79Ep2p/JeCvXIJMt0WznGcRuWPolcZr0 oIzyumOtsWJ2Sjbk6OFnrbI4wCj25zID6ra257LW4dVWEqBqf/SGV45pGWYUh7Jrjqt8 QZRw== X-Forwarded-Encrypted: i=1; AHgh+RpDa/qsNAfiKxYkr0b5cSJkt2lAqfFDrvsTZPFSsKmn01ylfU2lJQkUUilcj08ZvvppgCeH2sC9ZBVAPXs=@vger.kernel.org X-Gm-Message-State: AOJu0Yx3gijjhpRXaLBKOQUWa8n9ISXPSRbN/rnukFXHNPe7ix/vmCtE zPES68Jto4YR5TB2+KT4NWHgkR0Yad0vfoGS0K5cxHVjvIrXjd4dHL+OKKTdJ5BdtLGNcXcPNk6 YSvE/BgBYgQ== X-Received: from dld11.prod.google.com ([2002:a05:7022:30b:b0:13e:5fe8:61ef]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:560c:b0:38e:70d5:b12d with SMTP id 98e67ed59e1d1-3903c537991mr11924708a91.6.1785978732757; Wed, 05 Aug 2026 18:12:12 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:07 -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-7-jyescas@google.com> Subject: [RFC PATCH v2 06/16] mm: Define function to create a dir for each page order 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change creates a directory for each page order inside the zone directory. Signed-off-by: Juan Yescas --- Changes in v2: - Update comments. - Remove unused parameters in function. mm/page_alloc_hogger.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index e8944080e82e..24856f7ea5d7 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -127,10 +127,29 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 +/** + * create_page_orders_subdirs() - Creates a directory for each page order = inside + * the zone directory. + */ +static inline int create_page_orders_subdirs(struct dentry *zonedir) +{ + struct dentry *orderdir; + char dirname[12]; + + for (int order =3D 0; order < NR_PAGE_ORDERS; order++) { + snprintf(dirname, sizeof(dirname), "order-%d", order); + orderdir =3D debugfs_create_dir(dirname, zonedir); + if (IS_ERR(orderdir)) + return PTR_ERR(orderdir); + } + + return 0; +} =20 /** * create_zones_subdirs() - Creates a directory for each populated zone in= the - * node. + * node. Once that the zone directory is created, it creates a directory f= or + * each order supported. * * Note: ZONE_DEVICE pages won't be allocated using this driver. The main = reason * is because they are not managed by the Buddy Allocator or CMA allocator. @@ -142,6 +161,7 @@ static inline int create_zones_subdirs(struct dentry *n= odedir, struct zone *zone; struct zone *node_zones =3D pgdata->node_zones; char dirname[24]; + int ret; =20 for (zone =3D node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { if (!populated_zone(zone)) @@ -155,6 +175,10 @@ static inline int create_zones_subdirs(struct dentry *= nodedir, zonedir =3D debugfs_create_dir(dirname, nodedir); if (IS_ERR(zonedir)) return PTR_ERR(zonedir); + + ret =3D create_page_orders_subdirs(zonedir); + if (ret) + return ret; } =20 return 0; --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 05E503A961A for ; Thu, 6 Aug 2026 01:12:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978742; cv=none; b=at1A/BvauHHKMSsIuV3/U5skJwIuKWrQG/DKOejV57e8DoD6dSpKL8/xAxpUnqMIa4V0QH0sTn3Pad8E+UuWH/02Hzj1ihb/rF986yoaa63eci56CPO69z/vybinXHk6V8t3uriHEx4pYzrOr1vt/Zet72XmUIcZjIiRUUZrOXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978742; c=relaxed/simple; bh=1bdOVMQbrpvD1mRBZ4IzznCqPSJiHqhdCBELaFvos60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tXi6ZrWEmxsN4tuMI3ucOy7LMeAB7GNnqRG0IGq9JRBO2oMMwZsriD0Kmmx6HlcwvK8GpVA0OMzlyfub5rd5oqqP3ai9i6GfWvCm3d/Wc56Sl7L0ymUDW10fvw5Z0Ya8p5In+imHKIKk90Myckps/dMLHQfkROz4H8aYyLv7U6k= 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=GBNhhknD; arc=none smtp.client-ip=209.85.216.69 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="GBNhhknD" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38fa7b09921so2560092a91.1 for ; Wed, 05 Aug 2026 18:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978740; x=1786583540; 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=eqEP+amGkpnagux7ncXk0arDHCDCPoq+yfQcXf7Ol/Y=; b=GBNhhknDpmeDl3h+9Jj8IAIwKJxn1iwKAcYieEoTPh1Dkix0vi3uagQUzz29VXPVD5 Am7caNrfTpDe94kSiCl2GX4ekA28nvEm3JCrsD+F+Zg1vj7FvOg2K79dzVc7likt8EU4 7OT1uYRQpke2UGPmFT7T+H/j4OXgc0Wy9lOLn1ka/enVCkhyEYwrsmwz8tg/u7ua6/DK AF51Q46trqyGsLiWMJMc9yTm94+x1R56qNpDL+bfnGs3cMSNPOhrozK75tF0iD10O/zC 2S0PZIww22iAhz0Cxdqyty1b1RGAjhZ2AzwqDtZxS1OWN+1MxOU7XUTEVt5hkszb+1KP PuOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978740; x=1786583540; 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=eqEP+amGkpnagux7ncXk0arDHCDCPoq+yfQcXf7Ol/Y=; b=ejmSKY7ssujTIIGsDSIyOWXKGjjiYehqVlMrau+J3RyPgM37OCpf8xEaGhm+xteCsK pDTMk3P52+ODz+yMMBi0PeWSsMiwvvm/5UB7RtXw16hCmrlz6fvBSl4hsLx4xLjR6N9Q z9YtdyA0CeWcEpmbk3PEQuYqU3aytRPjTIFLwWsTxsoVKejWu7GYF/MqDO89yXQYlH5A 9Dtg5kKgX/quF9RyUjPLPU5adICZ/223BjWAC9ZdMEo0iuWwtRMEtseQskWlbWPqsk6U 7NUoGkUohl4AucsCqESuA++zp4svGUy/CbZplQViiortoB0aLSUPJoPqszdmExIJRRZo x/gg== X-Forwarded-Encrypted: i=1; AHgh+Rocl98hxPHSLRF1YW4E0ylsXU+KG7EkDB1Le0l1sXGF/PQ1yzyzPCrAtTAxtItMEqrdjK+VCWtXLjd+/28=@vger.kernel.org X-Gm-Message-State: AOJu0Yx//WVliBlmGwjHth0/7zr+lbs457ri7ebinoPXt8lFymUJLd5y GBENwC3gP5ucVRL4/FUYw6JfPkYXq5/XsmDg0JBC5DbsS1PEngnePpvXgnJr+h5EK2pKAs/t2UX T5DhGb+CiRw== X-Received: from dldoa1.prod.google.com ([2002:a05:701a:ca81:b0:13c:dc9f:51f2]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5244:b0:38e:9eb2:9d43 with SMTP id 98e67ed59e1d1-3903c5b685bmr10977529a91.16.1785978740061; Wed, 05 Aug 2026 18:12:20 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:08 -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-8-jyescas@google.com> Subject: [RFC PATCH v2 07/16] mm: Define function to create a dir for each migrate type 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change creates a directory for each migrate type inside the order directory. This function won't create a directory for MIGRATE_ISOLATE due they can't be allocated using the Buddy Allocator. Note: The MIGRATE_CMA directory won't be created yet. It will be supported in the future. Signed-off-by: Juan Yescas --- Changes in v2: - Update comments. - Remove unused parameters. mm/page_alloc_hogger.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 24856f7ea5d7..ab39ea300704 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -127,20 +127,54 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 +/** + * create_migrate_type_subdirs() - Creates a directory for each migrate ty= pe + * inside the order directory. + */ +static inline int create_migrate_type_subdirs(struct dentry *orderdir) +{ + struct dentry *migratedir; + char dirname[24]; + + for (int mtype =3D 0; mtype < MIGRATE_TYPES; mtype++) { +#ifdef CONFIG_CMA + if (mtype =3D=3D MIGRATE_CMA) /* CMA allocs are not supported yet*/ + continue; +#endif +#ifdef CONFIG_MEMORY_ISOLATION + if (mtype =3D=3D MIGRATE_ISOLATE) /* can't allocate from here */ + continue; +#endif + snprintf(dirname, sizeof(dirname), "migrate-%s", + migratetype_names[mtype]); + migratedir =3D debugfs_create_dir(dirname, orderdir); + if (IS_ERR(migratedir)) + return PTR_ERR(migratedir); + } + + return 0; +} + /** * create_page_orders_subdirs() - Creates a directory for each page order = inside - * the zone directory. + * the zone directory. Once that the page order directory is created, it c= reates + * a directory for each migrate type. */ static inline int create_page_orders_subdirs(struct dentry *zonedir) { struct dentry *orderdir; char dirname[12]; + int ret; =20 for (int order =3D 0; order < NR_PAGE_ORDERS; order++) { snprintf(dirname, sizeof(dirname), "order-%d", order); orderdir =3D debugfs_create_dir(dirname, zonedir); if (IS_ERR(orderdir)) return PTR_ERR(orderdir); + + ret =3D create_migrate_type_subdirs(orderdir); + if (ret) + return ret; } =20 return 0; --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (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 3998D3A9618 for ; Thu, 6 Aug 2026 01:12:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978749; cv=none; b=hDv3PxlSxZFeXfmL0HRCd1pEKk6RMkCrOyku+376HF6jbjPs6B6toDA95C7wl5hw7AUEBd87rrNV9TR9I2ru8nltLF4lvWnvvgWPHE6TdyTBoiVXYFhm4bJmm8xfz31wT5iF6PSUo5ZUKi+muOtXLT9pAaOy4CwAofOxL1JKN5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978749; c=relaxed/simple; bh=0PCr9yzfcfAgoDoeBlL3P+26GMzN+fx5C8Er7J2LoaM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=S9TwRiCYLbWueTf+f34ulF3A0rAbaHCCmRLY3BV3AWQIUdfqDBYJo5glIyapXBA6YJireD5mSk+ZWPtWGC6bFXsgeXWiSm5kw3I9NaKmaEBIEiHAtEodGXpYYGlcdBOVvKj+wRQJtf+NFTC7UDdAD7USe8eK2hJboLECDhSALKo= 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=YWEFkBlE; arc=none smtp.client-ip=209.85.216.69 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="YWEFkBlE" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3811279d51aso2637028a91.1 for ; Wed, 05 Aug 2026 18:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978747; x=1786583547; 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=8abuksqZM3TFFDeoiYatQV1rWPvHTMlTEjpMkYl7Nf8=; b=YWEFkBlEpVP1EWsEhvPk4/9yilFPY4OuqnChW9ihUyF1mE15vaNDrKTJSSv/QMVFtV hHXVtr4OrC6yAjY9+GnZFZHX03RUPKt20MS9lZZq7fNRoBfjuuhOEPnipwpj8gt4z/ih cKZbiM7yS6sCzuLLLU0tE3pVULwsw/TkMiujQelJp7hpyHit4aNNgwCR9SLEZGxVrTun 0Mnisf0T+JwiCP6c9gfmtTVbTe8TxuVVNkXe7ZEI7Jp0cdvo7NrDvxbG/i9Rk4+ESwSj cIGxDsqSc/d9bw4iOM8KirQgyfVU5dVeW7oxFQJ6QKNKRpytQP26XP2D3x3BiTYM7XLb 7nmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978747; x=1786583547; 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=8abuksqZM3TFFDeoiYatQV1rWPvHTMlTEjpMkYl7Nf8=; b=dZ+NUQwvM2bLLDUfrOgRxZ67xL0OdABXTO2ZrtDdDuN7qW04XaJeD5jal4Qwg7yXJY qROMprmJRDsOmn2xHDCoUIdrWXL7PGB5chy/mF4hh/DjxOsViH5RIc50CKjMTiId2bdI MrkhK9S02DGhKGceFVDL7xzJjd36dNmdYKLyPZazF0NeS+vT1Do1QAQ1SdyJidMqQ0mB 73QFsoiiw7bVjAh+JVQBZJEvcxNtWRx88oPJJkuQLmM70M2GnXRiOELN8nm+K9d6uuvC /xFZ5DuTdNpGmrfJ18hXoQr1+r7Co5w/mulg5kf5Fi8ZA23ZGwb/8Unheo+xMeQC79Bw 0qpA== X-Forwarded-Encrypted: i=1; AHgh+Ro9rkwZmePadZdtvu+tlQktzgcbPuE7XRGq6Uv7HhnFiXvMDyu9jzhi0wCBByw83u6c4SjG6efEFsN0bgQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxQit7NOX1D6qIG7cIVJROFe054WmXZCkNim+5Izsbi20P6xI1c gL8subM+HIcGdAbmiA6oKTMF3LZYm6UzsXZwun1hCEOdIEmc/Eny85Y0T6A0e50ORtqk3H6A2Cg Nsx9LNspKlA== X-Received: from dyz1.prod.google.com ([2002:a05:693c:4081:b0:314:2a38:b2a1]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:ec86:b0:38e:bbf1:de34 with SMTP id 98e67ed59e1d1-3903c537a12mr12089869a91.7.1785978747238; Wed, 05 Aug 2026 18:12:27 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:09 -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-9-jyescas@google.com> Subject: [RFC PATCH v2 08/16] mm: Define function that creates the "nr_pages_allocs" file 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change implements the function that creates the "nr_pages_allocs". This file will be used to make the allocations. When the user wants to make an allocation, it will write the number of allocations to this file. For example, if want to make 56 allocations of order 9 in the Node 0, Normal Zone and Migrate type Movable, we execute this command: echo 56 > /mm/node-0/zone-Normal/order-9/migrate-Movable/nr_pages_al= locs Signed-off-by: Juan Yescas --- Changes in v2: - Update file permissions to 0200. - Free req_alloc. mm/page_alloc_hogger.c | 81 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index ab39ea300704..ded3f0fc6641 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -127,14 +127,70 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 +/** + * req_page_alloc_write() - Allocates the pages on the requested node, zon= e, + * order and migrate type. Once the allocation is performed, a file is cre= ated + * to free the allocation later. + */ +static ssize_t req_page_alloc_write(struct file *file, const char __user *= ubuf, + size_t cnt, loff_t *ppos) +{ + return cnt; +} + +static const struct file_operations req_page_alloc_fops =3D { + .owner =3D THIS_MODULE, + .open =3D simple_open, + .write =3D req_page_alloc_write, +}; + +/** + * create_nr_pages_allocs_file() - Creates the file "nr_pages_allocs". + * + * The "nr_pages_allocs" file will be used to write the number of allocati= ons + * that will be performed. When the allocations are performed, a new file = for + * each allocation will be created in @migratedir. + */ +static inline int create_nr_pages_allocs_file(struct dentry *migratedir, + int nid, int zone_idx, + int order, int mtype) +{ + struct req_alloc *req; + struct dentry *nr_pages; + + req =3D kmem_cache_alloc(req_alloc_cache, GFP_KERNEL); + if (!req) { + pr_err("Failed to create nr_pages_allocs_info"); + return -ENOMEM; + } + + req->node_idx =3D nid; + req->zone_idx =3D zone_idx; + req->order =3D order; + req->migrate_type =3D mtype; + req->parentdir =3D migratedir; + + nr_pages =3D debugfs_create_file("nr_pages_allocs", 0200, migratedir, req, + &req_page_alloc_fops); + if (IS_ERR(nr_pages)) { + kmem_cache_free(req_alloc_cache, req); + return PTR_ERR(nr_pages); + } + + return 0; +} + /** * create_migrate_type_subdirs() - Creates a directory for each migrate ty= pe - * inside the order directory. + * inside the order directory. Once the migrate type directory is created,= it + * creates the "nr_pages_allocs" file. */ -static inline int create_migrate_type_subdirs(struct dentry *orderdir) +static inline int create_migrate_type_subdirs(struct dentry *orderdir, int= nid, + int zone_idx, int order) { struct dentry *migratedir; char dirname[24]; + int ret; =20 for (int mtype =3D 0; mtype < MIGRATE_TYPES; mtype++) { #ifdef CONFIG_CMA @@ -150,6 +206,11 @@ static inline int create_migrate_type_subdirs(struct d= entry *orderdir) migratedir =3D debugfs_create_dir(dirname, orderdir); if (IS_ERR(migratedir)) return PTR_ERR(migratedir); + + ret =3D create_nr_pages_allocs_file(migratedir, nid, zone_idx, + order, mtype); + if (ret) + return ret; } =20 return 0; @@ -160,7 +221,8 @@ static inline int create_migrate_type_subdirs(struct de= ntry *orderdir) * the zone directory. Once that the page order directory is created, it c= reates * a directory for each migrate type. */ -static inline int create_page_orders_subdirs(struct dentry *zonedir) +static inline int create_page_orders_subdirs(struct dentry *zonedir, int n= id, + int zone_idx) { struct dentry *orderdir; char dirname[12]; @@ -172,7 +234,8 @@ static inline int create_page_orders_subdirs(struct den= try *zonedir) if (IS_ERR(orderdir)) return PTR_ERR(orderdir); =20 - ret =3D create_migrate_type_subdirs(orderdir); + ret =3D create_migrate_type_subdirs(orderdir, nid, zone_idx, + order); if (ret) return ret; } @@ -189,15 +252,17 @@ static inline int create_page_orders_subdirs(struct d= entry *zonedir) * is because they are not managed by the Buddy Allocator or CMA allocator. */ static inline int create_zones_subdirs(struct dentry *nodedir, - struct pglist_data *pgdata) + struct pglist_data *pgdata, int nid) { struct dentry *zonedir; struct zone *zone; struct zone *node_zones =3D pgdata->node_zones; + int zone_idx; char dirname[24]; int ret; =20 - for (zone =3D node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { + for (zone =3D node_zones, zone_idx =3D 0; zone - node_zones < MAX_NR_ZONE= S; + ++zone, ++zone_idx) { if (!populated_zone(zone)) continue; =20 @@ -210,7 +275,7 @@ static inline int create_zones_subdirs(struct dentry *n= odedir, if (IS_ERR(zonedir)) return PTR_ERR(zonedir); =20 - ret =3D create_page_orders_subdirs(zonedir); + ret =3D create_page_orders_subdirs(zonedir, nid, zone_idx); if (ret) return ret; } @@ -238,7 +303,7 @@ static inline int create_nodes_subdirs(struct dentry *m= mdir) if (IS_ERR(nodedir)) return PTR_ERR(nodedir); =20 - ret =3D create_zones_subdirs(nodedir, pgdata); + ret =3D create_zones_subdirs(nodedir, pgdata, nid); if (ret) return ret; } --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.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 8DEC93A9618 for ; Thu, 6 Aug 2026 01:12:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978756; cv=none; b=CnZ1S31pFVxiv+hoqeb5Q9pcJVyXqMbgzStkxwImLAM1WfOQ+J444lRLVwnaPzjRpx6h096D6oREH1ujgkv34AgR+PNnK5F5JAXNSz4rXs5nFOojislcpO/0G+k8gWEhCi8b1DNs6i/cMVyKijo3s0qPbHDegpp4w85LYFifupI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978756; c=relaxed/simple; bh=8JO27Ri6DA3uKFxW+PXk1PVmS/7s6WvHUElM3I1QKmI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q/cSHeDSyKwqgXr+tGfVFnoXr7SmRukIY3KQVniqF5LnS0MEd8yxWuR+3n6dWC+IlyJ5aQRBuaY1I54MpRiyjbVdTGMA0UInIKUXBUf572JW7kZ6ohC8HupiljPTYknjAfqFS3WqMneCOzi7ixGB1bPNlj/SshIM75W4bkPqQyc= 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=R9ZKNrw9; arc=none smtp.client-ip=209.85.210.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="R9ZKNrw9" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-84870e7f498so1776869b3a.3 for ; Wed, 05 Aug 2026 18:12:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978755; x=1786583555; 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=TMQCLZS6DH1nuKj6XZQA4CCWO5WJygqkZvtHLpH3qzU=; b=R9ZKNrw9z9F5/aNL792SR+zsjxkK0cl3bd9T6VuVhvWHDCtd6Ak2tskYHiaC3VhXre 7O1wu8TpzSVcPkAymPio2DiuEZGXSvankeCIeo843/SK29ePLqBmggKSAE/39uI8j7Xb w7VmEV9KHa0gsFtEwGhNLc5aNv7PxfLcoh7aD9hlPrmJKmtPKqi9w1w2S2Gf1v8ZySrT f4Xo7w4GMci7BtG6lxpWzTqT5uThHcS4dD7ArGiKoGHOJ089UXwDonQf2HotE4o9Jaru ARXO+MmUvBcsOKd+znv/wS26nT0E6WuCyMbldfnH2zkndgHgDmMLnn3lZ6gZBAOa9kXC qRMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978755; x=1786583555; 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=TMQCLZS6DH1nuKj6XZQA4CCWO5WJygqkZvtHLpH3qzU=; b=Y1kRQtwqST3LdFnZnQ1Zmjwwv17sefyaOp0sACxQf75w55j1cfL9uGKT8CCoOopbph Zlgk8tRJiI/+W3Q+qKw3xm78jka0jBH0pV9GHcqD6vXFkl+NtFFVZLje0yPljogHVH1h yg+nzYZPJLpIOBKuxNCsafV6VCpk7JKsI4FmvzRNkzbgfrFjqUZ9X7AY+JJCxhjaaoix J4GgEQD/WuCKMjfVJ0Ca0sKBmYxVOop8ls+dVMlvhlccrw5pEc6AhKUTrxvCidI059hQ iJoqdGJmdztkr5IGnjbGL0/c/gGpydWpcH079Q3mD5J/PbfrU7xWHl0QNeH+geWtszb9 pQLw== X-Forwarded-Encrypted: i=1; AHgh+RpZg8eJ9NXgSozJjJiPIkEGs5qjXReReP5dm4ApLY+1r26or37z13KwBzIFf+kKWE6hQga/scNscJBCkkY=@vger.kernel.org X-Gm-Message-State: AOJu0YxOL2DR2kdKKAxt/diSbElXD2ltScWUQ8IxECtkVMJ2QKDiLa/h SfF9O+TgnioGiP2z7gDnvwkwcbZq8w3G1PNqmsnOgPCZRcNWCnzcQDGz9/9wTFmmmTZ4t4Z8Mrz vhUkccBXGXg== X-Received: from pgkg21.prod.google.com ([2002:a63:fa55:0:b0:c7f:cbe1:2d84]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2e17:b0:847:8f7c:fa10 with SMTP id d2e1a72fcca58-84f2e12d04cmr11046682b3a.35.1785978754627; Wed, 05 Aug 2026 18:12:34 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:10 -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-10-jyescas@google.com> Subject: [RFC PATCH v2 09/16] mm: Read the nr_pages_allocs value given by user 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change reads the nr_page_allocs value given by the user and validates that is an unsigned long. If the input is valid, it will allocate an array of nr_page_allocs size. This array will store the allocation ids. These allocation ids will be used to free the allocations. Signed-off-by: Juan Yescas --- Changes in v2: - Free allocs_ids. mm/page_alloc_hogger.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index ded3f0fc6641..9b1eaf3814e1 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -135,6 +135,21 @@ static struct kmem_cache *page_alloc_cache; static ssize_t req_page_alloc_write(struct file *file, const char __user *= ubuf, size_t cnt, loff_t *ppos) { + unsigned long nr_pages_allocs; + unsigned long *allocs_ids; + int ret; + + ret =3D kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs); + if (ret) + return ret; + + allocs_ids =3D kmalloc_array(nr_pages_allocs, sizeof(unsigned long), + GFP_KERNEL); + if (!allocs_ids) + return -ENOMEM; + + kfree(allocs_ids); + return cnt; } =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (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 5814E39D3D3 for ; Thu, 6 Aug 2026 01:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978763; cv=none; b=AaV4XNV30qT8oZ97uiAMcNrDV8yRV8kU57+zp3M72ZJ1SAeTbmaiSKz4IWjJuMExeBkz9IZbqF7kflBTQeuQSmR/kGgaGS5Cucm7zgrbwl+KBZvwFSBFODwU3e54hlfyvB2vlTd3erau62c+9OiTCVttt5S9kryftFAw8rpNz5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978763; c=relaxed/simple; bh=G0VTn7/E6JNtaJ++FUifo8AfjJ8iv2RRmBBnKrLozpo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=orG8r4V7pWfmx+b/bjJ4GcYnPPhcLIaBypVPKLBaqIqanNqIGGL81Ak3bSGMAETZUm9e7L7J2Q76Jn0jWk8gA/gJWLGlkWn1kUTR9IFAYAAplkWxoHfjs6DIh6sUBZBSOU3tKFPsQNBRBBtpUXNtPL5znF4mUzJbBemtwnPo0Y0= 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=UTGm3NEQ; arc=none smtp.client-ip=209.85.216.70 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="UTGm3NEQ" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-38f97b3f853so1966196a91.3 for ; Wed, 05 Aug 2026 18:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978762; x=1786583562; 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=Vmtnxr/CFlJueuSd4faqGngHGq0KEMm5ZYo1LjMLsQA=; b=UTGm3NEQhWsUAih9oCWw+6YAW/E+H0Za+IdRhhdRFgHe0gQfzuuEtwQiH4t8GTX1Iv hixqUzpgVKAMDyrdfWQW70C2LEADTGZkYyd1JXq8SE3tueWdLNe/eNkXEfGQTVjqgEf3 j3lqRDe4s7xzxXXgtwd7hkL+gfcS0daCudlq6SIQZRrTGYHcAP7QYL5PdEyI0mjFYPh2 LDbldmZgLx3M8AYrVQZu+VogtFlBw/pCc1LbP3k5dENIGLH5k3OJzwPsuYnCHrnuSQNT zgknhEREM315E8vFGiVsFylI7rVCazyOLfMYLGx/IIvMq4QmOpQvmsuZXu6iQf/iCKJh KxVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978762; x=1786583562; 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=Vmtnxr/CFlJueuSd4faqGngHGq0KEMm5ZYo1LjMLsQA=; b=YmgrkYSidIq6LEjN8fsgd+MrcPEgCMVIfA8nQ/S0AhXYYBubClqhkrwOFkSheRfjOJ S/rp6pmRTqO4eoOmiJXKM3S3qIPJwF4qH1VXperFXNKBhz6WOR8GFC8nIWyOFfq1LE6/ uBwsJX203yzWQg9wVdSyz1eek/nOknA5y3/NxaNssBbKqhnpqcq/bD6HFkDlY6ZsuQIy //jFRdkGccuCDq7sibPX/+GQ5UigQKeyr03oCPjzjD01XhQA9NTmha+QJY0uW6X2zan5 Aif8UT89Z0Xh+x0ljMuxa6THXFGoZEkHhTlQJygUzTHN5ot9G+QAVNAILKM+nf6Ww+4t Qzqg== X-Forwarded-Encrypted: i=1; AHgh+Rp3YLPAyBdrONswdOt58IheN3xaBBz9MNg2Y+yLucJU5x8dEU+Ok7E0vMUTi5wNtBLQKDk7Zbix26wbAVs=@vger.kernel.org X-Gm-Message-State: AOJu0YzKZ5XG0yJmAu/Fynu97xVeU2f2+9dr0fJzGwEXUutqHZ1higoY hD+LJ04qdYGSR5KlKMINOb0Av5XI6w7wo/Z/dbt6N0pCj0RwPPZ13yWGM1L2KcdpRe46G0HCXTa meGSmEhoZhQ== X-Received: from dybde36.prod.google.com ([2002:a05:7300:ae24:b0:311:4e0a:d4e1]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3847:b0:38e:b400:a860 with SMTP id 98e67ed59e1d1-3903c5a7285mr9799538a91.13.1785978761582; Wed, 05 Aug 2026 18:12:41 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:11 -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-11-jyescas@google.com> Subject: [RFC PATCH v2 10/16] mm: Set the selected zone in gfp_t flags 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change sets the selected zone in gfp_t flags. Signed-off-by: Juan Yescas --- Changes in v2: - Use static for the set_zone_to_alloc_from function. mm/page_alloc_hogger.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 9b1eaf3814e1..0e9ac43e9868 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -127,6 +127,34 @@ struct page_alloc { static struct kmem_cache *req_alloc_cache; static struct kmem_cache *page_alloc_cache; =20 +static inline void set_zone_to_alloc_from(int zone_idx, gfp_t *flags_ptr) +{ + switch (zone_idx) { +#ifdef CONFIG_ZONE_DMA + case ZONE_DMA: + *flags_ptr |=3D __GFP_DMA; + break; +#endif +#ifdef CONFIG_ZONE_DMA32 + case ZONE_DMA32: + *flags_ptr |=3D __GFP_DMA32; + break; +#endif +#ifdef CONFIG_HIGHMEM + case ZONE_HIGHMEM: + *flags_ptr |=3D __GFP_HIGHMEM; + break; +#endif + case ZONE_MOVABLE: + *flags_ptr |=3D __GFP_MOVABLE; + break; + case ZONE_NORMAL: + default: + *flags_ptr |=3D 0; + break; + } +} + /** * req_page_alloc_write() - Allocates the pages on the requested node, zon= e, * order and migrate type. Once the allocation is performed, a file is cre= ated @@ -135,8 +163,10 @@ static struct kmem_cache *page_alloc_cache; static ssize_t req_page_alloc_write(struct file *file, const char __user *= ubuf, size_t cnt, loff_t *ppos) { + struct req_alloc *req =3D file->private_data; unsigned long nr_pages_allocs; unsigned long *allocs_ids; + gfp_t flags =3D 0; int ret; =20 ret =3D kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs); @@ -148,6 +178,8 @@ static ssize_t req_page_alloc_write(struct file *file, = const char __user *ubuf, if (!allocs_ids) return -ENOMEM; =20 + set_zone_to_alloc_from(req->zone_idx, &flags); + kfree(allocs_ids); =20 return cnt; --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.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 CB65D3AE1A6 for ; Thu, 6 Aug 2026 01:12:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978771; cv=none; b=cUlbYkynoJ+WCWxC1pT4mKbcUYcsORtoKr+1GJAlabpAa9Cr50tE6Tp71wHOFtn8L/2M/wQhP6mxAup6ZCuLikzOXrbsT4LtZb48so5PqkVJhGVEzTfFshzZPoqJkq0BG47Hkg1XqHU4lUYGK1obGS9AQLaGzzwo2JVTz3FzRKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978771; c=relaxed/simple; bh=9Rbdn/nxBW/RacaOA/2S0AjWLk27bZqE+Y0j45NG2Dw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EPsy/ue1MaFDBAQRRTz6H7XnC6EKLFtvDKbZYAgbuyGqwLzFLFE592IJqEEz5mThzdLRFQEtF3kp4fjwMqYhEStmvQMXlqlnVuktTvb+NR0ksG41wnIjL0nl7Fv2HoZUUzoESWifOl113SCKhasHaoPi/kQS3B4AT9W9awtoVxQ= 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=iUpWqc5u; arc=none smtp.client-ip=209.85.215.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="iUpWqc5u" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cab048cdb3eso2237176a12.0 for ; Wed, 05 Aug 2026 18:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978769; x=1786583569; 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=sN8q6fisIIgd75G0Jqfk36UVrl5SrSLb7qi04o0MNbA=; b=iUpWqc5ugDDmZ7GngYz3tsYq22hL+OHY8Bo1m9LF+VZSRa9Il6bT5JIhQ5/bZRlVIl si7c38ebK3tDNhqN7hIhGv8oBCUR/y3QkkjWgpinqnn5i+efpwmznKdLltdrZ6sxMm8T bCrL+jLt4ymEyaAQ7TNqN0DOVkyWtz81C8kvMThQvPWB6nzfDkokE+vueuFZo/rUZYGg fVJZ7axgI+0g9oFDF4MHt0foKAZakN4APNvlVWGcJ1zYvdKJd/CVyI53GVytpgXpOAM8 sZIdgbaAHY27Dreco6ALaunNB1h6s9+mmJX4hcJx7MvcRC54uBaPI9IIm50qI8cslXPX 04og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978769; x=1786583569; 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=sN8q6fisIIgd75G0Jqfk36UVrl5SrSLb7qi04o0MNbA=; b=MTSDGK7Ev3KlXIa5/iIpJvVAwJbHXLT84LNu0n6bWLk9HzjfupdV0ByIlxXz4LvUgA Yvzy/c2WiYJtX++EDAzt8abWs6lVrj3Sdin20JJvj0dV5DqGGaoXvpWq69DW/m4hO77D lfuTjhSoBJAH+FKiKSp5OXSFPRCDl7+J1hyjkh8RxMSIsllZwA0ImS4hncTM9fvtPZ20 cvVmbo+noxIxW2GGUwDuN9FF9tU3fNILbuWnb6G963SdRltEeNargarK7vCgii7iGxBS hx+zA2j4rDeO/C/JLDRnyLnPDjeds5vWz1AhpttIpqEiKuAX0GYMETEUdH2zDi8XqdQS 0m0g== X-Forwarded-Encrypted: i=1; AHgh+RoostJ0TrqO4mB+/MclvcfUfQFK6dzfVBEvX3+YIYF+g9qQAAXJUhsMgMaS+JVCvlHvLMC5sK/0E8Fr1hs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+MLanqecuKkdZxc0DQYSdP8sfCb4ib12hqVcs8UTe7QJDrmSF BGeEFpZfV4hejpoShYTSrECiymtWQ6oasn9uLg0czysjbbimGF2vA6PiaoAVlnohMdrbQAkmRuP +VWcv4zoPrw== X-Received: from dlbep6.prod.google.com ([2002:a05:7022:1086:b0:13d:2ef5:67be]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a107:b0:3c3:8d86:9856 with SMTP id adf61e73a8af0-3cb85ded96dmr12416899637.14.1785978768797; Wed, 05 Aug 2026 18:12:48 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:12 -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-12-jyescas@google.com> Subject: [RFC PATCH v2 11/16] mm: Sets the migrate type in gfp_t flags 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change sets the selected migrate type in gfp_t flags. Signed-off-by: Juan Yescas --- Changes in v2: - Make sure that ZONE_MOVABLE is only used by MIGRATE_MOVABLE requests. mm/page_alloc_hogger.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 0e9ac43e9868..4b72acfbc087 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -155,6 +155,24 @@ static inline void set_zone_to_alloc_from(int zone_idx= , gfp_t *flags_ptr) } } =20 +static inline void set_migrate_type_to_alloc_from(int migrate_type, gfp_t = *flags_ptr) +{ + switch (migrate_type) { + case MIGRATE_UNMOVABLE: + *flags_ptr &=3D ~(__GFP_RECLAIMABLE | __GFP_MOVABLE); + break; + case MIGRATE_RECLAIMABLE: + *flags_ptr |=3D __GFP_RECLAIMABLE; + break; + case MIGRATE_HIGHATOMIC: + *flags_ptr |=3D __GFP_HIGH; + break; + case MIGRATE_MOVABLE: default: + *flags_ptr |=3D __GFP_MOVABLE; + break; + } +} + /** * req_page_alloc_write() - Allocates the pages on the requested node, zon= e, * order and migrate type. Once the allocation is performed, a file is cre= ated @@ -179,6 +197,7 @@ static ssize_t req_page_alloc_write(struct file *file, = const char __user *ubuf, return -ENOMEM; =20 set_zone_to_alloc_from(req->zone_idx, &flags); + set_migrate_type_to_alloc_from(req->migrate_type, &flags); =20 kfree(allocs_ids); =20 @@ -248,6 +267,9 @@ static inline int create_migrate_type_subdirs(struct de= ntry *orderdir, int nid, if (mtype =3D=3D MIGRATE_ISOLATE) /* can't allocate from here */ continue; #endif + if (zone_idx =3D=3D ZONE_MOVABLE && mtype !=3D MIGRATE_MOVABLE) + continue; + snprintf(dirname, sizeof(dirname), "migrate-%s", migratetype_names[mtype]); migratedir =3D debugfs_create_dir(dirname, orderdir); --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 7187A3BB682 for ; Thu, 6 Aug 2026 01:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978779; cv=none; b=pWxwQrOZvDq1pCR8dQMvym3Evx68FKrsAa0BjlselAhtj6SGS30tte/A4w20YqP8C6Oza1gDxIIeBuB+M9DVFKV1V9n3UYwalQFeITMhDLNXW107MYI/PDTunXlECg6hYlLUPTy5ankduDrxE5XGOpTcf7ZCzW9ef5++gXJrB3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978779; c=relaxed/simple; bh=TW8Az3zfcJFGFsisfgpEYY9q5sNJPNcDx1rQfEc6Rig=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=d4WoUCpmzZWmso6Jeqi3OMZ590hv6lDCj0EuHWzrlUJwCjhivIa1fb+KnXTcR7DqACXGbD7CFPCgxVAYNyR/7ZulX+uh2uf9/l2Urkjv3OYAy0JueU5JKRlDumvZSpi7DUs/WovyFQfFp5So836HQsXTbEglTrUZeNHBYqtuNt4= 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=sm6/owJb; arc=none smtp.client-ip=209.85.214.198 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="sm6/owJb" Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2cc88e22f92so34686095ad.1 for ; Wed, 05 Aug 2026 18:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978776; x=1786583576; 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=qT2U8sjoXnH+lrEkvLzdxmLHnjH1gE3vQbkqTT4aFL8=; b=sm6/owJbTiJ/1qDEQkhATZiHe2UGOUEmt+s6u94t+slc//eWAlF3lg0qBuIy7gi6G2 XOKJ3XuOilu/mKhG7QY3a430T4SofZcPaKhR7xR5sOPMMS9+9n8Klb126acPJ8INuY4Y WDKDr30XMgflTJyoFKIZ/Mk2Mqd13cvaN/A2wbWtV2enWbStzzUJQAhtpxbTsMdF6MmJ uDQ8E6JOo8Yi1UOY3oR+7RnIJy3d1qADOVBfRa8B96IJrnNpg/6LOyf7lRUIugvzQ2Av R7BZfmqTB4LryhDejNKYQB5IMz9m6INxfQg7+sxdw8iNEJkkLLSRLxQ0DcCDhESM3ygf ju5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978776; x=1786583576; 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=qT2U8sjoXnH+lrEkvLzdxmLHnjH1gE3vQbkqTT4aFL8=; b=ZwIVR7bpKOkUUB51vHH5R0kyXU14Np63C8PoQnnCShB6ODS32qbQ9Qus3idveD/i70 aqZV67SOop3gm9Gq4E3GpthvvH+uuBvMKmfCy2d+zXAupaZm1gOarrDnjB0WdUt2SoOi 2g1akgts1thCqc49EbwXS8Ttu5+PVa0eAWhZ4iWhx6xC1wNxCgi6uFFcAeyivT49Tqtf HpIizsVFagV1wgN7i6jfoQIbQ3ZKO0Ziut6bLVDuFNsW+eELkt+bHGN49d5oZU3g2sWv iSSPinXY1Bn2GJ3oFZ4qOWU47+t3dZeHn7NmwI3Y3GpYhmIHrTP/MPQyhDeg0WNx+47/ 07qA== X-Forwarded-Encrypted: i=1; AHgh+Rp/NSYth9HkgaDoR/Gv8lVcGUqAPpZBzCsHoPSoTBO+bL9lI+IywuKwma12Vdt3uzJY2aeKe7aSCx8e0/0=@vger.kernel.org X-Gm-Message-State: AOJu0YwrnRnIQWHO9j0OLozKeMQFAMFy5tdBEAnW02gvQ2j7/kcy5JIH T6t8i9qyELSQWZc9bySXoONNVjwO2AIY+LUftwJUm4DxtlRlsoyaNrKgzGOfkpeca4rqyf7BwXb Rx5KKz6UyTA== X-Received: from dyctg10.prod.google.com ([2002:a05:693c:3b0a:b0:311:6294:c296]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:41ce:b0:2ce:9c48:22d3 with SMTP id d9443c01a7336-2d0ca75151dmr122948145ad.11.1785978776189; Wed, 05 Aug 2026 18:12:56 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:13 -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-13-jyescas@google.com> Subject: [RFC PATCH v2 12/16] mm: Define the make_alloc() function 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The make_alloc() is the core function that performs the allocation. The tasks of this function are: - Call the Buddy allocator to make the allocation. - Store the details of the allocation in struct page_alloc. - Insert the struct page_alloc in an xarray using the allocation id as key. If something fails during the allocation, the pages and cache will be freed. Signed-off-by: Juan Yescas --- Changes in v2: - Once that page_alloc is initialized, insert it in xarray. - Use 20 characters for the file name instead of 12. - Fix use-after-free issue while releasing the pages. mm/page_alloc_hogger.c | 72 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 4b72acfbc087..e22247b7bd98 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -96,6 +96,18 @@ =20 static struct dentry *mmdir; =20 +/** + * atomic_long_t allocs_file_seq - Represents the naming sequence used for + * allocation files. + */ +static atomic_long_t allocs_file_seq =3D ATOMIC_INIT(0); + +/** + * allocs_xa - Represent the xarray that contains the actual allocations p= erform + * by this driver. + */ +static DEFINE_XARRAY(allocs_xa); + /** * struct req_alloc - Represents the requested allocation * @node_idx: The Node index to allocate from. @@ -173,6 +185,47 @@ static inline void set_migrate_type_to_alloc_from(int = migrate_type, gfp_t *flags } } =20 +static int make_alloc(struct req_alloc *req, + gfp_t flags, unsigned long *alloc_id) +{ + struct page_alloc *pa; + struct page *page; + char new_alloc_name[20]; + int ret; + + page =3D alloc_pages_node_noprof(req->node_idx, flags, req->order); + if (page) { + pa =3D kmem_cache_alloc(page_alloc_cache, GFP_KERNEL); + if (!pa) { + ret =3D -ENOMEM; + goto free_pages; + } + + *alloc_id =3D atomic_long_inc_return(&allocs_file_seq); + snprintf(new_alloc_name, sizeof(new_alloc_name), "%lu", + *alloc_id); + + pa->req_alloc =3D req; + pa->page =3D page; + + ret =3D xa_insert(&allocs_xa, *alloc_id, pa, GFP_KERNEL); + if (ret) + goto free_page_alloc; + } else { + return -ENOMEM; + } + + return 0; + +free_page_alloc: + kmem_cache_free(page_alloc_cache, pa); + +free_pages: + __free_pages(page, req->order); + + return ret; +} + /** * req_page_alloc_write() - Allocates the pages on the requested node, zon= e, * order and migrate type. Once the allocation is performed, a file is cre= ated @@ -182,10 +235,12 @@ static ssize_t req_page_alloc_write(struct file *file= , const char __user *ubuf, size_t cnt, loff_t *ppos) { struct req_alloc *req =3D file->private_data; + unsigned long alloc_id; unsigned long nr_pages_allocs; unsigned long *allocs_ids; gfp_t flags =3D 0; int ret; + int i; =20 ret =3D kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs); if (ret) @@ -199,9 +254,26 @@ static ssize_t req_page_alloc_write(struct file *file,= const char __user *ubuf, set_zone_to_alloc_from(req->zone_idx, &flags); set_migrate_type_to_alloc_from(req->migrate_type, &flags); =20 + for (i =3D 0; i < nr_pages_allocs; i++) { + ret =3D make_alloc(req, flags, &alloc_id); + if (ret) + goto free_allocs; + + allocs_ids[i] =3D alloc_id; + } + kfree(allocs_ids); =20 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. + */ + kfree(allocs_ids); + + return ret; } =20 static const struct file_operations req_page_alloc_fops =3D { --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 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 5E6A63BB69D for ; Thu, 6 Aug 2026 01:13:04 +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=1785978785; cv=none; b=k4HKNjfU/LG3EMSNlvzfEaTIJSo+29twFK/688fg8xUxTVce8dr7V5y81cYQE4ZQG7C+NZXi6/AkL44lYc22cc8O4A3YU0+qglB3GKWbTtnpuJ35z/vBufuCqOK4iHuURaTHLmnj81AMzlqhV+gpMT85jaaTCjCooIfxzGN8/zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978785; c=relaxed/simple; bh=kFF5ybhqynoFgUT5UbDhCcpxK7wDpu7an1BWImtMbhg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EYjkpIdR33jTKjxyfvpzfplXpUEVx0jc6hVYnNes/twQoNYTrzuZaVMe+KZGnITnFmrGkY6fzoccvr26o4qDvG3M1sHhtZQSxowB5BTFKweFdbHreCoIbY2C7OXFr1yKuqEA6XMWzWe4/Fqmf8NS0hU45LHnphKW5FkaSdXxlgM= 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=BViTDMjn; 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="BViTDMjn" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cbbb9c9bfc3so1000513a12.1 for ; Wed, 05 Aug 2026 18:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978784; x=1786583584; 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=w+7m+wEFnwXkxLiUbjcNNWB1I8uLbBVbpTJLAVglWe8=; b=BViTDMjnAnAucXnXbhNifD6AtsjBFmzkmfRCztH+NLc/bcsL8aqi/gyMiEhRQP6Dwi bRCnaAQZSeYuzWU7hBeZ/kDB4CgrcUO1enJckh2oSKyRgYPcWmakal3ERNjSMDAq7HFS 2T7cUJ9SV5+OuYkkNWE2ZxV0B8+WmH5XLgokL6S/J/Kt0bv/hfjbrjF9152+zsuARFs/ RU0y/3NPkEBEu3gKTZOZjNeGTG45TE+2sTlKozq+EOtSMLsenA8+9W08amnGWKEjlMNP KbRIjNOEFi20N+bABhh2MQ7ZBZzk9W0z2Zfd6Fx01cjA+vLoJuRc7dwF3GBdf/PhJFwj Y5WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978784; x=1786583584; 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=w+7m+wEFnwXkxLiUbjcNNWB1I8uLbBVbpTJLAVglWe8=; b=jXubSNMLVczMc57tvIGyAGCpr0t246eYYtXjgEglpdNyJcTuDfJ8AuP3dIJZ2O+AsJ rzuWD7YedzCWA2kdyfJubrEfHejrbfKHhhMchaHzk7XGRjZc452TedCQL2liEPww6U4V 90Mm20n2hhbyXsQqa/OemDSTyBZi+GwXQBhwZx8zWCMQjITPdB4ANI+Zm95pIk9h5xVG /jYPrIEdGrxuJTCdmhq9pa7EZ6vHGv7cyYHk5t+HpnIxwVeKw/9YwBZMQbUDLqoqNgEa xx6bFenVPowB2zLKujNA39ftGr6dLXKu09wEz2SlDTikyPU849XpK60zI5YFlHBqEz6U Wndg== X-Forwarded-Encrypted: i=1; AHgh+RrNJK1/6hftawd9cYCRreBOVgFAuZwsC4pBt+lYe7RCRlH+aqGX6Bc2EKxMYznXFoXIFHbwOHn/lLYWrEI=@vger.kernel.org X-Gm-Message-State: AOJu0YzR0RikKMXJAeogZQoJkSUZVh46w2UWDatl7NIRf+45PyNskoW0 rfi9o3xck2G2fj3ZIwks+8PrR7IuS6J3XjpTHgq700xfIpq6RZTwQXCMiLKxhri8bR8TH2rvL+d xiaWNKxlXQw== X-Received: from dyw7.prod.google.com ([2002:a05:7300:8807:b0:315:206:5a14]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:178b:b0:3c3:fb32:a004 with SMTP id adf61e73a8af0-3cb85fac065mr13957847637.34.1785978783412; Wed, 05 Aug 2026 18:13:03 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:14 -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-14-jyescas@google.com> Subject: [RFC PATCH v2 13/16] mm: Create the file associated with an allocation 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change creates the file associated with an allocation. The name of the file will be given by incrementing the atomic long "allocs_file_seq". This file will be used to free the allocation when the user requests it. The implementation will be included in a follow-up patch of this topic. Signed-off-by: Juan Yescas --- Changes in v2: - Update commit message. - Set file permissions to 0400 instead of 0644. mm/page_alloc_hogger.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index e22247b7bd98..a70c924e4172 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -185,12 +185,26 @@ static inline void set_migrate_type_to_alloc_from(int= migrate_type, gfp_t *flags } } =20 +static ssize_t page_alloc_read(struct file *file, char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + /* Which information should be print about the page or allocation? */ + return 0; +} + +static const struct file_operations page_alloc_fops =3D { + .owner =3D THIS_MODULE, + .open =3D simple_open, + .read =3D page_alloc_read, +}; + static int make_alloc(struct req_alloc *req, gfp_t flags, unsigned long *alloc_id) { struct page_alloc *pa; struct page *page; char new_alloc_name[20]; + struct dentry *new_alloc_dentry; int ret; =20 page =3D alloc_pages_node_noprof(req->node_idx, flags, req->order); @@ -205,18 +219,30 @@ static int make_alloc(struct req_alloc *req, snprintf(new_alloc_name, sizeof(new_alloc_name), "%lu", *alloc_id); =20 + new_alloc_dentry =3D debugfs_create_file( + new_alloc_name, 0400, req->parentdir, + pa, &page_alloc_fops); + if (IS_ERR(new_alloc_dentry)) { + ret =3D PTR_ERR(new_alloc_dentry); + goto free_page_alloc; + } + pa->req_alloc =3D req; pa->page =3D page; + pa->alloc_dentry =3D new_alloc_dentry; =20 ret =3D xa_insert(&allocs_xa, *alloc_id, pa, GFP_KERNEL); if (ret) - goto free_page_alloc; + goto remove_alloc_dentry; } else { return -ENOMEM; } =20 return 0; =20 +remove_alloc_dentry: + debugfs_remove(new_alloc_dentry); + free_page_alloc: kmem_cache_free(page_alloc_cache, pa); =20 --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 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-Transfer-Encoding: quoted-printable 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 =20 static struct dentry *mmdir; =20 @@ -252,6 +253,23 @@ static int make_alloc(struct req_alloc *req, return ret; } =20 +static int free_alloc_helper(unsigned long alloc_id) +{ + struct page_alloc *pa; + + pa =3D 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, zon= e, * order and migrate type. Once the allocation is performed, a file is cre= ated @@ -293,10 +311,15 @@ static ssize_t req_page_alloc_write(struct file *file= , const char __user *ubuf, return cnt; =20 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 =3D 0; j < i; j++) { + int ret2 =3D free_alloc_helper(allocs_ids[j]); + + if (ret2) + pr_err("Unable to free pages associated with file %lu", + allocs_ids[j]); + } + kfree(allocs_ids); =20 return ret; --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 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-Transfer-Encoding: quoted-printable 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 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 +#include #include #include #include @@ -331,6 +332,37 @@ static const struct file_operations req_page_alloc_fop= s =3D { .write =3D req_page_alloc_write, }; =20 +/** + * 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 =3D kstrtoul_from_user(ubuf, cnt, 10, &alloc_id); + if (ret) + return ret; + + ret =3D free_alloc_helper(alloc_id); + if (ret) + return ret; + + return cnt; +} + +static const struct file_operations free_page_alloc_fops =3D { + .owner =3D THIS_MODULE, + .write =3D 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 *m= mdir) =20 static int __init page_alloc_hogger_debugfs_init(void) { + struct dentry *free_file; int ret; =20 req_alloc_cache =3D kmem_cache_create( @@ -534,6 +567,13 @@ static int __init page_alloc_hogger_debugfs_init(void) if (ret) goto clean_dir; =20 + free_file =3D debugfs_create_file("free", 0200, mmdir, NULL, + &free_page_alloc_fops); + if (IS_ERR(free_file)) { + ret =3D PTR_ERR(free_file); + goto clean_dir; + } + return 0; =20 clean_dir: --=20 2.55.0.629.g250fe7f194-goog From nobody Sat Oct 3 03:54:24 2026 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (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 090603AA19B for ; Thu, 6 Aug 2026 01:13:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978807; cv=none; b=lm/3t2pcCZFZZlFDP73N6knal1cNdbhXOFU7kXP395Z3nmuhJKe470hcB40chxq94uLdqBNwmtJKVmOjYlOQuZtWbqpY3UCKRZ5VCaY2yU7KRCMfhq8HjZZj1Z/KMCTATn9UvI796Tk3ttPGBA3fAUiwjlHSPDlk+FmVhVOqSqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785978807; c=relaxed/simple; bh=LJ8Fq2a0b7Uz2q/1Q5JLKpw0e6hqK0VExHSWU+iq1t8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=lDebBofrIIah2cMYLlvCV707lqhzhw67i1fMNmqrLvUO91HmLm9ebBwt0ITUHSzJtdLatgc+FbljmUx5ZROPPUmXu07bwEUuxw8x1Nqd5JMexeSS9xDsHpYAbpM4zV70WMHOvzXLCEeZP38pu7vEz1BTfYniPF2U9iBO3qA6hVM= 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=Q4gZ/6Mb; arc=none smtp.client-ip=209.85.215.198 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="Q4gZ/6Mb" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c860544c077so3338564a12.3 for ; Wed, 05 Aug 2026 18:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785978805; x=1786583605; 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=3g38r6hFv2wbBj3eGxSH6q709M8ljSg38dlChPPOKHk=; b=Q4gZ/6Mba7F420meSn+rJzHdrpUbSgvbHrJ7uT/H8oG1FlG2wkBEyCu0JUl42K0wg/ LhdfXf+pTKFU+rQDVr9Le3mwtz1LpKIDLPPkbLn0hbN0uf/MpHN6i0L1RDA063oV8yH9 7mf/8sDD+UJw4KtfYuQO1C7o2nturXTs/QY67Rpl82xsX6rXYeHgz3WEcomc9jtB9CIv +f0oCr4z6ccwXtdHlJsM/mB/RyAFiRDjmJKgkqarsQFaLblKohIZ3jRCH7AC7IeVoqZH Rsa4t1EzNPXXWnzXPqNjbAS3QDW03DpMw9xUGL+GUpDiYQ4QCHZPaTeLVUPlHPSE2MBf fCmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785978805; x=1786583605; 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=3g38r6hFv2wbBj3eGxSH6q709M8ljSg38dlChPPOKHk=; b=d0xt3djAz/Yu1MtW5Z549F33DEvDfqW07ZDuFDEpe+ol6MbKBsvnzXc59Zw/Kw4NFS I4dXvppvuo2FO4FulXXtyNWlXeTwk8PLZtvXNTbWTWIhDyaq3Ir1YyzOvcKHB5NoHfCN ICpXwlwNIqNVQRxc/QEMW29cTDA0eugn69MXhcf9PGsXdYprkUSah30/Uu4rqDm5MJ9k g7WcF4XFxpxNcs74K2oUua6l5zV2J2Idk+rveLCHhtZHNme8Pit7+aqUKCUFLWKxFv8Q PAio+6Bb6wC7ICK+pzeLkSSkUIF389DKxA0tqY5QVS1tf2rgcutsRaWzFHtJCuQxTji7 4RsQ== X-Forwarded-Encrypted: i=1; AHgh+RrQYghfuE4uaBFDNlmzeuW3RlxQNEyrzkSy9dwncivlMY7oVz9m/eE8pD0iOKIcUjjKUNviXGdjey71hiM=@vger.kernel.org X-Gm-Message-State: AOJu0YxrGPLtH8svUKYbYCSfcWImpylkKUa3i5RvxtaL1Mf51cH6hCEb TaBF7j87njOeH6VdYre5QeqjpMU4faFADUu5T9SRXrVYd7jiSYi2fX8cH29mYBJEPlk8nuIZBqp MdxRc+OlK/w== X-Received: from dyx18.prod.google.com ([2002:a05:693c:8212:b0:30c:5c4a:b8b1]) (user=jyescas job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:a111:b0:3c3:64cb:9b99 with SMTP id adf61e73a8af0-3cb85dcc784mr12261790637.6.1785978805017; Wed, 05 Aug 2026 18:13:25 -0700 (PDT) Date: Wed, 5 Aug 2026 18:09:17 -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-17-jyescas@google.com> Subject: [RFC PATCH v2 16/16] mm: Release resources when the page alloc hogger module exits 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When the page alloc hogger module exits: - free all the previously allocated pages - Erase all the entries from the xarray Signed-off-by: Juan Yescas --- Changes in v2: - Refactor the exit method. - Release the page_alloc object. mm/page_alloc_hogger.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index 6a6fbb78513a..72c0505a6f5a 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -591,6 +591,12 @@ static int __init page_alloc_hogger_debugfs_init(void) =20 static void __exit page_alloc_hogger_debugfs_exit(void) { + struct page_alloc *pa; + unsigned long idx; + + xa_for_each(&allocs_xa, idx, pa) + free_alloc_helper(idx); + debugfs_remove_recursive(mmdir); kmem_cache_destroy(req_alloc_cache); kmem_cache_destroy(page_alloc_cache); --=20 2.55.0.629.g250fe7f194-goog