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 5202D3AC00 for ; Fri, 8 May 2026 21:13:52 +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=1778274832; cv=none; b=ZjllAPQeR4jEMH8aNSncg5kPJj0/ybYGEa0c+LdoI0ArviLS8etpoFG7MaOEbqgtIgQOSZdWw0x0ihkRtjt62VxhWL4/TBbO4QuzeGW9jbOl2xK0MDq8Wu/7FrL9xZAQo8E9Ypi7Q6qf0cHFSehek7zVBkhmghkqTQoCMh9adVs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778274832; c=relaxed/simple; bh=k+LoqhXRgaCkxxZ37Q+HKM6NnjKl7YimWBWMstuJfkE=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=uBt2kHoK5+lpT1M9BpwfgdOsYjnEHKjg1pRSeUX1Hk+HIonz/8E5CF3Ob749Io6ZSs1sF+hUyblUZ83zCQshV6FNdphLOg4cyEzvdyNiSUtgB0SF8eYaZv/c6REk90MQeg8ZRqzBq9OwJaaPd5lUTTUxvqlqDpnYCicU8lms2sE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=1ycYUPCU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="1ycYUPCU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF9DBC2BCB0; Fri, 8 May 2026 21:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1778274832; bh=k+LoqhXRgaCkxxZ37Q+HKM6NnjKl7YimWBWMstuJfkE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=1ycYUPCUHF7AXdO+gyTeYy+0qnC9Bi84CPCc4m49leg7TM8fvXEPJ7/2LGZJGEFLm URgygYZAuF8LXlC4rlFQDauCSyPc/T5qXxM3zXBdcu96nFrLDZwImErvp8fVDY1tha K1HCAEvJkWWlBu1y0cpMSpXeI/Z0rTdLLwARASFY= Date: Fri, 8 May 2026 14:13:51 -0700 From: Andrew Morton To: Zhen Ni Cc: 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 Message-Id: <20260508141351.00cb6e81cf547ab2cff655c7@linux-foundation.org> In-Reply-To: <20260507064643.179187-2-zhen.ni@easystack.cn> References: <20260507064643.179187-1-zhen.ni@easystack.cn> <20260507064643.179187-2-zhen.ni@easystack.cn> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 > ... I like the example. But what is the user to do with `handle'? Perhaps expand this example to cover looking up that stack in /sys/kernel/debug/page_owner_stacks/show_stacks_handles? > --- a/mm/page_owner.c > +++ b/mm/page_owner.c > > ... > > +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); This is bikeshedding, but... Why kmalloc this when we know it's <= 32 bytes? A local array... > + if (!kbuf) > + return -ENOMEM; > + > + if (strncpy_from_user(kbuf, buf, count) < 0) { > + ret = -EFAULT; > + goto out_free; > + } > + kbuf[count] = '\0'; > + > + mode = sysfs_match_string(page_owner_print_mode_strings, kbuf); > + if (mode < 0) { > + ret = -EINVAL; > + goto out_free; > + } > + > + WRITE_ONCE(owner_filter.print_mode, mode); > + > +out_free: > + kfree(kbuf); > + return ret; > +} print_mode_write() seems a lot of work to get a simple string from userspace! > > ... >