Skip to content

Commit 58568d2

Browse files
Miao Xietorvalds
authored andcommitted
cpuset,mm: update tasks' mems_allowed in time
Fix allocating page cache/slab object on the unallowed node when memory spread is set by updating tasks' mems_allowed after its cpuset's mems is changed. In order to update tasks' mems_allowed in time, we must modify the code of memory policy. Because the memory policy is applied in the process's context originally. After applying this patch, one task directly manipulates anothers mems_allowed, and we use alloc_lock in the task_struct to protect mems_allowed and memory policy of the task. But in the fast path, we didn't use lock to protect them, because adding a lock may lead to performance regression. But if we don't add a lock,the task might see no nodes when changing cpuset's mems_allowed to some non-overlapping set. In order to avoid it, we set all new allowed nodes, then clear newly disallowed ones. [lee.schermerhorn@hp.com: The rework of mpol_new() to extract the adjusting of the node mask to apply cpuset and mpol flags "context" breaks set_mempolicy() and mbind() with MPOL_PREFERRED and a NULL nodemask--i.e., explicit local allocation. Fix this by adding the check for MPOL_PREFERRED and empty node mask to mpol_new_mpolicy(). Remove the now unneeded 'nodes = NULL' from mpol_new(). Note that mpol_new_mempolicy() is always called with a non-NULL 'nodes' parameter now that it has been removed from mpol_new(). Therefore, we don't need to test nodes for NULL before testing it for 'empty'. However, just to be extra paranoid, add a VM_BUG_ON() to verify this assumption.] [lee.schermerhorn@hp.com: I don't think the function name 'mpol_new_mempolicy' is descriptive enough to differentiate it from mpol_new(). This function applies cpuset set context, usually constraining nodes to those allowed by the cpuset. However, when the 'RELATIVE_NODES flag is set, it also translates the nodes. So I settled on 'mpol_set_nodemask()', because the comment block for mpol_new() mentions that we need to call this function to "set nodes". Some additional minor line length, whitespace and typo cleanup.] Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Christoph Lameter <cl@linux-foundation.org> Cc: Paul Menage <menage@google.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 950592f commit 58568d2

7 files changed

Lines changed: 170 additions & 191 deletions

File tree

‎include/linux/cpuset.h‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
extern int number_of_cpusets; /* How many cpusets are defined in system? */
2020

21-
extern int cpuset_init_early(void);
2221
extern int cpuset_init(void);
2322
extern void cpuset_init_smp(void);
2423
extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
@@ -27,7 +26,6 @@ extern void cpuset_cpus_allowed_locked(struct task_struct *p,
2726
extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
2827
#define cpuset_current_mems_allowed (current->mems_allowed)
2928
void cpuset_init_current_mems_allowed(void);
30-
void cpuset_update_task_memory_state(void);
3129
int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask);
3230

3331
extern int __cpuset_node_allowed_softwall(int node, gfp_t gfp_mask);
@@ -92,9 +90,13 @@ extern void rebuild_sched_domains(void);
9290

9391
extern void cpuset_print_task_mems_allowed(struct task_struct *p);
9492

93+
static inline void set_mems_allowed(nodemask_t nodemask)
94+
{
95+
current->mems_allowed = nodemask;
96+
}
97+
9598
#else /* !CONFIG_CPUSETS */
9699

97-
static inline int cpuset_init_early(void) { return 0; }
98100
static inline int cpuset_init(void) { return 0; }
99101
static inline void cpuset_init_smp(void) {}
100102

@@ -116,7 +118,6 @@ static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
116118

117119
#define cpuset_current_mems_allowed (node_states[N_HIGH_MEMORY])
118120
static inline void cpuset_init_current_mems_allowed(void) {}
119-
static inline void cpuset_update_task_memory_state(void) {}
120121

121122
static inline int cpuset_nodemask_valid_mems_allowed(nodemask_t *nodemask)
122123
{
@@ -188,6 +189,10 @@ static inline void cpuset_print_task_mems_allowed(struct task_struct *p)
188189
{
189190
}
190191

192+
static inline void set_mems_allowed(nodemask_t nodemask)
193+
{
194+
}
195+
191196
#endif /* !CONFIG_CPUSETS */
192197

193198
#endif /* _LINUX_CPUSET_H */

‎include/linux/sched.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,8 @@ struct task_struct {
13181318
/* Thread group tracking */
13191319
u32 parent_exec_id;
13201320
u32 self_exec_id;
1321-
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings */
1321+
/* Protection of (de-)allocation: mm, files, fs, tty, keyrings, mems_allowed,
1322+
* mempolicy */
13221323
spinlock_t alloc_lock;
13231324

13241325
#ifdef CONFIG_GENERIC_HARDIRQS
@@ -1386,8 +1387,7 @@ struct task_struct {
13861387
cputime_t acct_timexpd; /* stime + utime since last update */
13871388
#endif
13881389
#ifdef CONFIG_CPUSETS
1389-
nodemask_t mems_allowed;
1390-
int cpuset_mems_generation;
1390+
nodemask_t mems_allowed; /* Protected by alloc_lock */
13911391
int cpuset_mem_spread_rotor;
13921392
#endif
13931393
#ifdef CONFIG_CGROUPS
@@ -1410,7 +1410,7 @@ struct task_struct {
14101410
struct list_head perf_counter_list;
14111411
#endif
14121412
#ifdef CONFIG_NUMA
1413-
struct mempolicy *mempolicy;
1413+
struct mempolicy *mempolicy; /* Protected by alloc_lock */
14141414
short il_next;
14151415
#endif
14161416
atomic_t fs_excl; /* holding fs exclusive resources */

‎init/main.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ asmlinkage void __init start_kernel(void)
670670
initrd_start = 0;
671671
}
672672
#endif
673-
cpuset_init_early();
674673
page_cgroup_init();
675674
enable_debug_pagealloc();
676675
cpu_hotplug_init();
@@ -867,6 +866,11 @@ static noinline int init_post(void)
867866
static int __init kernel_init(void * unused)
868867
{
869868
lock_kernel();
869+
870+
/*
871+
* init can allocate pages on any node
872+
*/
873+
set_mems_allowed(node_possible_map);
870874
/*
871875
* init can run on any cpu.
872876
*/

0 commit comments

Comments
 (0)