From nobody Tue Feb 10 01:59:16 2026 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED59C3314B8 for ; Thu, 8 Jan 2026 20:38:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767904739; cv=none; b=WuNwpn23X466xNlVdJFMjfsCo8GRoTkXzyzcDEZ/U6buTwVvcu3vnhD13on/J+8QglXtacsxTH+ObfnLoeEsoBG5fekyMNVyXHpF0h9VoS40KIVasrKijiRve0AqHqvx7CBdVyCLyBCRx85ydO4KeeMNPQTrj5nSXH+jLFfrghE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767904739; c=relaxed/simple; bh=Svp3zx02/oXeli/4ycXpUYqvgWOFWoraBOL/YLhuieA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MdEZDK0UPDDtZmTqaZ1bRmU/+ptWZ1vcZOXO2IlQDupRzjKw3LM01Ndw4HjcY8pRqBvIikmRa1G19in1gQx7wbGqtIMNynUsyY97eN8RFW0dAlcTeUqN1ojDsCkNOYUKX8yT4tQkQgPW+9fp4DzeW3gYW/0V0ZJvGlCkIu8iN9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=oUYDj5eb; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="oUYDj5eb" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-88a35a00506so48725126d6.2 for ; Thu, 08 Jan 2026 12:38:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1767904735; x=1768509535; darn=vger.kernel.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; bh=ZHxGrBtl/hlNeoeWLQW++mLZlqqQEPHYPIYdLPi7GaY=; b=oUYDj5ebfGBDiqGGUN6/7W2yrHQ9qayBYVthZpoDKsTCNRbQqNrK+gBcIxQAjG9MRi fT8y0WsERbyUk1qrALNjgnHDF9p8fCaxYKkQIIi49zO8WGjHE2obP596F/JYZgzn4CWI DjsG8U0P8Jnmg+HxZLi6hv+ulfnaiwD3uP9+/XntEVLdpJB6oHT10nk5tE2cKpCP5Ypf L/q4YeW40k9oxo9xscTUJuQoqIGnOLhld45vRKgElinZea62jcuug8rRHqQNEuEQRMN+ re00ORrUJTpGkIvpTu1KfRt2AvytEm/l6ewn1sozbOBKW+dFipR4Ai+MvIRZ9eUFyxPs tf1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767904735; x=1768509535; 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; bh=ZHxGrBtl/hlNeoeWLQW++mLZlqqQEPHYPIYdLPi7GaY=; b=JCx1arm5qPWOmocRJW+isMTRJQk00yfsGW13pI2l1VHnva1pXJbLpDK6PeeV5pe0nT u6jtQ8GwCWK/rphZhFpMmQ1OrhAnI5PACRMQnGxRfWhfIt9NL+xJg9t7L5INvBda9faO 3f67zTAd/bHQSrynayGSBQRxI/yWc2Pwm70nw5hgfLNUfVPriltO6q6QlDrEakXetwgF CYje57VweSm/mcdHJTG7Z+zLSI9B8zX1qI1pHnEXMzhyzeT6rt1FyLh87JmDy9QRo5Sc kM+Av713KLxElGi3CiB8j1TQl6uNZB67xIhw+H+ar5j9bsjZy/ax4ktAQ6Hk0H7HBDZ9 P79A== X-Forwarded-Encrypted: i=1; AJvYcCVUepzABFWglp1pjwNeEyYjfk+Zs4WpyBk+8IXVQqTfJgt666beISYbe7YDKBPy3+0VAQoqtCa9rzlkZm4=@vger.kernel.org X-Gm-Message-State: AOJu0YxXvIGK8XyGUyisz36oOYWHOsev6i06hTjpi3SjFoUsOjUrrnuf NjAa6sOrcBhsRNH63XblNgOtssiTESHWkcpcmgYRUu+dKy9viUB3kwaUgRqvYaF+VAU= X-Gm-Gg: AY/fxX7RjplbuEXB/UdQDMYPvHatI+VyCu8rHvOMn9Vn0+tyqxmeLAjtTGjkJmbyY6u I3+18vpmOyiSes7w12sUZYYmyhVvs2kqpJW5OvELb27B44kODdXlCuem1bJSmNzv0Ie1XGYDb4Z SVeYP1OyLLr8hsnHm8g+9Iqei1rp2y01Mmd4DQn36DsDXX9QfQVezA/i62bxgznsuHU5iA9g9Qu Do74vAaz5nnbEbXrpfyBmF1hE0nHBar9+/5hXlLKlOBv+nOG6zTBeJw7i2CcxWnnsGBkAT8OPv9 V+cOvBbDVgZH703Qj6Idqqu++cda9Tw4SZcsqYnmOgzuDWDyrjffv1ijuuSOBD9P/cW1RUtsuIF /7E6XASphRQ58hRdPNlD4CUZIlGK/P4q77T80IEzo/YQdMH2aw4Hs9mFYeU+Q8YCYW4F19CvXze blcNnPjPZZju/Bq2D8B1c9SZWyHx3pgs3/VwiEHtJWolAQn3z9dDfRSo9+xXZhpc3JheMtKYN9p hBM1XMNWFKxkQ== X-Google-Smtp-Source: AGHT+IHoPDtEyu/qazAej9qUcvHlLXP2al9oKF0ZIuQR82MK0kzJKO/DN4uJk0hBSgOfyzdaEtp2Zw== X-Received: by 2002:a05:6214:1147:b0:890:9169:d2f5 with SMTP id 6a1803df08f44-8909169d5c2mr55584316d6.64.1767904734853; Thu, 08 Jan 2026 12:38:54 -0800 (PST) Received: from gourry-fedora-PF4VCD3F.lan (pool-96-255-20-138.washdc.ftas.verizon.net. [96.255.20.138]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-890770e472csm60483886d6.23.2026.01.08.12.38.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jan 2026 12:38:54 -0800 (PST) From: Gregory Price To: linux-mm@kvack.org, cgroups@vger.kernel.org, linux-cxl@vger.kernel.org Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@meta.com, longman@redhat.com, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, corbet@lwn.net, gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, dave@stgolabs.net, jonathan.cameron@huawei.com, dave.jiang@intel.com, alison.schofield@intel.com, vishal.l.verma@intel.com, ira.weiny@intel.com, dan.j.williams@intel.com, akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com, mhocko@suse.com, jackmanb@google.com, ziy@nvidia.com, david@kernel.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, rppt@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk, rientjes@google.com, shakeel.butt@linux.dev, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org, yosry.ahmed@linux.dev, chengming.zhou@linux.dev, roman.gushchin@linux.dev, muchun.song@linux.dev, osalvador@suse.de, matthew.brost@intel.com, joshua.hahnjy@gmail.com, rakie.kim@sk.com, byungchul@sk.com, gourry@gourry.net, ying.huang@linux.alibaba.com, apopple@nvidia.com, cl@gentwo.org, harry.yoo@oracle.com, zhengqi.arch@bytedance.com Subject: [RFC PATCH v3 4/8] cpuset: introduce cpuset.mems.sysram Date: Thu, 8 Jan 2026 15:37:51 -0500 Message-ID: <20260108203755.1163107-5-gourry@gourry.net> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260108203755.1163107-1-gourry@gourry.net> References: <20260108203755.1163107-1-gourry@gourry.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" mems_sysram contains only SystemRAM nodes (omitting Private Nodes). The nodemask is intersect(effective_mems, node_states[N_MEMORY]). When checking mems_allowed, check for __GFP_THISNODE to determine if the check should be made against sysram_nodes or mems_allowed. This omits Private Nodes (N_PRIVATE) from default mems_allowed checks, making those nodes unreachable via normal allocation paths (page faults, mempolicies, etc). Signed-off-by: Gregory Price --- include/linux/cpuset.h | 20 +++++-- kernel/cgroup/cpuset-internal.h | 8 +++ kernel/cgroup/cpuset-v1.c | 8 +++ kernel/cgroup/cpuset.c | 96 +++++++++++++++++++++++++-------- mm/memcontrol.c | 2 +- mm/mempolicy.c | 6 +-- mm/migrate.c | 4 +- 7 files changed, 112 insertions(+), 32 deletions(-) diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h index fe4f29624117..1ae09ec0fcb7 100644 --- a/include/linux/cpuset.h +++ b/include/linux/cpuset.h @@ -174,7 +174,9 @@ static inline void set_mems_allowed(nodemask_t nodemask) task_unlock(current); } =20 -extern void cpuset_nodes_allowed(struct cgroup *cgroup, nodemask_t *mask); +extern void cpuset_sysram_nodes_allowed(struct cgroup *cgroup, + nodemask_t *mask); +extern nodemask_t cpuset_sysram_nodemask(struct task_struct *p); #else /* !CONFIG_CPUSETS */ =20 static inline bool cpusets_enabled(void) { return false; } @@ -218,7 +220,13 @@ static inline bool cpuset_cpu_is_isolated(int cpu) return false; } =20 -static inline nodemask_t cpuset_mems_allowed(struct task_struct *p) +static inline void cpuset_sysram_nodes_allowed(struct cgroup *cgroup, + nodemask_t *mask) +{ + nodes_copy(*mask, node_possible_map); +} + +static inline nodemask_t cpuset_sysram_nodemask(struct task_struct *p) { return node_possible_map; } @@ -301,10 +309,16 @@ static inline bool read_mems_allowed_retry(unsigned i= nt seq) return false; } =20 -static inline void cpuset_nodes_allowed(struct cgroup *cgroup, nodemask_t = *mask) +static inline void cpuset_sysram_nodes_allowed(struct cgroup *cgroup, + nodemask_t *mask) { nodes_copy(*mask, node_states[N_MEMORY]); } + +static nodemask_t cpuset_sysram_nodemask(struct task_struct *p) +{ + return node_states[N_MEMORY]; +} #endif /* !CONFIG_CPUSETS */ =20 #endif /* _LINUX_CPUSET_H */ diff --git a/kernel/cgroup/cpuset-internal.h b/kernel/cgroup/cpuset-interna= l.h index 01976c8e7d49..4764aaef585f 100644 --- a/kernel/cgroup/cpuset-internal.h +++ b/kernel/cgroup/cpuset-internal.h @@ -53,6 +53,7 @@ typedef enum { FILE_MEMORY_MIGRATE, FILE_CPULIST, FILE_MEMLIST, + FILE_MEMS_SYSRAM, FILE_EFFECTIVE_CPULIST, FILE_EFFECTIVE_MEMLIST, FILE_SUBPARTS_CPULIST, @@ -104,6 +105,13 @@ struct cpuset { cpumask_var_t effective_cpus; nodemask_t effective_mems; =20 + /* + * SystemRAM Memory Nodes for tasks. + * This is the intersection of effective_mems and node_states[N_MEMORY]. + * Tasks will have their sysram_nodes set to this value. + */ + nodemask_t mems_sysram; + /* * Exclusive CPUs dedicated to current cgroup (default hierarchy only) * diff --git a/kernel/cgroup/cpuset-v1.c b/kernel/cgroup/cpuset-v1.c index 12e76774c75b..45b74181effd 100644 --- a/kernel/cgroup/cpuset-v1.c +++ b/kernel/cgroup/cpuset-v1.c @@ -293,6 +293,8 @@ void cpuset1_hotplug_update_tasks(struct cpuset *cs, cpumask_copy(cs->effective_cpus, new_cpus); cs->mems_allowed =3D *new_mems; cs->effective_mems =3D *new_mems; + nodes_and(cs->mems_sysram, cs->effective_mems, node_states[N_MEMORY]); + cpuset_update_tasks_nodemask(cs); cpuset_callback_unlock_irq(); =20 /* @@ -532,6 +534,12 @@ struct cftype cpuset1_files[] =3D { .private =3D FILE_EFFECTIVE_MEMLIST, }, =20 + { + .name =3D "mems_sysram", + .seq_show =3D cpuset_common_seq_show, + .private =3D FILE_MEMS_SYSRAM, + }, + { .name =3D "cpu_exclusive", .read_u64 =3D cpuset_read_u64, diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index a3ade9d5968b..4c213a2ea7ac 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -454,11 +455,11 @@ static void guarantee_active_cpus(struct task_struct = *tsk, * * Call with callback_lock or cpuset_mutex held. */ -static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask) +static void guarantee_online_sysram_nodes(struct cpuset *cs, nodemask_t *p= mask) { - while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY])) + while (!nodes_intersects(cs->mems_sysram, node_states[N_MEMORY])) cs =3D parent_cs(cs); - nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]); + nodes_and(*pmask, cs->mems_sysram, node_states[N_MEMORY]); } =20 /** @@ -2791,7 +2792,7 @@ void cpuset_update_tasks_nodemask(struct cpuset *cs) =20 cpuset_being_rebound =3D cs; /* causes mpol_dup() rebind */ =20 - guarantee_online_mems(cs, &newmems); + guarantee_online_sysram_nodes(cs, &newmems); =20 /* * The mpol_rebind_mm() call takes mmap_lock, which we couldn't @@ -2816,7 +2817,7 @@ void cpuset_update_tasks_nodemask(struct cpuset *cs) =20 migrate =3D is_memory_migrate(cs); =20 - mpol_rebind_mm(mm, &cs->mems_allowed); + mpol_rebind_mm(mm, &cs->mems_sysram); if (migrate) cpuset_migrate_mm(mm, &cs->old_mems_allowed, &newmems); else @@ -2876,6 +2877,8 @@ static void update_nodemasks_hier(struct cpuset *cs, = nodemask_t *new_mems) =20 spin_lock_irq(&callback_lock); cp->effective_mems =3D *new_mems; + nodes_and(cp->mems_sysram, cp->effective_mems, + node_states[N_MEMORY]); spin_unlock_irq(&callback_lock); =20 WARN_ON(!is_in_v2_mode() && @@ -3304,11 +3307,11 @@ static void cpuset_attach(struct cgroup_taskset *ts= et) * by skipping the task iteration and update. */ if (cpuset_v2() && !cpus_updated && !mems_updated) { - cpuset_attach_nodemask_to =3D cs->effective_mems; + cpuset_attach_nodemask_to =3D cs->mems_sysram; goto out; } =20 - guarantee_online_mems(cs, &cpuset_attach_nodemask_to); + guarantee_online_sysram_nodes(cs, &cpuset_attach_nodemask_to); =20 cgroup_taskset_for_each(task, css, tset) cpuset_attach_task(cs, task); @@ -3319,7 +3322,7 @@ static void cpuset_attach(struct cgroup_taskset *tset) * if there is no change in effective_mems and CS_MEMORY_MIGRATE is * not set. */ - cpuset_attach_nodemask_to =3D cs->effective_mems; + cpuset_attach_nodemask_to =3D cs->mems_sysram; if (!is_memory_migrate(cs) && !mems_updated) goto out; =20 @@ -3441,6 +3444,9 @@ int cpuset_common_seq_show(struct seq_file *sf, void = *v) case FILE_EFFECTIVE_MEMLIST: seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->effective_mems)); break; + case FILE_MEMS_SYSRAM: + seq_printf(sf, "%*pbl\n", nodemask_pr_args(&cs->mems_sysram)); + break; case FILE_EXCLUSIVE_CPULIST: seq_printf(sf, "%*pbl\n", cpumask_pr_args(cs->exclusive_cpus)); break; @@ -3552,6 +3558,12 @@ static struct cftype dfl_files[] =3D { .private =3D FILE_EFFECTIVE_MEMLIST, }, =20 + { + .name =3D "mems.sysram", + .seq_show =3D cpuset_common_seq_show, + .private =3D FILE_MEMS_SYSRAM, + }, + { .name =3D "cpus.partition", .seq_show =3D cpuset_partition_show, @@ -3654,6 +3666,8 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) if (is_in_v2_mode()) { cpumask_copy(cs->effective_cpus, parent->effective_cpus); cs->effective_mems =3D parent->effective_mems; + nodes_and(cs->mems_sysram, cs->effective_mems, + node_states[N_MEMORY]); } spin_unlock_irq(&callback_lock); =20 @@ -3685,6 +3699,8 @@ static int cpuset_css_online(struct cgroup_subsys_sta= te *css) spin_lock_irq(&callback_lock); cs->mems_allowed =3D parent->mems_allowed; cs->effective_mems =3D parent->mems_allowed; + nodes_and(cs->mems_sysram, cs->effective_mems, + node_states[N_MEMORY]); cpumask_copy(cs->cpus_allowed, parent->cpus_allowed); cpumask_copy(cs->effective_cpus, parent->cpus_allowed); spin_unlock_irq(&callback_lock); @@ -3838,7 +3854,7 @@ static void cpuset_fork(struct task_struct *task) =20 /* CLONE_INTO_CGROUP */ mutex_lock(&cpuset_mutex); - guarantee_online_mems(cs, &cpuset_attach_nodemask_to); + guarantee_online_sysram_nodes(cs, &cpuset_attach_nodemask_to); cpuset_attach_task(cs, task); =20 dec_attach_in_progress_locked(cs); @@ -3887,7 +3903,8 @@ int __init cpuset_init(void) cpumask_setall(top_cpuset.effective_xcpus); cpumask_setall(top_cpuset.exclusive_cpus); nodes_setall(top_cpuset.effective_mems); - + nodes_and(top_cpuset.mems_sysram, top_cpuset.effective_mems, + node_states[N_MEMORY]); fmeter_init(&top_cpuset.fmeter); =20 BUG_ON(!alloc_cpumask_var(&cpus_attach, GFP_KERNEL)); @@ -3916,6 +3933,7 @@ hotplug_update_tasks(struct cpuset *cs, spin_lock_irq(&callback_lock); cpumask_copy(cs->effective_cpus, new_cpus); cs->effective_mems =3D *new_mems; + nodes_and(cs->mems_sysram, cs->effective_mems, node_states[N_MEMORY]); spin_unlock_irq(&callback_lock); =20 if (cpus_updated) @@ -4064,7 +4082,15 @@ static void cpuset_handle_hotplug(void) =20 /* fetch the available cpus/mems and find out which changed how */ cpumask_copy(&new_cpus, cpu_active_mask); - new_mems =3D node_states[N_MEMORY]; + + /* + * Effective mems is union(N_MEMORY, N_PRIVATE), this allows + * control over N_PRIVATE node usage from cgroups while + * mems.sysram prevents N_PRIVATE nodes from being used + * without __GFP_THISNODE. + */ + nodes_clear(new_mems); + nodes_or(new_mems, node_states[N_MEMORY], node_states[N_PRIVATE]); =20 /* * If subpartitions_cpus is populated, it is likely that the check @@ -4106,6 +4132,8 @@ static void cpuset_handle_hotplug(void) if (!on_dfl) top_cpuset.mems_allowed =3D new_mems; top_cpuset.effective_mems =3D new_mems; + nodes_and(top_cpuset.mems_sysram, top_cpuset.effective_mems, + node_states[N_MEMORY]); spin_unlock_irq(&callback_lock); cpuset_update_tasks_nodemask(&top_cpuset); } @@ -4176,6 +4204,7 @@ void __init cpuset_init_smp(void) =20 cpumask_copy(top_cpuset.effective_cpus, cpu_active_mask); top_cpuset.effective_mems =3D node_states[N_MEMORY]; + top_cpuset.mems_sysram =3D node_states[N_MEMORY]; =20 hotplug_node_notifier(cpuset_track_online_nodes, CPUSET_CALLBACK_PRI); =20 @@ -4293,14 +4322,18 @@ bool cpuset_cpus_allowed_fallback(struct task_struc= t *tsk) return changed; } =20 +/* + * At this point in time, no hotplug nodes can have been added, so just set + * the sysram_nodes of the init task to the set of N_MEMORY nodes. + */ void __init cpuset_init_current_mems_allowed(void) { - nodes_setall(current->mems_allowed); + current->mems_allowed =3D node_states[N_MEMORY]; } =20 /** - * cpuset_mems_allowed - return mems_allowed mask from a tasks cpuset. - * @tsk: pointer to task_struct from which to obtain cpuset->mems_allowed. + * cpuset_sysram_nodemask - return mems_sysram mask from a tasks cpuset. + * @tsk: pointer to task_struct from which to obtain cpuset->mems_sysram. * * Description: Returns the nodemask_t mems_allowed of the cpuset * attached to the specified @tsk. Guaranteed to return some non-empty @@ -4308,13 +4341,13 @@ void __init cpuset_init_current_mems_allowed(void) * tasks cpuset. **/ =20 -nodemask_t cpuset_mems_allowed(struct task_struct *tsk) +nodemask_t cpuset_sysram_nodemask(struct task_struct *tsk) { nodemask_t mask; unsigned long flags; =20 spin_lock_irqsave(&callback_lock, flags); - guarantee_online_mems(task_cs(tsk), &mask); + guarantee_online_sysram_nodes(task_cs(tsk), &mask); spin_unlock_irqrestore(&callback_lock, flags); =20 return mask; @@ -4383,17 +4416,30 @@ static struct cpuset *nearest_hardwall_ancestor(str= uct cpuset *cs) * tsk_is_oom_victim - any node ok * GFP_KERNEL - any node in enclosing hardwalled cpuset ok * GFP_USER - only nodes in current tasks mems allowed ok. + * GFP_THISNODE - allows private memory nodes in mems_allowed */ bool cpuset_current_node_allowed(int node, gfp_t gfp_mask) { struct cpuset *cs; /* current cpuset ancestors */ bool allowed; /* is allocation in zone z allowed? */ unsigned long flags; + bool private_nodes =3D gfp_mask & __GFP_THISNODE; =20 + /* Only SysRAM nodes are valid in interrupt context */ if (in_interrupt()) - return true; - if (node_isset(node, current->mems_allowed)) - return true; + return node_isset(node, node_states[N_MEMORY]); + + if (private_nodes) { + rcu_read_lock(); + cs =3D task_cs(current); + allowed =3D node_isset(node, cs->effective_mems); + rcu_read_unlock(); + } else + allowed =3D node_isset(node, current->mems_allowed); + + if (allowed) + return allowed; + /* * Allow tasks that have access to memory reserves because they have * been OOM killed to get memory anywhere. @@ -4412,6 +4458,10 @@ bool cpuset_current_node_allowed(int node, gfp_t gfp= _mask) cs =3D nearest_hardwall_ancestor(task_cs(current)); allowed =3D node_isset(node, cs->mems_allowed); =20 + /* If not allowing private node allocation, restrict to sysram nodes */ + if (!private_nodes) + allowed &=3D node_isset(node, node_states[N_MEMORY]); + spin_unlock_irqrestore(&callback_lock, flags); return allowed; } @@ -4434,7 +4484,7 @@ bool cpuset_current_node_allowed(int node, gfp_t gfp_= mask) * online due to hot plugins. Callers should check the mask for validity on * return based on its subsequent use. **/ -void cpuset_nodes_allowed(struct cgroup *cgroup, nodemask_t *mask) +void cpuset_sysram_nodes_allowed(struct cgroup *cgroup, nodemask_t *mask) { struct cgroup_subsys_state *css; struct cpuset *cs; @@ -4457,16 +4507,16 @@ void cpuset_nodes_allowed(struct cgroup *cgroup, no= demask_t *mask) =20 /* * The reference taken via cgroup_get_e_css is sufficient to - * protect css, but it does not imply safe accesses to effective_mems. + * protect css, but it does not imply safe accesses to mems_sysram. * - * Normally, accessing effective_mems would require the cpuset_mutex + * Normally, accessing mems_sysram would require the cpuset_mutex * or callback_lock - but the correctness of this information is stale * immediately after the query anyway. We do not acquire the lock * during this process to save lock contention in exchange for racing * against mems_allowed rebinds. */ cs =3D container_of(css, struct cpuset, css); - nodes_copy(*mask, cs->effective_mems); + nodes_copy(*mask, cs->mems_sysram); css_put(css); } =20 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7fbe9565cd06..2df7168edca0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5610,7 +5610,7 @@ void mem_cgroup_node_filter_allowed(struct mem_cgroup= *memcg, nodemask_t *mask) * in effective_mems and hot-unpluging of nodes, inaccurate allowed * mask is acceptable. */ - cpuset_nodes_allowed(memcg->css.cgroup, &allowed); + cpuset_sysram_nodes_allowed(memcg->css.cgroup, &allowed); nodes_and(*mask, *mask, allowed); } =20 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 76da50425712..760b5b6b4ae6 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1901,14 +1901,14 @@ static int kernel_migrate_pages(pid_t pid, unsigned= long maxnode, } rcu_read_unlock(); =20 - task_nodes =3D cpuset_mems_allowed(task); + task_nodes =3D cpuset_sysram_nodemask(task); /* Is the user allowed to access the target nodes? */ if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) { err =3D -EPERM; goto out_put; } =20 - task_nodes =3D cpuset_mems_allowed(current); + task_nodes =3D cpuset_sysram_nodemask(current); nodes_and(*new, *new, task_nodes); if (nodes_empty(*new)) goto out_put; @@ -2833,7 +2833,7 @@ struct mempolicy *__mpol_dup(struct mempolicy *old) *new =3D *old; =20 if (current_cpuset_is_being_rebound()) { - nodemask_t mems =3D cpuset_mems_allowed(current); + nodemask_t mems =3D cpuset_sysram_nodemask(current); mpol_rebind_policy(new, &mems); } atomic_set(&new->refcnt, 1); diff --git a/mm/migrate.c b/mm/migrate.c index 5169f9717f60..0ad893bf862b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2534,7 +2534,7 @@ static struct mm_struct *find_mm_struct(pid_t pid, no= demask_t *mem_nodes) */ if (!pid) { mmget(current->mm); - *mem_nodes =3D cpuset_mems_allowed(current); + *mem_nodes =3D cpuset_sysram_nodemask(current); return current->mm; } =20 @@ -2555,7 +2555,7 @@ static struct mm_struct *find_mm_struct(pid_t pid, no= demask_t *mem_nodes) mm =3D ERR_PTR(security_task_movememory(task)); if (IS_ERR(mm)) goto out; - *mem_nodes =3D cpuset_mems_allowed(task); + *mem_nodes =3D cpuset_sysram_nodemask(task); mm =3D get_task_mm(task); out: put_task_struct(task); --=20 2.52.0