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 78733302CD5 for ; Tue, 28 Apr 2026 14:16:41 +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=1777385801; cv=none; b=Hy1oz1QVuE4HhzUBtk6//eaO5uzFdbPMeB+zgcgxsRO3YpVvi5PtWgVc8ZoUGwoqThnd8xnBPVte04xFD0VCXKfTG8vHYlbNY/cYnIld6uzisyXEBX8ownGL3Js8kepvEnmYY9S5EHP/tGCLRXJiBhmzg500AlvkbSjMc6GzM8U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777385801; c=relaxed/simple; bh=UattL/at57T5QqsU15Ijo7r8+bjYkLs0PoPIsDETnyk=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=eLYQXp6POpIIssyzDgyVttKLu86ja7qZKYrt4YPQBCZEyWPcns0X7NLtDoGvGK0ofq4Q4+mYEZWWK7bLtuHChwY/IuGvdYPyZrWV90bA07Rpb/MQxaPTkZ2AGy3Rem16u/FLmEArsz2MSXlYJPd4e+WItiAT8UOVRmhG2Ts+J7s= 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=Y91yBWuL; 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="Y91yBWuL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8300AC2BCB5; Tue, 28 Apr 2026 14:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1777385800; bh=UattL/at57T5QqsU15Ijo7r8+bjYkLs0PoPIsDETnyk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Y91yBWuLlrROcgwR1CTvATWhhqa90vwmQzmigqGiL+94Xm2XlEyTabW11nUbxAsNM dJuk4dC12lxZhh9RDrcEPsGUO0Q7lTOOpsm8kNfGJO27C+8CMMIIfTiQeb63nv5N4j JF6DhqVGbIXv+3h2fKMZ1/54crN8gvbW2te4TSKg= Date: Tue, 28 Apr 2026 07:16:40 -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 v3 3/4] mm/page_owner: add NUMA node filter with nodelist support Message-Id: <20260428071640.53b6f37e3a0b2d0ce520622e@linux-foundation.org> In-Reply-To: <20260428071112.1420380-4-zhen.ni@easystack.cn> References: <20260428071112.1420380-1-zhen.ni@easystack.cn> <20260428071112.1420380-4-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 Tue, 28 Apr 2026 15:11:11 +0800 Zhen Ni 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 > > ... > > +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; > + int val; > + > + /* > + * Limit input size to handle worst-case nodelist (all nodes). > + * Worst case per node: ",NNNNN" (comma + 5-digit node number) = 6 bytes. > + * Formula: 100 bytes overhead + 6 * MAX_NUMNODES > + */ > + if (count > (100 + 6 * MAX_NUMNODES)) > + return -EINVAL; > + > + 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'; strncpy_from_user() was not useful here? > + /* Support: "-1" to clear, or nodelist format like "0", "0,2", "0-3" */ > + if (kstrtoint(kbuf, 10, &val) == 0 && val == -1) > + nodes_clear(mask); > + else if (nodelist_parse(kbuf, mask)) { > + ret = -EINVAL; > + goto out_free; > + } > + > + owner_filter.nid_mask = mask; > + ret = count; > + > +out_free: > + kfree(kbuf); > + return ret; > +}