* [PATCH] cpuset: avoid changing cpuset's cpus when -errno returned
@ 2008-09-03 7:33 Li Zefan
2008-09-04 17:49 ` Paul Menage
0 siblings, 1 reply; 4+ messages in thread
From: Li Zefan @ 2008-09-03 7:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Paul Jackson, Paul Menage, LKML
After the patch:
commit 0b2f630a28d53b5a2082a5275bc3334b10373508
Author: Miao Xie <miaox@cn.fujitsu.com>
Date: Fri Jul 25 01:47:21 2008 -0700
cpusets: restructure the function update_cpumask() and update_nodemask()
It might happen that 'echo 0 > /cpuset/sub/cpus' returns failure but 'cpus'
has been changed, because cpus was changed before calling heap_init() which
may return -ENOMEM.
This patch restores the orginal behavior.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/cpuset.c | 32 ++++++++++++++------------------
1 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index d5ab79c..817f8ac 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -774,36 +774,27 @@ static void cpuset_change_cpumask(struct task_struct *tsk,
/**
* update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
* @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
+ * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
*
* Called with cgroup_mutex held
*
* The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
* calling callback functions for each.
*
- * Return 0 if successful, -errno if not.
+ * Always return 0 if @heap != NULL, may return -errno if @heap == NULL
*/
-static int update_tasks_cpumask(struct cpuset *cs)
+static int update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
{
struct cgroup_scanner scan;
- struct ptr_heap heap;
int retval;
- /*
- * cgroup_scan_tasks() will initialize heap->gt for us.
- * heap_init() is still needed here for we should not change
- * cs->cpus_allowed when heap_init() fails.
- */
- retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
- if (retval)
- return retval;
-
scan.cg = cs->css.cgroup;
scan.test_task = cpuset_test_cpumask;
scan.process_task = cpuset_change_cpumask;
- scan.heap = &heap;
+ scan.heap = heap;
retval = cgroup_scan_tasks(&scan);
+ BUG_ON(heap != NULL && retval);
- heap_free(&heap);
return retval;
}
@@ -814,6 +805,7 @@ static int update_tasks_cpumask(struct cpuset *cs)
*/
static int update_cpumask(struct cpuset *cs, const char *buf)
{
+ struct ptr_heap heap;
struct cpuset trialcs;
int retval;
int is_load_balanced;
@@ -848,6 +840,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed))
return 0;
+ retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
+ if (retval)
+ return retval;
+
is_load_balanced = is_sched_load_balance(&trialcs);
mutex_lock(&callback_mutex);
@@ -858,9 +854,9 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
* Scan tasks in the cpuset, and update the cpumasks of any
* that need an update.
*/
- retval = update_tasks_cpumask(cs);
- if (retval < 0)
- return retval;
+ update_tasks_cpumask(cs, &heap);
+
+ heap_free(&heap);
if (is_load_balanced)
rebuild_sched_domains();
@@ -1896,7 +1892,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root)
nodes_empty(cp->mems_allowed))
remove_tasks_in_empty_cpuset(cp);
else {
- update_tasks_cpumask(cp);
+ update_tasks_cpumask(cp, NULL);
update_tasks_nodemask(cp, &oldmems);
}
}
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] cpuset: avoid changing cpuset's cpus when -errno returned
2008-09-03 7:33 [PATCH] cpuset: avoid changing cpuset's cpus when -errno returned Li Zefan
@ 2008-09-04 17:49 ` Paul Menage
2008-09-05 3:42 ` [PATCH -v2] " Li Zefan
0 siblings, 1 reply; 4+ messages in thread
From: Paul Menage @ 2008-09-04 17:49 UTC (permalink / raw)
To: Li Zefan; +Cc: Andrew Morton, Paul Jackson, LKML
On Wed, Sep 3, 2008 at 12:33 AM, Li Zefan <lizf@cn.fujitsu.com> wrote:
> After the patch:
>
> commit 0b2f630a28d53b5a2082a5275bc3334b10373508
> Author: Miao Xie <miaox@cn.fujitsu.com>
> Date: Fri Jul 25 01:47:21 2008 -0700
>
> cpusets: restructure the function update_cpumask() and update_nodemask()
>
> It might happen that 'echo 0 > /cpuset/sub/cpus' returns failure but 'cpus'
> has been changed, because cpus was changed before calling heap_init() which
> may return -ENOMEM.
Since neither of the callers of update_tasks_cpumask() check the
return value (one knows it's going to be 0, the other doesn't care
about errors) I think it would be better to just make it a void
function.
Paul
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH -v2] cpuset: avoid changing cpuset's cpus when -errno returned
2008-09-04 17:49 ` Paul Menage
@ 2008-09-05 3:42 ` Li Zefan
2008-09-05 23:24 ` Paul Menage
0 siblings, 1 reply; 4+ messages in thread
From: Li Zefan @ 2008-09-05 3:42 UTC (permalink / raw)
To: Paul Menage; +Cc: Andrew Morton, Paul Jackson, LKML
After the patch:
commit 0b2f630a28d53b5a2082a5275bc3334b10373508
Author: Miao Xie <miaox@cn.fujitsu.com>
Date: Fri Jul 25 01:47:21 2008 -0700
cpusets: restructure the function update_cpumask() and update_nodemask()
It might happen that 'echo 0 > /cpuset/sub/cpus' returned failure but 'cpus'
has been changed, because cpus was changed before calling heap_init() which
may return -ENOMEM.
This patch restores the orginal behavior.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
kernel/cpuset.c | 37 +++++++++++++++----------------------
1 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index d5ab79c..0d33827 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -774,37 +774,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk,
/**
* update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
* @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
+ * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
*
* Called with cgroup_mutex held
*
* The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
* calling callback functions for each.
*
- * Return 0 if successful, -errno if not.
+ * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
+ * if @heap != NULL.
*/
-static int update_tasks_cpumask(struct cpuset *cs)
+static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
{
struct cgroup_scanner scan;
- struct ptr_heap heap;
- int retval;
-
- /*
- * cgroup_scan_tasks() will initialize heap->gt for us.
- * heap_init() is still needed here for we should not change
- * cs->cpus_allowed when heap_init() fails.
- */
- retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
- if (retval)
- return retval;
scan.cg = cs->css.cgroup;
scan.test_task = cpuset_test_cpumask;
scan.process_task = cpuset_change_cpumask;
- scan.heap = &heap;
- retval = cgroup_scan_tasks(&scan);
-
- heap_free(&heap);
- return retval;
+ scan.heap = heap;
+ cgroup_scan_tasks(&scan);
}
/**
@@ -814,6 +802,7 @@ static int update_tasks_cpumask(struct cpuset *cs)
*/
static int update_cpumask(struct cpuset *cs, const char *buf)
{
+ struct ptr_heap heap;
struct cpuset trialcs;
int retval;
int is_load_balanced;
@@ -848,6 +837,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed))
return 0;
+ retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
+ if (retval)
+ return retval;
+
is_load_balanced = is_sched_load_balance(&trialcs);
mutex_lock(&callback_mutex);
@@ -858,9 +851,9 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
* Scan tasks in the cpuset, and update the cpumasks of any
* that need an update.
*/
- retval = update_tasks_cpumask(cs);
- if (retval < 0)
- return retval;
+ update_tasks_cpumask(cs, &heap);
+
+ heap_free(&heap);
if (is_load_balanced)
rebuild_sched_domains();
@@ -1896,7 +1889,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root)
nodes_empty(cp->mems_allowed))
remove_tasks_in_empty_cpuset(cp);
else {
- update_tasks_cpumask(cp);
+ update_tasks_cpumask(cp, NULL);
update_tasks_nodemask(cp, &oldmems);
}
}
--
1.5.4.rc3
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH -v2] cpuset: avoid changing cpuset's cpus when -errno returned
2008-09-05 3:42 ` [PATCH -v2] " Li Zefan
@ 2008-09-05 23:24 ` Paul Menage
0 siblings, 0 replies; 4+ messages in thread
From: Paul Menage @ 2008-09-05 23:24 UTC (permalink / raw)
To: Li Zefan; +Cc: Andrew Morton, Paul Jackson, LKML
On Thu, Sep 4, 2008 at 8:42 PM, Li Zefan <lizf@cn.fujitsu.com> wrote:
> After the patch:
>
> commit 0b2f630a28d53b5a2082a5275bc3334b10373508
> Author: Miao Xie <miaox@cn.fujitsu.com>
> Date: Fri Jul 25 01:47:21 2008 -0700
>
> cpusets: restructure the function update_cpumask() and update_nodemask()
>
> It might happen that 'echo 0 > /cpuset/sub/cpus' returned failure but 'cpus'
> has been changed, because cpus was changed before calling heap_init() which
> may return -ENOMEM.
>
> This patch restores the orginal behavior.
>
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Paul Menage <menage@google.com>
Thanks.
Paul
> ---
> kernel/cpuset.c | 37 +++++++++++++++----------------------
> 1 files changed, 15 insertions(+), 22 deletions(-)
>
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> index d5ab79c..0d33827 100644
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -774,37 +774,25 @@ static void cpuset_change_cpumask(struct task_struct *tsk,
> /**
> * update_tasks_cpumask - Update the cpumasks of tasks in the cpuset.
> * @cs: the cpuset in which each task's cpus_allowed mask needs to be changed
> + * @heap: if NULL, defer allocating heap memory to cgroup_scan_tasks()
> *
> * Called with cgroup_mutex held
> *
> * The cgroup_scan_tasks() function will scan all the tasks in a cgroup,
> * calling callback functions for each.
> *
> - * Return 0 if successful, -errno if not.
> + * No return value. It's guaranteed that cgroup_scan_tasks() always returns 0
> + * if @heap != NULL.
> */
> -static int update_tasks_cpumask(struct cpuset *cs)
> +static void update_tasks_cpumask(struct cpuset *cs, struct ptr_heap *heap)
> {
> struct cgroup_scanner scan;
> - struct ptr_heap heap;
> - int retval;
> -
> - /*
> - * cgroup_scan_tasks() will initialize heap->gt for us.
> - * heap_init() is still needed here for we should not change
> - * cs->cpus_allowed when heap_init() fails.
> - */
> - retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
> - if (retval)
> - return retval;
>
> scan.cg = cs->css.cgroup;
> scan.test_task = cpuset_test_cpumask;
> scan.process_task = cpuset_change_cpumask;
> - scan.heap = &heap;
> - retval = cgroup_scan_tasks(&scan);
> -
> - heap_free(&heap);
> - return retval;
> + scan.heap = heap;
> + cgroup_scan_tasks(&scan);
> }
>
> /**
> @@ -814,6 +802,7 @@ static int update_tasks_cpumask(struct cpuset *cs)
> */
> static int update_cpumask(struct cpuset *cs, const char *buf)
> {
> + struct ptr_heap heap;
> struct cpuset trialcs;
> int retval;
> int is_load_balanced;
> @@ -848,6 +837,10 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
> if (cpus_equal(cs->cpus_allowed, trialcs.cpus_allowed))
> return 0;
>
> + retval = heap_init(&heap, PAGE_SIZE, GFP_KERNEL, NULL);
> + if (retval)
> + return retval;
> +
> is_load_balanced = is_sched_load_balance(&trialcs);
>
> mutex_lock(&callback_mutex);
> @@ -858,9 +851,9 @@ static int update_cpumask(struct cpuset *cs, const char *buf)
> * Scan tasks in the cpuset, and update the cpumasks of any
> * that need an update.
> */
> - retval = update_tasks_cpumask(cs);
> - if (retval < 0)
> - return retval;
> + update_tasks_cpumask(cs, &heap);
> +
> + heap_free(&heap);
>
> if (is_load_balanced)
> rebuild_sched_domains();
> @@ -1896,7 +1889,7 @@ static void scan_for_empty_cpusets(const struct cpuset *root)
> nodes_empty(cp->mems_allowed))
> remove_tasks_in_empty_cpuset(cp);
> else {
> - update_tasks_cpumask(cp);
> + update_tasks_cpumask(cp, NULL);
> update_tasks_nodemask(cp, &oldmems);
> }
> }
> --
> 1.5.4.rc3
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-09-05 23:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-03 7:33 [PATCH] cpuset: avoid changing cpuset's cpus when -errno returned Li Zefan
2008-09-04 17:49 ` Paul Menage
2008-09-05 3:42 ` [PATCH -v2] " Li Zefan
2008-09-05 23:24 ` Paul Menage
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox