From 058a401be3656dbefb6ac81e08a254ab56f066a0 Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sat, 14 Jan 2006 13:21:06 -0800 Subject: [PATCH] --- yaml --- r: 18511 b: refs/heads/master c: 505970b96e3b7d22177c38e03435a68376628e7a h: refs/heads/master i: 18509: 843eeeced0426800732e5e6ef7d857a7d25dc635 18507: 83c675cd261a7dcac64e485264245e1a6007ea31 18503: 423b326a10ba92050df22056b5859ccd1a1907fe 18495: 2735ae9e8db0b41f89e732a4cc42399f08f48ce2 v: v3 --- [refs] | 2 +- trunk/include/linux/cpuset.h | 6 ++++++ trunk/kernel/cpuset.c | 33 ++++++++++++++++++++++++++++----- trunk/mm/oom_kill.c | 3 +++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index 872992a42b8c..77f664f25503 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: ed68cb3676bb179768529aeb808403d57295af56 +refs/heads/master: 505970b96e3b7d22177c38e03435a68376628e7a diff --git a/trunk/include/linux/cpuset.h b/trunk/include/linux/cpuset.h index c472f972bd6d..3bc606927116 100644 --- a/trunk/include/linux/cpuset.h +++ b/trunk/include/linux/cpuset.h @@ -48,6 +48,9 @@ extern void __cpuset_memory_pressure_bump(void); extern struct file_operations proc_cpuset_operations; extern char *cpuset_task_status_allowed(struct task_struct *task, char *buffer); +extern void cpuset_lock(void); +extern void cpuset_unlock(void); + #else /* !CONFIG_CPUSETS */ static inline int cpuset_init_early(void) { return 0; } @@ -93,6 +96,9 @@ static inline char *cpuset_task_status_allowed(struct task_struct *task, return buffer; } +static inline void cpuset_lock(void) {} +static inline void cpuset_unlock(void) {} + #endif /* !CONFIG_CPUSETS */ #endif /* _LINUX_CPUSET_H */ diff --git a/trunk/kernel/cpuset.c b/trunk/kernel/cpuset.c index d4b6bd7d74e5..fe2f71f92ae0 100644 --- a/trunk/kernel/cpuset.c +++ b/trunk/kernel/cpuset.c @@ -2149,6 +2149,33 @@ int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) return allowed; } +/** + * cpuset_lock - lock out any changes to cpuset structures + * + * The out of memory (oom) code needs to lock down cpusets + * from being changed while it scans the tasklist looking for a + * task in an overlapping cpuset. Expose callback_sem via this + * cpuset_lock() routine, so the oom code can lock it, before + * locking the task list. The tasklist_lock is a spinlock, so + * must be taken inside callback_sem. + */ + +void cpuset_lock(void) +{ + down(&callback_sem); +} + +/** + * cpuset_unlock - release lock on cpuset changes + * + * Undo the lock taken in a previous cpuset_lock() call. + */ + +void cpuset_unlock(void) +{ + up(&callback_sem); +} + /** * cpuset_excl_nodes_overlap - Do we overlap @p's mem_exclusive ancestors? * @p: pointer to task_struct of some other task. @@ -2158,7 +2185,7 @@ int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) * determine if task @p's memory usage might impact the memory * available to the current task. * - * Acquires callback_sem - not suitable for calling from a fast path. + * Call while holding callback_sem. **/ int cpuset_excl_nodes_overlap(const struct task_struct *p) @@ -2166,8 +2193,6 @@ int cpuset_excl_nodes_overlap(const struct task_struct *p) const struct cpuset *cs1, *cs2; /* my and p's cpuset ancestors */ int overlap = 0; /* do cpusets overlap? */ - down(&callback_sem); - task_lock(current); if (current->flags & PF_EXITING) { task_unlock(current); @@ -2186,8 +2211,6 @@ int cpuset_excl_nodes_overlap(const struct task_struct *p) overlap = nodes_intersects(cs1->mems_allowed, cs2->mems_allowed); done: - up(&callback_sem); - return overlap; } diff --git a/trunk/mm/oom_kill.c b/trunk/mm/oom_kill.c index 4748b906aff2..14bd4ec79597 100644 --- a/trunk/mm/oom_kill.c +++ b/trunk/mm/oom_kill.c @@ -274,6 +274,7 @@ void out_of_memory(gfp_t gfp_mask, int order) show_mem(); } + cpuset_lock(); read_lock(&tasklist_lock); retry: p = select_bad_process(); @@ -284,6 +285,7 @@ void out_of_memory(gfp_t gfp_mask, int order) /* Found nothing?!?! Either we hang forever, or we panic. */ if (!p) { read_unlock(&tasklist_lock); + cpuset_unlock(); panic("Out of memory and no killable processes...\n"); } @@ -293,6 +295,7 @@ void out_of_memory(gfp_t gfp_mask, int order) out: read_unlock(&tasklist_lock); + cpuset_unlock(); if (mm) mmput(mm);