From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-m3285.qiye.163.com (mail-m3285.qiye.163.com [220.197.32.85]) (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 0413B1A9F9B for ; Sun, 19 Apr 2026 17:11:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.32.85 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776618711; cv=none; b=lWxE+maKAVZ7qChKr2pIwYILqjC0I7EHqOIAGTvAff8NxbbCEExcMmMCe7pn8mxc90gewZK5dMw5s5FgDJAW3yemZSKZ/E0UtrZeojBJtMdL76TrFuaC4wsat8zP5rxxRWAgm02rAgBrHsmb2DkebGNxZj+sh0sisjXFYLcYuQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776618711; c=relaxed/simple; bh=0f+Er4L4jZVYe2pmte9KnA2bEYszPgPP66NG6ZyE2K8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mxB69GMcTva/Sv5jaf11RCOVMc6zOhaQYeCQhMdGoxiuHg7cHcDBoRZireHZLBKoaR27+K68IuQDunHPj3rTQATCB/r0GcfLmJpCFbxmNoFfhA6XggMtkkUkX4JiIcuKaqQoqF7MY25VXBAvTUkrdkAzNkDpuMytUJztGarOSOQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn; spf=pass smtp.mailfrom=easystack.cn; arc=none smtp.client-ip=220.197.32.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=easystack.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=easystack.cn Received: from localhost.localdomain (unknown [IPV6:2409:8a20:ef7:a5b4:8810:8f74:8c26:2]) by smtp.qiye.163.com (Hmail) with ESMTP id 1918e52ab; Sun, 19 Apr 2026 23:55:57 +0800 (GMT+08:00) From: Zhen Ni To: akpm@linux-foundation.org, vbabka@kernel.org Cc: surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Zhen Ni Subject: [PATCH v2 2/3] mm/page_owner: add print_mode filter Date: Sun, 19 Apr 2026 23:55:39 +0800 Message-Id: <20260419155540.376847-3-zhen.ni@easystack.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260419155540.376847-1-zhen.ni@easystack.cn> References: <20260419155540.376847-1-zhen.ni@easystack.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-HM-Tid: 0a9da674ada00229kunma1b4aa74234e8f X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJQjdXWS1ZQUlXWQ8JGhUIEh9ZQVkaHUwZVkJDShoeGkMYSEgfQ1YVFAkWGhdVGRETFh oSFyQUDg9ZV1kYEgtZQVlJT0tCQUMaSUtBHh1MQRpOGU9BQ0NKS0FDHUxPQUMYSU1BSVlXWRYaDx IVHRRZQVlPS0hVSktJT09PSFVKS0tVSkJLS1kG Add print_mode functionality to reduce page_owner output size by printing only the stack handle instead of the full stack trace. Example output with print_mode enabled: Page allocated via order 0, mask 0x42800(GFP_NOWAIT|__GFP_COMP), pid 1, tgid 1 (systemd), ts 349667370 ns PFN 0xa00a2 type Unmovable Block 1280 type Unmovable Flags 0x33fffe0000004124(referenced|lru|active|private|node=3|zone=0| lastcpupid=0x1ffff) handle: 17432583 Charged to memcg / Print mode significantly reduces output size while preserving all other page allocation information. The correspondence between handles and stack traces can be obtained through the show_stacks_handles interface. Link: https://lore.kernel.org/linux-mm/20260417154638.22370-3-zhen.ni@easystack.cn/ Suggested-by: Zi Yan Signed-off-by: Zhen Ni --- Changes in v2: - Renamed from 'compact mode' to 'print_mode' for better clarity - Use enum values (0=full_stack, 1=stack_handle) instead of boolean - Update debugfs filename from 'compact' to 'print_mode' --- mm/page_owner.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/mm/page_owner.c b/mm/page_owner.c index 5884d883837e..6d87b6948cfa 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -590,7 +590,13 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn, migratetype_names[pageblock_mt], &page->flags); - ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); + /* Print mode: full stack or stack handle */ + if (READ_ONCE(owner_filter.print_mode) == PAGE_OWNER_PRINT_STACK_HANDLE) { + ret += scnprintf(kbuf + ret, count - ret, + "handle: %d\n", handle); + } else { + ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0); + } if (ret >= count) goto err; @@ -985,6 +991,24 @@ static int page_owner_threshold_set(void *data, u64 val) DEFINE_SIMPLE_ATTRIBUTE(page_owner_threshold_fops, &page_owner_threshold_get, &page_owner_threshold_set, "%llu"); +static int page_owner_print_mode_get(void *data, u64 *val) +{ + *val = READ_ONCE(owner_filter.print_mode); + return 0; +} + +static int page_owner_print_mode_set(void *data, u64 val) +{ + if (val > PAGE_OWNER_PRINT_STACK_HANDLE) + return -EINVAL; + WRITE_ONCE(owner_filter.print_mode, val); + return 0; +} + +DEFINE_SIMPLE_ATTRIBUTE(page_owner_print_mode_fops, + &page_owner_print_mode_get, + &page_owner_print_mode_set, "%lld"); + static int __init pageowner_init(void) { @@ -998,6 +1022,8 @@ static int __init pageowner_init(void) debugfs_create_file("page_owner", 0400, NULL, NULL, &page_owner_fops); filter_dir = debugfs_create_dir("page_owner_filter", NULL); + debugfs_create_file("print_mode", 0600, filter_dir, NULL, + &page_owner_print_mode_fops); dir = debugfs_create_dir("page_owner_stacks", NULL); debugfs_create_file("show_stacks", 0400, dir, -- 2.20.1