From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 84DDD12CD8B for ; Sat, 9 May 2026 00:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778286551; cv=none; b=WroqsNsoOeok0FT/CcZcmaaBOT8gW783D+wEjekeq2zjbDwU7fOkiqqUSzU3nS9/ijfM2VJUThQe9D/6yeV6T1Xusz5MTge3nN937qUf3dFzf3v1UysC8GrMnGKszqfzWl5PClvGoZJGDTbUTJDj6p5FEqp/nQUFvhdFGQZCzCw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778286551; c=relaxed/simple; bh=zkGXVGKhc/OnhZzxUCS0Kh9AEbI5Bonc05pyUjUtSpE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lUfLrRHUk7fPiTgj9ZwGlksRy8RA87zIkL0SOvWglOBBzXwTCKvIzDlyTk8mU4QBj+XiNWr4h1ajfi8NMnJr88VmLdjbgTsDK6UJSDO7FZ3eJtIgm60dy7sachgNmE6t4bioh9BQ1M39IW0sOee/meJwRMV+xMYouitLBQqe7eo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fPJbXbpY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fPJbXbpY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA065C2BCB0; Sat, 9 May 2026 00:29:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778286551; bh=zkGXVGKhc/OnhZzxUCS0Kh9AEbI5Bonc05pyUjUtSpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fPJbXbpYAQYSCAwmqqgmXLxZlU6TDzdhxRZOEgK/ypHcmb/jfRuwBZWIq5t4Gokz7 b8gzGWla2B/ptCjddFSETIb77LWDOD4/oXEBDyhHN6ecbw0IfvRCGtwIfnriwBWDxh JoXKH770DkJSwE5DEyP3KMSBTizK+866lgrzWwdi+gT3HFz3RKGgajeH6HsAiN7341 F5C1bBaCIV3SZx0RjgnZUfqxmW8K4ZjMEPon8zUb6uVeq3cYHCJfUad6nhqXY8Zp88 ESU6RLSMkAWzwYlUIfLcjis0B0g+63qYq8cmazpzqNC9N3Z+DxFgrLqnvTnriX/5OG k/nSvpQWTdLag== From: SeongJae Park To: Zhen Ni Cc: SeongJae Park , akpm@linux-foundation.org, vbabka@kernel.org, surenb@google.com, mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 1/3] mm/page_owner: add print_mode filter Date: Fri, 8 May 2026 17:29:01 -0700 Message-ID: <20260509002902.83937-1-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260507064643.179187-2-zhen.ni@easystack.cn> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Thu, 7 May 2026 14:46:41 +0800 Zhen Ni wrote: > Add a print_mode filter to page_owner that allows users to choose between > printing full stack traces or only stack handles, significantly reducing > output size for debugging and analysis. > > The filter provides a string-based interface under > /sys/kernel/debug/page_owner_filter/: > - Reading shows the current mode with [] brackets around active option > - Writing accepts "full_stack" or "stack_handle" strings > > The default full_stack mode maintains backward compatibility with existing > usage, displaying complete stack traces for each page allocation. > > The stack_handle mode dramatically reduces log size by showing only > the handle number instead of the full stack trace. The mapping from > handles to actual stack traces can be obtained via the > show_stacks_handles interface. > > Example usage: > # echo stack_handle > /sys/kernel/debug/page_owner_filter/print_mode > # cat /sys/kernel/debug/page_owner_filter/print_mode > full_stack [stack_handle] > # cat /sys/kernel/debug/page_owner > Page allocated via order 0, migratetype Unmovable, gfp_mask 0x1100ca, > pid 1, tgid 1 (systemd), ts 123456789 ns > PFN 0x1000 type Unmovable Block 1 type Unmovable > Flags 0x3fffe800000084(referenced|lru|active|private|node=0|zone=1) > handle: 17432583 > ... > > Signed-off-by: Zhen Ni I added a few trivial comments below, but overall looks good to me. Reviewed-by: SeongJae Park > --- > > Changes in v5: > - No code changes > > Changes in v4: > - Change from numeric (0/1) to string-based interface ("full_stack"/"stack_handle") > - Merge infrastructure patch into this patch > > Changes in v3: > - No code changes > > 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' Adding links to previous revisions would be helpful. > --- > mm/page_owner.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 91 insertions(+), 2 deletions(-) > > diff --git a/mm/page_owner.c b/mm/page_owner.c > index 8178e0be557f..28766c854d02 100644 > --- a/mm/page_owner.c > +++ b/mm/page_owner.c [...] > @@ -575,7 +594,11 @@ 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); > + 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); Braces are unnecessary [2] because both branches have only one statement. [...] > +static ssize_t print_mode_write(struct file *file, > + const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + char *kbuf; > + int mode; > + int ret = count; > + > + /* > + * Limit input size. Maximum valid input is "stack_handle" (12 chars) > + * plus newline and null terminator. Use 32 bytes as a reasonable limit. > + */ > + if (count > 32) > + return -EINVAL; > + > + kbuf = kmalloc(count + 1, GFP_KERNEL); > + if (!kbuf) > + return -ENOMEM; Would it make sense to use kmalloc_objs(), or simply using a local array as Andrew suggested? [...] [1] https://docs.kernel.org/process/submitting-patches.html#commentary [2] https://docs.kernel.org/process/coding-style.html#placing-braces-and-spaces Thanks, SJ