public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Zhen Ni <zhen.ni@easystack.cn>
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 v2 3/3] mm/page_owner: add NUMA node filter with nodelist support
Date: Fri, 24 Apr 2026 04:26:41 -0700	[thread overview]
Message-ID: <20260424042641.b2fbe039ffef2935326077ee@linux-foundation.org> (raw)
In-Reply-To: <20260419155540.376847-4-zhen.ni@easystack.cn>

On Sun, 19 Apr 2026 23:55:40 +0800 Zhen Ni <zhen.ni@easystack.cn> wrote:

> Add NUMA node filtering functionality to page_owner to allow
> filtering pages by specific NUMA node(s) using nodelist format.
> 
> The filter allows users to focus on pages from specific NUMA nodes,
> which is useful for NUMA-aware memory allocation analysis and debugging.
> 
> Supported input formats:
> - Single node: echo "2" > nid
> - Multiple nodes: echo "0,2,3" > nid
> - Node range: echo "0-3" > nid
> - Mixed format: echo "0,2-4,7" > nid
> - Disable filter: echo "-1" > nid
> 
> ...
>
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -707,6 +707,7 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>  		 * user through copy_to_user() or GFP_KERNEL allocations.
>  		 */
>  		struct page_owner page_owner_tmp;
> +		nodemask_t mask;
>  
>  		/*
>  		 * If the new page is in a new MAX_ORDER_NR_PAGES area,
> @@ -730,6 +731,15 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>  		if (unlikely(!page_ext))
>  			continue;
>  
> +		/* NUMA node filter using bitmask */
> +		mask = READ_ONCE(owner_filter.nid_mask);
> +		if (!nodes_empty(mask)) {
> +			int nid = page_to_nid(page);
> +
> +			if (!node_isset(nid, mask))
> +				goto ext_put_continue;
> +		}
> +
>  		/*
>  		 * Some pages could be missed by concurrent allocation or free,
>  		 * because we don't hold the zone lock.
> @@ -1009,6 +1019,70 @@ DEFINE_SIMPLE_ATTRIBUTE(page_owner_print_mode_fops,
>  			&page_owner_print_mode_get,
>  			&page_owner_print_mode_set, "%lld");
>  
> +static ssize_t nid_filter_write(struct file *file,
> +				 const char __user *buf,
> +				 size_t count, loff_t *ppos)
> +{
> +	char *kbuf;
> +	nodemask_t mask;
> +	int ret;
> +
> +	/* Limit input size to handle worst-case nodelist (all nodes) */
> +	if (count > (100 + 6 * MAX_NUMNODES))
> +		return -EINVAL;

I'm wondering how that expression was arrived at ;) Perhaps a little
comment explaining?  Or can we simply use strnlen_user() here?

> +	kbuf = kmalloc(count + 1, GFP_KERNEL);
> +	if (!kbuf)
> +		return -ENOMEM;
> +
> +	if (copy_from_user(kbuf, buf, count)) {
> +		ret = -EFAULT;
> +		goto out_free;
> +	}
> +	kbuf[count] = '\0';

Can we use strncpy_from_user() here?

In fact I thought that we had a strdup_from_user() thing which does the
kmalloc also, but maybe I dreamed it.

And memdup_user_nul() could perhaps be used in here.

Nothing really fits.  We need a

	char *strdup_user(const void __user *src);

(Probably it's OK to assume GFP_KERNEL)
(Maybe needs a size_t max_len arg)

> +	/* Support: "-1" to clear, or nodelist format like "0", "0,2", "0-3" */
> +	if (strcmp(kbuf, "-1\n") == 0 || strcmp(kbuf, "-1") == 0)

Maybe

	if (kstrtoll(kbuf) == -1)

(we have lots of goodies in /lib!)




  reply	other threads:[~2026-04-24 11:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 15:55 [PATCH v2 0/3] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Zhen Ni
2026-04-19 15:55 ` [PATCH v2 1/3] mm/page_owner: add filter infrastructure Zhen Ni
2026-04-27 15:35   ` Zi Yan
2026-04-28  3:33     ` zhen.ni
2026-04-28 13:13       ` Zi Yan
2026-04-29  1:39         ` SeongJae Park
2026-04-29 11:22         ` zhen.ni
2026-04-29 11:28           ` Zi Yan
2026-04-19 15:55 ` [PATCH v2 2/3] mm/page_owner: add print_mode filter Zhen Ni
2026-04-27 15:43   ` Zi Yan
2026-04-28  3:36     ` zhen.ni
2026-04-28 13:20       ` Zi Yan
2026-04-29 11:42         ` zhen.ni
2026-04-19 15:55 ` [PATCH v2 3/3] mm/page_owner: add NUMA node filter with nodelist support Zhen Ni
2026-04-24 11:26   ` Andrew Morton [this message]
2026-04-24 20:15   ` Andrew Morton
2026-04-24 11:27 ` [PATCH v2 0/3] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Andrew Morton
2026-04-24 14:09 ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260424042641.b2fbe039ffef2935326077ee@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=zhen.ni@easystack.cn \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox