From mboxrd@z Thu Jan 1 00:00:00 1970 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-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_allocs 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; +/** + * req_page_alloc_write() - Allocates the pages on the requested node, zone, + * order and migrate type. Once the allocation is performed, a file is created + * 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 = { + .owner = THIS_MODULE, + .open = simple_open, + .write = 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 allocations + * 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 = kmem_cache_alloc(req_alloc_cache, GFP_KERNEL); + if (!req) { + pr_err("Failed to create nr_pages_allocs_info"); + return -ENOMEM; + } + + req->node_idx = nid; + req->zone_idx = zone_idx; + req->order = order; + req->migrate_type = mtype; + req->parentdir = migratedir; + + nr_pages = 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 type - * 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; for (int mtype = 0; mtype < MIGRATE_TYPES; mtype++) { #ifdef CONFIG_CMA @@ -150,6 +206,11 @@ static inline int create_migrate_type_subdirs(struct dentry *orderdir) migratedir = debugfs_create_dir(dirname, orderdir); if (IS_ERR(migratedir)) return PTR_ERR(migratedir); + + ret = create_nr_pages_allocs_file(migratedir, nid, zone_idx, + order, mtype); + if (ret) + return ret; } return 0; @@ -160,7 +221,8 @@ static inline int create_migrate_type_subdirs(struct dentry *orderdir) * the zone directory. Once that the page order directory is created, it creates * 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 nid, + int zone_idx) { struct dentry *orderdir; char dirname[12]; @@ -172,7 +234,8 @@ static inline int create_page_orders_subdirs(struct dentry *zonedir) if (IS_ERR(orderdir)) return PTR_ERR(orderdir); - ret = create_migrate_type_subdirs(orderdir); + ret = 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 dentry *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 = pgdata->node_zones; + int zone_idx; char dirname[24]; int ret; - for (zone = node_zones; zone - node_zones < MAX_NR_ZONES; ++zone) { + for (zone = node_zones, zone_idx = 0; zone - node_zones < MAX_NR_ZONES; + ++zone, ++zone_idx) { if (!populated_zone(zone)) continue; @@ -210,7 +275,7 @@ static inline int create_zones_subdirs(struct dentry *nodedir, if (IS_ERR(zonedir)) return PTR_ERR(zonedir); - ret = create_page_orders_subdirs(zonedir); + ret = create_page_orders_subdirs(zonedir, nid, zone_idx); if (ret) return ret; } @@ -238,7 +303,7 @@ static inline int create_nodes_subdirs(struct dentry *mmdir) if (IS_ERR(nodedir)) return PTR_ERR(nodedir); - ret = create_zones_subdirs(nodedir, pgdata); + ret = create_zones_subdirs(nodedir, pgdata, nid); if (ret) return ret; } -- 2.55.0.629.g250fe7f194-goog