From nobody Wed Oct 1 20:32:42 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8CC02D0C9F for ; Wed, 1 Oct 2025 17:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341395; cv=none; b=ZdOd8svksH5GEh1LtP9va1JnzvLX4wYdheyAs4ndbZl9Bq85GA7fPgkkFUil9E7LbKJ4eKVqaUvgKK8oGLkZcfsGMWWmKNklUYlZHFDYoe6JV6nUEHLP+5hcOBhLAnyBU9Wlgod4cJuR0Y1oVBZ1RfkdNIcHuj72GKU8Z7wirCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341395; c=relaxed/simple; bh=DGHrA71q9LC2gqZCNU5YsojWnUP7S7smVpWqz558TCE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Loryi602SJ3ffqFt2n1f6pmQSpyKlKwuzc0N+LjdmwCqkqnJW/kfklWbWtykjlirQktYH17wP4O8zSwUfR6gLCmYHGU7vXFrzxJtktw/X07OxupxSFomaJVAi2zCU1i8y44iGRfnmgNn6VcXrJxIkoXt2Hb2wihwWt53jjLK50Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=JQDFI9If; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="JQDFI9If" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=aJLopUjdg6abKCdBvFBz2DgGEx0e5f4MfKDCPhNtEqM=; b=JQDFI9IfVzCldlJpfK4bDQaE2h QPZss9dMFj0eA7iTfB27+w6qVnSPeygo5lxNEtyUrgPhoiaOlidBrxoosMvgoF3FO/bI2rtzmdfip 3udzdqkBWoOX/Y+ZMYGBGH2DwwYHgA5zlhvSEtFEzfGf/cMc/tJfbtv6bWWGvimPOFA7Kz5NV5AdK CxDZx7EX7SLzc8HPsfwez15Np4eY4ZG9wPb7wVKCP1RVEyWxtzXu9Wzk+LQ25EvOl0vf/0pJ3N6tZ VP2qp4U09BusUl12XBDA1JMhjkfyIK3S8x9Gw0HLPq5bJPNkNuW6Kmjz+Kvs8Fu1PsZKx0+ejvSk8 3HZjscww==; Received: from [179.159.118.139] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v413v-002xd4-Lk; Wed, 01 Oct 2025 19:56:24 +0200 From: Mauricio Faria de Oliveira To: Michal Hocko , Vlastimil Babka , Andrew Morton Cc: Oscar Salvador , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH v2 1/5] mm/page_owner: introduce struct stack_print_ctx Date: Wed, 1 Oct 2025 14:56:07 -0300 Message-ID: <20251001175611.575861-2-mfo@igalia.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251001175611.575861-1-mfo@igalia.com> References: <20251001175611.575861-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, struct seq_file.private is used as an iterator in stack_list by stack_start|next(), for stack_print(). Create a context struct for this, in order to add another field next. No behavior change intended. P.S.: page_owner_stack_open() is expanded with separate statements for variable definition and return just in preparation for the next patch. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index c3ca21132c2c..c1a7d7afe945 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -45,6 +45,10 @@ static struct stack failure_stack; static struct stack *stack_list; static DEFINE_SPINLOCK(stack_list_lock); =20 +struct stack_print_ctx { + struct stack *stack; +}; + static bool page_owner_enabled __initdata; DEFINE_STATIC_KEY_FALSE(page_owner_inited); =20 @@ -856,6 +860,7 @@ static const struct file_operations proc_page_owner_ope= rations =3D { static void *stack_start(struct seq_file *m, loff_t *ppos) { struct stack *stack; + struct stack_print_ctx *ctx =3D m->private; =20 if (*ppos =3D=3D -1UL) return NULL; @@ -867,9 +872,9 @@ static void *stack_start(struct seq_file *m, loff_t *pp= os) * value of stack_list. */ stack =3D smp_load_acquire(&stack_list); - m->private =3D stack; + ctx->stack =3D stack; } else { - stack =3D m->private; + stack =3D ctx->stack; } =20 return stack; @@ -878,10 +883,11 @@ static void *stack_start(struct seq_file *m, loff_t *= ppos) static void *stack_next(struct seq_file *m, void *v, loff_t *ppos) { struct stack *stack =3D v; + struct stack_print_ctx *ctx =3D m->private; =20 stack =3D stack->next; *ppos =3D stack ? *ppos + 1 : -1UL; - m->private =3D stack; + ctx->stack =3D stack; =20 return stack; } @@ -926,7 +932,10 @@ static const struct seq_operations page_owner_stack_op= =3D { =20 static int page_owner_stack_open(struct inode *inode, struct file *file) { - return seq_open_private(file, &page_owner_stack_op, 0); + int ret =3D seq_open_private(file, &page_owner_stack_op, + sizeof(struct stack_print_ctx)); + + return ret; } =20 static const struct file_operations page_owner_stack_operations =3D { --=20 2.48.1 From nobody Wed Oct 1 20:32:42 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81BDE2D46D1 for ; Wed, 1 Oct 2025 17:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341400; cv=none; b=soI0VCvzN/mMZyLoBjlt1GCiB6ppTHwFSyQUCpH5FBN3Zy5YO7ulKcHmu38khuhFxxQ4hLDuUOkdVEpBS9i0pdUmJTLT0PhJr+jofga/73PZpmPmAT7DHipItaASnFj3IuaskdrXvD9Y0OnusHXscRK3RsTNxMbdThmEJZ672l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341400; c=relaxed/simple; bh=9mbyqCPUNLXPsjbK/czsQqoVyLEqgKEu2DRsdIHtI4M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MrvFi/Dn0XhQLS6wEe8O1AWAnndM+F/hJNBKF+oIIdwDe7CHgO5pqsRZluIxkB3tKQ/Ig0a2O2Yj91MKchYUepnrTBWhU1ghwDnEKKsjcsxMYQVh2TjwTc16OIEC9iwmBC4Z8GpYc2Fu1OsI0R6+fS5U2CDZ7qC4cQ6FcggAT4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=joDiFQJ/; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="joDiFQJ/" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8Yt1tx1hSW4BERbOPJZtMQAF71fcPnG6q+/M6LLWaWU=; b=joDiFQJ/fpMabMXZVaNDK8vUS1 kyoFyUPQkwqGmJ8AnV01uDW0mP9zJhCegyxoIqbcvlFQjbL3eK9ToZsGdrl/bUKzHB0sJidvkWQvR k07yWhlMGjQdCYrX3wDJMspzuxxERLLkmZhrIpUqXNnvSIaBMheFkV6jqPlt7QFByjszvqkPbRO6b 4JnVfwuXwf2Ue0Rx4faKUXDH6kg3hFRK1PCEe/RNLDJE3ZMH3bAzX0JnWDuChz2AMjnsnKFuNSsHJ P79SOeZBnJshgVzCV40ejsUqFauAyBo775lddWTbVTz8Z15JxWclrl4fkIOfEE5KPbnJUD9siWGl6 rJH11IGg==; Received: from [179.159.118.139] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v4140-002xd4-CN; Wed, 01 Oct 2025 19:56:28 +0200 From: Mauricio Faria de Oliveira To: Michal Hocko , Vlastimil Babka , Andrew Morton Cc: Oscar Salvador , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH v2 2/5] mm/page_owner: add struct stack_print_ctx.flags Date: Wed, 1 Oct 2025 14:56:08 -0300 Message-ID: <20251001175611.575861-3-mfo@igalia.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251001175611.575861-1-mfo@igalia.com> References: <20251001175611.575861-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the flags field to stack_print_ctx, and define two flags for current behavior (printing stack traces and their number of base pages). The plumbing of flags is debugfs_create_file(data) -> inode.i_private -> page_owner_stack_open() -> stack_print_ctx.flags -> stack_print(). No behavior change intended. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index c1a7d7afe945..e983ac21a4db 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -45,8 +45,12 @@ static struct stack failure_stack; static struct stack *stack_list; static DEFINE_SPINLOCK(stack_list_lock); =20 +#define STACK_PRINT_FLAG_STACK 0x1 +#define STACK_PRINT_FLAG_PAGES 0x2 + struct stack_print_ctx { struct stack *stack; + u8 flags; }; =20 static bool page_owner_enabled __initdata; @@ -901,20 +905,24 @@ static int stack_print(struct seq_file *m, void *v) unsigned long *entries; unsigned long nr_entries; struct stack_record *stack_record =3D stack->stack_record; + struct stack_print_ctx *ctx =3D m->private; =20 if (!stack->stack_record) return 0; =20 - nr_entries =3D stack_record->size; - entries =3D stack_record->entries; nr_base_pages =3D refcount_read(&stack_record->count) - 1; =20 if (nr_base_pages < 1 || nr_base_pages < page_owner_pages_threshold) return 0; =20 - for (i =3D 0; i < nr_entries; i++) - seq_printf(m, " %pS\n", (void *)entries[i]); - seq_printf(m, "nr_base_pages: %d\n\n", nr_base_pages); + if (ctx->flags & STACK_PRINT_FLAG_STACK) { + nr_entries =3D stack_record->size; + entries =3D stack_record->entries; + for (i =3D 0; i < nr_entries; i++) + seq_printf(m, " %pS\n", (void *)entries[i]); + } + if (ctx->flags & STACK_PRINT_FLAG_PAGES) + seq_printf(m, "nr_base_pages: %d\n\n", nr_base_pages); =20 return 0; } @@ -935,6 +943,13 @@ static int page_owner_stack_open(struct inode *inode, = struct file *file) int ret =3D seq_open_private(file, &page_owner_stack_op, sizeof(struct stack_print_ctx)); =20 + if (!ret) { + struct seq_file *m =3D file->private_data; + struct stack_print_ctx *ctx =3D m->private; + + ctx->flags =3D (uintptr_t) inode->i_private; + } + return ret; } =20 @@ -973,7 +988,9 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &proc_page_owner_operations); dir =3D debugfs_create_dir("page_owner_stacks", NULL); - debugfs_create_file("show_stacks", 0400, dir, NULL, + debugfs_create_file("show_stacks", 0400, dir, + (void *)(STACK_PRINT_FLAG_STACK | + STACK_PRINT_FLAG_PAGES), &page_owner_stack_operations); debugfs_create_file("count_threshold", 0600, dir, NULL, &proc_page_owner_threshold); --=20 2.48.1 From nobody Wed Oct 1 20:32:42 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 024592D47FA for ; Wed, 1 Oct 2025 17:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341403; cv=none; b=G5DJSD3QJZ6moM027HWqj+4JF8oqs+l0WdPOE15+klFOGIDsyRrezofI0vUS6HBhf2oJfGEKBtymKH7yiRk1fGgaS9wPlg+I+c5LmVkb20E6BjzQY+G9bUXUhRQW4KkDFnK8vF8BJGCigNmo8Nw4ib6FRSAkJVntDKiJfb87H5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341403; c=relaxed/simple; bh=/JbmZP+KG/WdPRvPML4GzKCOCSPnPbKC8+lVmQbRifs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jpth0HkbAi9EVUVHXpbQ0oV6CSos50LmO5snXYw3duHAHBlt2T/icGahhmq5CnxM9ISZSoB2Lcxvj8sUMzjniaks2epsVa9DMXSHGy2+07pfn7TGKfNlZfux+k882KQdod9kZE5cHqpHvYTpiad/Ur56GXayAzBSkzri8eXxVuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=dD3pr7mI; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="dD3pr7mI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=sGokdKfJ/nczLFQrrcykX4jGc1e0TlOvSMvafR6R/Tw=; b=dD3pr7mIhhMXSbQjUnGdZ4gU/a WIt+5Qj6yv0UttvV4urtza6p349IrHhOZ0v6rGXhavI/sRq8V3HJx8wUKNY6fJMwbuI141X/hvjMz GsbgA5WTysJ7NLtlWWOKgtJbNbJKOtubZkSi7b7fGGRFPsG8pLb5TYqQ3Ugkmu0Rwfpf4eJv9M65R FWEJV1Lk9Nelf7VCvLG3uIQyq34Uij81y9B86ziWh9sn7IxKL/zwZV/2H01SV0kJQ18aQ81P7d0zj xGr18N+9DMT+PGVhKD+8q7eMGAVtTXKYupAyS+1wnOi43dkyqxmnzputIA88kHicQAHQYS+OC0X0H Gqj58U6w==; Received: from [179.159.118.139] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v4144-002xd4-W0; Wed, 01 Oct 2025 19:56:33 +0200 From: Mauricio Faria de Oliveira To: Michal Hocko , Vlastimil Babka , Andrew Morton Cc: Oscar Salvador , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH v2 3/5] mm/page_owner: add debugfs file 'show_handles' Date: Wed, 1 Oct 2025 14:56:09 -0300 Message-ID: <20251001175611.575861-4-mfo@igalia.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251001175611.575861-1-mfo@igalia.com> References: <20251001175611.575861-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the flag STACK_PRINT_FLAG_HANDLE to print a stack's handle number from stackdepot, and add the file 'show_handles' to show just handles and their number of pages. This is similar to 'show_stacks', with handles instead of stack traces. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/page_owner.c b/mm/page_owner.c index e983ac21a4db..5d488fce0e3d 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -47,6 +47,7 @@ static DEFINE_SPINLOCK(stack_list_lock); =20 #define STACK_PRINT_FLAG_STACK 0x1 #define STACK_PRINT_FLAG_PAGES 0x2 +#define STACK_PRINT_FLAG_HANDLE 0x4 =20 struct stack_print_ctx { struct stack *stack; @@ -921,6 +922,8 @@ static int stack_print(struct seq_file *m, void *v) for (i =3D 0; i < nr_entries; i++) seq_printf(m, " %pS\n", (void *)entries[i]); } + if (ctx->flags & STACK_PRINT_FLAG_HANDLE) + seq_printf(m, "handle: %d\n", stack_record->handle.handle); if (ctx->flags & STACK_PRINT_FLAG_PAGES) seq_printf(m, "nr_base_pages: %d\n\n", nr_base_pages); =20 @@ -992,6 +995,10 @@ static int __init pageowner_init(void) (void *)(STACK_PRINT_FLAG_STACK | STACK_PRINT_FLAG_PAGES), &page_owner_stack_operations); + debugfs_create_file("show_handles", 0400, dir, + (void *)(STACK_PRINT_FLAG_HANDLE | + STACK_PRINT_FLAG_PAGES), + &page_owner_stack_operations); debugfs_create_file("count_threshold", 0600, dir, NULL, &proc_page_owner_threshold); =20 --=20 2.48.1 From nobody Wed Oct 1 20:32:42 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97FF92D5930 for ; Wed, 1 Oct 2025 17:56:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341408; cv=none; b=tZxcbpWhEL6UJ86Ri3itZgtu+Y4S1RJ71eKNwFRh0acwKlZlXKU5IcRvbn0w5k56UH+sgl1SBJ/kBwnRhIw4fLb3HQbJ8aocGAJC6puvLN2H2ZKZrVdqSvW0dlEzJOiwFqypP3BXUr/HluivquAI4nKfAniRY76itgRpXBmT5SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341408; c=relaxed/simple; bh=O2QhPRG5ehYwpVdSphmEdNTxp8pMZwchEjuB62NnGiY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d3w3KSPQXMuv2oHlGh6cUD4HRrkaFaCWzGaIhLUCQDIQnAN4MgY2JAdIQr8GzJpmxTFnsM3r8KAyrgLT3q6bAI28VjVlju21+z83RwPPoyQAiFvlrM5Vyuzn4KY0lK09AUpWQezaFf6mikJ0/yE3A7A5fI0IjV8qRId6RaQZ7sA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=Qf+EB3vI; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="Qf+EB3vI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=d2BHJMm4sslHyidALeIjAD23MeiVl6ZlrbLv4A2t1ZM=; b=Qf+EB3vIvufdgNxjmGXzOvYobp 89qmQvFn2SwESes+rePGkq4Zc6twetH21Kap3KonAlEcE0lfMmviZPuedwyZ+Jp6rGzOce5QxpJMP 8Jq9ORB7euMY65AZZQuVrV3H0cYq8QjHG6+y44t+ceTbzuE2KUvTkI38NZJViOzkIxm7pUPwNB3aE 6NsIBon2W35uyqWj3UFqKdgvXNNannhLwvbNGqzt8P8L6kKM18r+RiRBxt0ZGeA2EKJqFdO3MUtTo BN5eOTHoutn9Zz3GF+vV5qGXGcnhsh/Y48n/4YgoZaWrG9nqTEosA61IT3MolHld4xgt8xDWXZtuI H6D4dHig==; Received: from [179.159.118.139] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v4149-002xd4-NQ; Wed, 01 Oct 2025 19:56:38 +0200 From: Mauricio Faria de Oliveira To: Michal Hocko , Vlastimil Babka , Andrew Morton Cc: Oscar Salvador , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH v2 4/5] mm/page_owner: add debugfs file 'show_stacks_handles' Date: Wed, 1 Oct 2025 14:56:10 -0300 Message-ID: <20251001175611.575861-5-mfo@igalia.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251001175611.575861-1-mfo@igalia.com> References: <20251001175611.575861-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add the file 'show_stacks_handles' to show just stack traces and their handles, in order to resolve stack traces and handles (i.e., to identify the stack traces for handles in previous reads from 'show_handles'). All stacks/handles must show up, regardless of their number of pages, that might have become zero or no longer make 'count_threshold', but made it in previous reads from 'show_handles' -- and need to be resolved later. P.S.: now, print the extra newline independently of the number of pages. Signed-off-by: Mauricio Faria de Oliveira --- mm/page_owner.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 5d488fce0e3d..0e5c7bb3e4e8 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -913,7 +913,8 @@ static int stack_print(struct seq_file *m, void *v) =20 nr_base_pages =3D refcount_read(&stack_record->count) - 1; =20 - if (nr_base_pages < 1 || nr_base_pages < page_owner_pages_threshold) + if (ctx->flags & STACK_PRINT_FLAG_PAGES && + (nr_base_pages < 1 || nr_base_pages < page_owner_pages_threshold)) return 0; =20 if (ctx->flags & STACK_PRINT_FLAG_STACK) { @@ -925,7 +926,8 @@ static int stack_print(struct seq_file *m, void *v) if (ctx->flags & STACK_PRINT_FLAG_HANDLE) seq_printf(m, "handle: %d\n", stack_record->handle.handle); if (ctx->flags & STACK_PRINT_FLAG_PAGES) - seq_printf(m, "nr_base_pages: %d\n\n", nr_base_pages); + seq_printf(m, "nr_base_pages: %d\n", nr_base_pages); + seq_putc(m, '\n'); =20 return 0; } @@ -999,6 +1001,10 @@ static int __init pageowner_init(void) (void *)(STACK_PRINT_FLAG_HANDLE | STACK_PRINT_FLAG_PAGES), &page_owner_stack_operations); + debugfs_create_file("show_stacks_handles", 0400, dir, + (void *)(STACK_PRINT_FLAG_STACK | + STACK_PRINT_FLAG_HANDLE), + &page_owner_stack_operations); debugfs_create_file("count_threshold", 0600, dir, NULL, &proc_page_owner_threshold); =20 --=20 2.48.1 From nobody Wed Oct 1 20:32:42 2025 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77EC22D592C for ; Wed, 1 Oct 2025 17:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341411; cv=none; b=kH1Xtxm/MGpp+UdEFWm9haw4foqnYXE5OzNIliEqqgdrCK2ayFi2XUkofD/KoQr6a9fjlo6uPmRP/PHUzre7pBbxHkcEKNhC7lxhKmLqaKN/cq42qpaGFOg0fPbbyL30RkVY8VJ+sigyQ+9BaBK9t2sadfVgEhNke85RENzM004= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759341411; c=relaxed/simple; bh=T2XPE/MC4hQ1H6ThFy0YB5n4tbezjalvg27FOt+AOwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qwwh8cOF/fnv21oQr2/kkdXYEUcCZ4oYkCJfER1VooRla0dQJR7xUq8JG8MEpR3M0EuAaeufeWn+MwbxOyH5YUhIa/LW792GPDhxgWnpFAWlBliy4MAghjhyboq9hv+fAc5lBwwL9EEbj2dHHM5nWHkUDE49T4wvJV7qcNeVzBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=jo4lfrDb; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="jo4lfrDb" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=pFGrw9AJtqB09g7OZrEbnRk6JGZDUVaKcZE3piDe3Pg=; b=jo4lfrDb7Ln2/ekILrcZTwpfHy ovbXmao2JZNNpAUTrE4TW71cJIenl9mkQPyMufLmibgYOnkD4vbFyB9vgDiawMZpvJa2PzWjrmCV2 y2luluqHqYGX+pBCFLuB1omuC7KUjIdsD/L5LY8+WFYrZaah5JqcODcnIUoals4FvmMXVzb7YKY8R GB6QZAPxELiecJKph7kxb5KiONOEhiqRjcn+WQ7hNmCe7sV5vKtyfzKISls4Zz5pdKtsMdPG7Mk9K 0XCVIVJpZOdPL4PAVwW59CLEiCpWltbNqy8CA4Rl2jxgxYnxN+tI9xXXYeF7YgpM3j1s1y6kre/np vBbhq2Aw==; Received: from [179.159.118.139] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1v414E-002xd4-DL; Wed, 01 Oct 2025 19:56:43 +0200 From: Mauricio Faria de Oliveira To: Michal Hocko , Vlastimil Babka , Andrew Morton Cc: Oscar Salvador , Suren Baghdasaryan , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com Subject: [PATCH v2 5/5] mm/page_owner: update Documentation with 'show_handles' and 'show_stacks_handles' Date: Wed, 1 Oct 2025 14:56:11 -0300 Message-ID: <20251001175611.575861-6-mfo@igalia.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251001175611.575861-1-mfo@igalia.com> References: <20251001175611.575861-1-mfo@igalia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Describe and provide examples for 'show_handles' and 'show_stacks_handles'. Signed-off-by: Mauricio Faria de Oliveira --- Documentation/mm/page_owner.rst | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Documentation/mm/page_owner.rst b/Documentation/mm/page_owner.= rst index 3a45a20fc05a..6b12f3b007ec 100644 --- a/Documentation/mm/page_owner.rst +++ b/Documentation/mm/page_owner.rst @@ -27,7 +27,10 @@ enabled. Other usages are more than welcome. It can also be used to show all the stacks and their current number of allocated base pages, which gives us a quick overview of where the memory is going without the need to screen through all the pages and match the -allocation and free operation. +allocation and free operation. It's also possible to show only a numeric +identifier of all the stacks (without stack traces) and their number of +allocated base pages (faster to read and parse, eg, for monitoring) that +can be matched with stacks later (show_handles and show_stacks_handles). =20 page owner is disabled by default. So, if you'd like to use it, you need to add "page_owner=3Don" to your boot cmdline. If the kernel is built @@ -116,6 +119,33 @@ Usage nr_base_pages: 20824 ... =20 + cat /sys/kernel/debug/page_owner_stacks/show_handles > handles_7000.txt + cat handles_7000.txt + handle: 42 + nr_base_pages: 20824 + ... + + cat /sys/kernel/debug/page_owner_stacks/show_stacks_handles > stacks_hand= les.txt + cat stacks_handles.txt + post_alloc_hook+0x177/0x1a0 + get_page_from_freelist+0xd01/0xd80 + __alloc_pages+0x39e/0x7e0 + alloc_pages_mpol+0x22e/0x490 + folio_alloc+0xd5/0x110 + filemap_alloc_folio+0x78/0x230 + page_cache_ra_order+0x287/0x6f0 + filemap_get_pages+0x517/0x1160 + filemap_read+0x304/0x9f0 + xfs_file_buffered_read+0xe6/0x1d0 [xfs] + xfs_file_read_iter+0x1f0/0x380 [xfs] + __kernel_read+0x3b9/0x730 + kernel_read_file+0x309/0x4d0 + __do_sys_finit_module+0x381/0x730 + do_syscall_64+0x8d/0x150 + entry_SYSCALL_64_after_hwframe+0x62/0x6a + handle: 42 + ... + cat /sys/kernel/debug/page_owner > page_owner_full.txt ./page_owner_sort page_owner_full.txt sorted_page_owner.txt =20 --=20 2.48.1