From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 725CEC44529 for ; Mon, 20 Jul 2026 19:35:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BD29E6B0095; Mon, 20 Jul 2026 15:34:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BA9BB6B0096; Mon, 20 Jul 2026 15:34:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4B9C6B0098; Mon, 20 Jul 2026 15:34:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 416156B0095 for ; Mon, 20 Jul 2026 15:34:52 -0400 (EDT) Received: from smtpin19.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A4019A0864 for ; Mon, 20 Jul 2026 19:34:51 +0000 (UTC) X-FDA: 85010157582.19.2C3C57D Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf05.hostedemail.com (Postfix) with ESMTP id E02C2100008 for ; Mon, 20 Jul 2026 19:34:49 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=HkoLmw7Q; spf=pass (imf05.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.180 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1784576089; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=M3kct1v+57CVZWjeLlS7sPI2XQHwAFOrYnO6UcPWFI4=; b=jUi9J43stGcn9w6XmXlKdzRn6ZmnxdlbMapzkLOOwl1z8NBCVlZ3GtzNVRBA97ebjWXCgZ rj/ESW7BB29QVRkLkrbpQ1RLHRh51uwWCe0lWn1bzO4LHMrLCVoUR7SHG7WSvcAA2ASDaS aVYIHGAMJOw+skuMS/qn21O+GOssvXU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=HkoLmw7Q; spf=pass (imf05.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.180 as permitted sender) smtp.mailfrom=gourry@gourry.net; dmarc=none ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1784576089; b=LO20m5/fTybNkhABsVLW+jhtIGy6TZkZPbKonK+p9I2kkHFNyMrnL6RUHh1bAzUz8VtOBc 9VXnH96poUMNs/LzKWpSEqnaUHGL1UWl+orI4IZ/gY72MmoAnwmgdUlVSpXRhSnkOOUT9f cmKZ8JylemJB2F3MyhftIKDnyloHDIE= Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-930c0f9c1b1so259079985a.1 for ; Mon, 20 Jul 2026 12:34:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1784576089; x=1785180889; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=M3kct1v+57CVZWjeLlS7sPI2XQHwAFOrYnO6UcPWFI4=; b=HkoLmw7QvMrufWogIECU+4j1mznKHIEhIaTPAmQ5cMeKdNktOsWq+9m3/YE+vS1Ruh 8Zq3MmeD5+mJ2AED41NE07ahA+F00Sk2eYVkl61muFMBpzzxLmqw5tKE+tmNiPoHL0AO e+ViENyPjeglX7o5P5X0zRp0klkEIkNRKGELQbx1uC4CtzkM0n+DOZ4PYINVSjXRsTqv nyqJCFIGY1FBjEaO0u4/7b1iBhMziSJxElToihAc+qd7yZ5W6FhPLY4YoN2ZmrIogBZo rstxW6grglUIVEE0N2uAs89tT1HrMbBGPbgOAUwD5TPGiwqGh7dDhTNR+WNX9TxKhoDu bzgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784576089; x=1785180889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=M3kct1v+57CVZWjeLlS7sPI2XQHwAFOrYnO6UcPWFI4=; b=PqKv7LaTs0BmOtAs4R6qvTCNwcd+wYq+hw7L6IFiWlV+3J2SfHq0JrzalPJrx0qsId GgFhMjNBSC9yaKOzglpb+ar6KtMmUIye+t+PHe0Q93EezcT0yqpMXrUqJSA9Hd7c3+Y1 KRGChCIwyZ2VZl9SKhoCpKZZTEoF4t13zqjXb1589r229a3RdG/CqCdmy1QklZxXslo/ rTp/Wy6huXLn8sMtjAeawnd30mXfege+4lAQuVbcuCwL+a3QlfGqTBoY+ddoKoppfNvM fPuezrrOF9kBksH7TdONU4A/RfEmOwwudwfFrq2GgvWQyxjNOnN0DYZUvvzZYDxF+8UP yAlg== X-Gm-Message-State: AOJu0YyVQNENn1+LUbEi/ugN+Vw8SYdOrj0KiadbExoISt1lsSS8TFtt 8Z5pUQj/VTF9meMzcG7Dxiol+LC7FhjGFu9MOOmI3bWVBPvJF5CgtRPsEE3H+BcRMiz7/zxNGZP oq5UR X-Gm-Gg: AfdE7cnSaFSzkqkxZcQccy6aM8TLGSdU44MeEfEYDMTslMXvaBxgO76GIHkhWZuLUkC m1YPJJDh7N+ZMyP2aMnL8clSx/MwgJtMW28+fhqCxgsUCI2jU6lBWdurMJbGLugoEZNDIjI9R9q 68Q4wQs6OwS8xyjCzCm/ZP2WsNGbLTWCJYWO6/96zyFMZZ9gv+G4DGhxSQJuyV3Ig23u5AXyekX Y5eCJfP+PGDuofJxfmqD5ubYWjLjmpYIVntYQEYecBAwJL1HpAGMtKeoJBaJbDzs5HXy40OgvqO Baja2nLYvYkiaVgHr8kyP7X1oo3wqWFuGtQztHteRW4S/KngCQ2g6pA6za/Owfv4a9TOkSssB/Z l0yCmlTcbxiMFDbfssKWtTTaD/BQWsIuXmc0InvrCRfDUboPo5KhUZRvxz5auxKQET2yT4mrkeN HqbUN+l9P9DNO6bor9LvoVKrZZ+fy/SbqJfxo/j4YNqpxVYXynlSpbP1prYekK3NNC8brMH5mYF Q== X-Received: by 2002:a05:620a:690c:b0:930:9c0c:657 with SMTP id af79cd13be357-930b41e29c5mr1450539485a.60.1784576089026; Mon, 20 Jul 2026 12:34:49 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-60-52.washdc.fios.verizon.net. [173.79.60.52]) by smtp.gmail.com with ESMTPSA id af79cd13be357-930b545e47bsm957792285a.35.2026.07.20.12.34.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 12:34:48 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: Zhigang.Luo@amd.com, arun.george@samsung.com, balbirs@nvidia.com, brendan.jackman@linux.dev, yuzenghui@huawei.com, apopple@nvidia.com, alucerop@amd.com, matthew.brost@intel.com, akpm@linux-foundation.org, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, corbet@lwn.net, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, alison.schofield@intel.com, osandov@osandov.com, jannh@google.com, pfalcato@suse.de, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, pbonzini@redhat.com, osalvador@suse.de, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, kasong@tencent.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk, longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org, mkoutny@suse.com, sj@kernel.org, jgg@ziepe.ca, jhubbard@nvidia.com, peterx@redhat.com, baolin.wang@linux.alibaba.com, npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com, lance.yang@linux.dev, usama.arif@linux.dev, xu.xin16@zte.com.cn, chengming.zhou@linux.dev, roman.gushchin@linux.dev, muchun.song@linux.dev, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, driver-core@lists.linux.dev, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-debuggers@vger.kernel.org, linux-fsdevel@vger.kernel.org, kvm@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-kselftest@vger.kernel.org, kernel-team@meta.com Subject: [PATCH v5 04/36] numa: introduce N_MEMORY_PRIVATE Date: Mon, 20 Jul 2026 15:33:58 -0400 Message-ID: <20260720193431.3841992-5-gourry@gourry.net> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260720193431.3841992-1-gourry@gourry.net> References: <20260720193431.3841992-1-gourry@gourry.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E02C2100008 X-Rspam-User: X-Stat-Signature: djsd5ge4ugqmu9ki9sq9oe633ajnmy35 X-Rspamd-Server: rspam04 X-HE-Tag: 1784576089-790356 X-HE-Meta: U2FsdGVkX18QIPS9SEpAUBIDtzxdBNss0Guinzz5A6FGqAAjEdkDyLWQevu9Mca9AaitM/Rt6Vj3DQftOjoxNk7SvBSLKrJAEydpd2SMa0HyiRv98Kv3v4UWM5I6gpneLNLGCLFdj4XNONFc0/e/nZqafv1knTmVG7BCZ+hE2Qwq0rs7oe+XJ3RRYkwwhw0lBhcceXEtU/OMwoy/W1uD2d9ZuT2GtvBO7joI0comzdYzKp2/TL/thzgETxRTpisgTIsn5y16Vc5JUCywOdwrQG5+kTXcfTz3OAsUn9wLQlLE187HeMXxYk8LFzorkoIM/YbrMmFtoQFjpF+cophP0U7NmMmmDxOEVwyBm+zFQQbFhm17vwt8l2D46ae7RKW23WNcKtIG6rNsKsCnmWHMx/7QfvwL/wI+p172ik0gGydnPlKHGAiC6t9NhsUgXcFRKW4t1xpTxLzF5bOdsFH0Y+FtLaN1k61JU4ubQuaEwMtOsQ+w6Q8IZE6US6RXEm82JNH5ybiPD3urcRcDJQMHv4BwnF0SrfN1NeoYKvUKl+r1mGw5+/oy/EAyCOulkepKLKlxC7DrffiK2XWmQYRj12Ew3WDz+H5nkFUyC5HG4I6xuBEytgq7Y2GjzaqZKkS2CQ4j1icEP8pEycv8Mr7TLMLn0aQrKQS9INGU52fZJjObvMAfh1ytYg59nuYcFnHohWKJbOzYnDQM4SZqFWId8VZREhGQ8WsaaUYV3bBWWLl2P9ceHuogtIQ7NODArRA/WMw9KemDRfibmwSN4vcB5rTjNZyTZYhPZ3mNS1ATfyAkm3iEWgsumhj2+dEcYJRS2HZ7p76F/0B1dudrr9GE20SZJrL4OC73HJav9eJSQikOGmktBtWijRTVcr4X/9g5HrG/WSsoaO0wM/8xB7i1grB8/f3QGHBC04Vzcm760XD8ZZt8csSPkqvkmawc2bDhKaB6ZPqS4Buk5DXcSNm 2SikwmK/ ECw8nizn0Be5f0esYwof83dSmuZMpSmT/8ZNEbSCFn2DijwZ40ltjSne/8dGK8D3lBInX2Oevr0OAl9NqfTnP182oz4wSEpqHeHQuEmUEPAPpPQ7SgISAo8vKrgkohlLbhjScgBLkjrtAzcFYbTt47zIuU6SQN5lB4kDJWvz7V4c+gLa237K82qdhEbOTbUGS6fI4uGD0+fA2moN6IDWdO8RYh9fP19JP+uTvXnJkS3mVaBSCk4RhrbOHCyQ39hlECdv9glndMGs8KqExuEVK5Tf0s3cAzD3Lup3ONKzKxJHVO83kykHuieeA35uyDxILoYa9Gdn55O48Ee9190CDC+Rz7LDIVlwMVDatlTNterEZAMF+18TDUeUahWUxZ+HYtuDoRa/Ppri3WUA7TT3eDAE/CwxhPu/Hzj8IfGAlydS4Osw83BGuTqJxHlqj6oheoQCVevGD6AdeohdRXJL+S50ncqhtynFDjGbSathsWvWDX4M= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Some devices want to hotplug their memory onto a node, but not have it exposed as "general purpose". The intent is to re-use portions of mm/ services for management without exposing it for general consumption. N_MEMORY nodes are intended to contain general System RAM, so they are unsuited for this purpose. Create N_MEMORY_PRIVATE for memory nodes whose memory is not intended for general consumption. N_MEMORY and N_MEMORY_PRIVATE are mutually exclusive states. This commit adds basic infrastructure for N_MEMORY_PRIVATE nodes: - struct node_private: Per-node container stored in NODE_DATA(nid) storing the owner. - folio/page_is_private_node(): true if it resides on a private node - folio/page_is_private_managed(): common predicate for checking private node or zone device Used to combine common filtering locations. - Registration API: node_private_register()/unregister() - sysfs attribute exposing N_MEMORY_PRIVATE node state. - fix node_state() and helpers to return false for N_MEMORY_PRIVATE when !CONFIG_NUMA (mutually exclusive w/ N_MEMORY) Signed-off-by: Gregory Price --- Documentation/ABI/stable/sysfs-devices-node | 10 ++ drivers/base/node.c | 113 ++++++++++++++++++++ include/linux/mmzone.h | 15 +++ include/linux/node_private.h | 82 ++++++++++++++ include/linux/nodemask.h | 7 +- mm/internal.h | 12 +++ 6 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 include/linux/node_private.h diff --git a/Documentation/ABI/stable/sysfs-devices-node b/Documentation/ABI/stable/sysfs-devices-node index 2d0e023f22a71..8a36fbc3d4028 100644 --- a/Documentation/ABI/stable/sysfs-devices-node +++ b/Documentation/ABI/stable/sysfs-devices-node @@ -29,6 +29,16 @@ Description: Nodes that have regular or high memory. Depends on CONFIG_HIGHMEM. +What: /sys/devices/system/node/has_private_memory +Contact: Linux Memory Management list +Description: + Nodes that have private (N_MEMORY_PRIVATE) memory: memory + hotplugged by a driver onto a CPU-less node and isolated from + the page allocator's normal and fallback zonelists. A node is + listed here for as long as it holds private memory; it is never + listed in has_memory at the same time (the two states are + mutually exclusive). See Documentation/mm/numa_private_nodes.rst. + What: /sys/devices/system/node/nodeX Date: October 2002 Contact: Linux Memory Management list diff --git a/drivers/base/node.c b/drivers/base/node.c index 3da91929ad4e3..94cd51f51b7e8 100644 --- a/drivers/base/node.c +++ b/drivers/base/node.c @@ -22,6 +22,7 @@ #include #include #include +#include static const struct bus_type node_subsys = { .name = "node", @@ -868,6 +869,116 @@ void register_memory_blocks_under_node_hotplug(int nid, unsigned long start_pfn, (void *)&nid, register_mem_block_under_node_hotplug); return; } + +static DEFINE_MUTEX(node_private_lock); + +/** + * node_private_register - Register a private node + * @nid: Node identifier + * @np: The node_private structure (driver-allocated, driver-owned) + * + * Register an owner for a private node. If an owner is already registered + * (different np), return -EBUSY. + * + * Re-registration with the same np is allowed. + * + * The caller owns the node_private memory and must ensure it remains valid + * until after node_private_unregister() returns. + * + * Returns 0 on success, negative errno on failure. + */ +int node_private_register(int nid, struct node_private *np) +{ + struct node_private *existing; + pg_data_t *pgdat; + int ret = 0; + + if (!np || !node_possible(nid)) + return -EINVAL; + + mutex_lock(&node_private_lock); + mem_hotplug_begin(); + + /* N_MEMORY_PRIVATE and N_MEMORY are mutually exclusive */ + if (node_state(nid, N_MEMORY)) { + ret = -EBUSY; + goto out; + } + + pgdat = NODE_DATA(nid); + existing = rcu_dereference_protected(pgdat->node_private, + lockdep_is_held(&node_private_lock)); + + /* If it exists, restrict to single owner */ + if (existing) { + if (existing != np) + ret = -EBUSY; + goto out; + } + + rcu_assign_pointer(pgdat->node_private, np); +out: + mem_hotplug_done(); + mutex_unlock(&node_private_lock); + return ret; +} +EXPORT_SYMBOL_GPL(node_private_register); + +/** + * node_private_unregister - Unregister a private node + * @nid: Node identifier + * + * Unregister the driver from a private node. + * + * Only succeeds if all memory has been offlined (N_MEMORY_PRIVATE cleared). + * + * N_MEMORY_PRIVATE state is cleared by offline_pages() when the last + * memory is offlined, not by this function. + * + * After this returns, the node_private pointer is no longer visible and + * an RCU grace period has elapsed, so the driver may free its context. + * + * Return: 0 if unregistered, -EBUSY if N_MEMORY_PRIVATE is still set. + */ +int node_private_unregister(int nid) +{ + struct node_private *np; + pg_data_t *pgdat; + + if (!node_possible(nid)) + return 0; + + mutex_lock(&node_private_lock); + mem_hotplug_begin(); + + pgdat = NODE_DATA(nid); + np = rcu_dereference_protected(pgdat->node_private, + lockdep_is_held(&node_private_lock)); + if (!np) { + mem_hotplug_done(); + mutex_unlock(&node_private_lock); + return 0; + } + + /* + * Only unregister if N_MEMORY_PRIVATE is cleared (only occurs when + * the last memory block is offlined in offline_pages()) + */ + if (node_is_private(nid)) { + mem_hotplug_done(); + mutex_unlock(&node_private_lock); + return -EBUSY; + } + + rcu_assign_pointer(pgdat->node_private, NULL); + + mem_hotplug_done(); + mutex_unlock(&node_private_lock); + + synchronize_rcu(); + return 0; +} +EXPORT_SYMBOL_GPL(node_private_unregister); #endif /* CONFIG_MEMORY_HOTPLUG */ /** @@ -966,6 +1077,7 @@ static struct node_attr node_state_attr[] = { [N_HIGH_MEMORY] = _NODE_ATTR(has_high_memory, N_HIGH_MEMORY), #endif [N_MEMORY] = _NODE_ATTR(has_memory, N_MEMORY), + [N_MEMORY_PRIVATE] = _NODE_ATTR(has_private_memory, N_MEMORY_PRIVATE), [N_CPU] = _NODE_ATTR(has_cpu, N_CPU), [N_GENERIC_INITIATOR] = _NODE_ATTR(has_generic_initiator, N_GENERIC_INITIATOR), @@ -979,6 +1091,7 @@ static struct attribute *node_state_attrs[] = { &node_state_attr[N_HIGH_MEMORY].attr.attr, #endif &node_state_attr[N_MEMORY].attr.attr, + &node_state_attr[N_MEMORY_PRIVATE].attr.attr, &node_state_attr[N_CPU].attr.attr, &node_state_attr[N_GENERIC_INITIATOR].attr.attr, NULL diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 0507193b3ae34..9815e48c03b97 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -26,6 +26,8 @@ #include #include +struct node_private; + /* Free memory management - zoned buddy allocator. */ #ifndef CONFIG_ARCH_FORCE_MAX_ORDER #define MAX_PAGE_ORDER 10 @@ -1596,12 +1598,25 @@ typedef struct pglist_data { atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]; #ifdef CONFIG_NUMA struct memory_tier __rcu *memtier; + struct node_private __rcu *node_private; #endif #ifdef CONFIG_MEMORY_FAILURE struct memory_failure_stats mf_stats; #endif } pg_data_t; +#ifdef CONFIG_NUMA +static inline bool pgdat_is_private(pg_data_t *pgdat) +{ + return !!pgdat->node_private; +} +#else +static inline bool pgdat_is_private(pg_data_t *pgdat) +{ + return false; +} +#endif + #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) #define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) diff --git a/include/linux/node_private.h b/include/linux/node_private.h new file mode 100644 index 0000000000000..475496c84249f --- /dev/null +++ b/include/linux/node_private.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_NODE_PRIVATE_H +#define _LINUX_NODE_PRIVATE_H + +#include +#include + +struct page; + +/** + * struct node_private - Per-node container for N_MEMORY_PRIVATE nodes + * + * Allocated by the driver and passed to node_private_register(). + * The driver owns the memory and must ensure it remains valid until after + * node_private_unregister() returns. + * + * @owner: Opaque driver identifier + * @caps: NODE_PRIVATE_CAP_* service opt-ins for the node (zero by default; + * individual capabilities are defined and consumed by later changes) + */ +struct node_private { + void *owner; + unsigned long caps; +}; + +#ifdef CONFIG_NUMA +#include + +static inline bool folio_is_private_node(struct folio *folio) +{ + return node_state(folio_nid(folio), N_MEMORY_PRIVATE); +} + +static inline bool page_is_private_node(struct page *page) +{ + return node_state(page_to_nid(page), N_MEMORY_PRIVATE); +} + +static inline bool node_is_private(int nid) +{ + return node_state(nid, N_MEMORY_PRIVATE); +} + +#else /* !CONFIG_NUMA */ + +static inline bool folio_is_private_node(struct folio *folio) +{ + return false; +} + +static inline bool page_is_private_node(struct page *page) +{ + return false; +} + +static inline bool node_is_private(int nid) +{ + return false; +} + +#endif /* CONFIG_NUMA */ + +#if defined(CONFIG_NUMA) && defined(CONFIG_MEMORY_HOTPLUG) + +int node_private_register(int nid, struct node_private *np); +int node_private_unregister(int nid); + +#else /* !CONFIG_NUMA || !CONFIG_MEMORY_HOTPLUG */ + +static inline int node_private_register(int nid, struct node_private *np) +{ + return -ENODEV; +} + +static inline int node_private_unregister(int nid) +{ + return 0; +} + +#endif /* CONFIG_NUMA && CONFIG_MEMORY_HOTPLUG */ + +#endif /* _LINUX_NODE_PRIVATE_H */ diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index b842aa5255464..ba3e6c570a112 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -391,6 +391,7 @@ enum node_states { N_HIGH_MEMORY = N_NORMAL_MEMORY, #endif N_MEMORY, /* The node has memory(regular, high, movable) */ + N_MEMORY_PRIVATE, /* The node's memory is private */ N_CPU, /* The node has one or more cpus */ N_GENERIC_INITIATOR, /* The node has one or more Generic Initiators */ NR_NODE_STATES @@ -457,7 +458,7 @@ static __always_inline void node_set_offline(int nid) static __always_inline int node_state(int node, enum node_states state) { - return node == 0; + return node == 0 && state != N_MEMORY_PRIVATE; } static __always_inline void node_set_state(int node, enum node_states state) @@ -470,11 +471,11 @@ static __always_inline void node_clear_state(int node, enum node_states state) static __always_inline int num_node_state(enum node_states state) { - return 1; + return state == N_MEMORY_PRIVATE ? 0 : 1; } #define for_each_node_state(node, __state) \ - for ( (node) = 0; (node) == 0; (node) = 1) + for ((node) = 0; (node) == 0 && (__state) != N_MEMORY_PRIVATE; (node) = 1) #define first_online_node 0 #define first_memory_node 0 diff --git a/mm/internal.h b/mm/internal.h index 96d78a7778e88..cb9f4a8342e32 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,17 @@ extern int sysctl_min_unmapped_ratio; extern int sysctl_min_slab_ratio; #endif +/* folio_is_private_managed() - folio has special mm management rules */ +static inline bool folio_is_private_managed(struct folio *folio) +{ + return folio_is_zone_device(folio) || folio_is_private_node(folio); +} + +static inline bool page_is_private_managed(struct page *page) +{ + return folio_is_private_managed(page_folio(page)); +} + /* * Maintains state across a page table move. The operation assumes both source * and destination VMAs already exist and are specified by the user. -- 2.53.0-Meta