Re: [PATCH/RFC] do not count frozen tasks toward load

From: Nigel Cunningham
Date: Wed Apr 08 2009 - 21:22:16 EST


Hi again.

On Wed, 2009-04-08 at 19:45 -0500, Nathan Lynch wrote:
> Freezing tasks via the cgroup freezer causes the load average to climb
> because the freezer's current implementation puts frozen tasks in
> uninterruptible sleep (D state).
>
> Some applications which perform job-scheduling functions consult the
> load average when making decisions. If a cgroup is frozen, the load
> average does not provide a useful measure of the system's utilization
> to such applications. This is especially inconvenient if the job
> scheduler employs the cgroup freezer as a mechanism for preempting low
> priority jobs. Contrast this with using SIGSTOP for the same purpose:
> the stopped tasks do not count toward system load.
>
> Change task_contributes_to_load() to return false if the task is
> frozen. This results in /proc/loadavg behavior that better meets
> users' expectations.
>
> Signed-off-by: Nathan Lynch <ntl@xxxxxxxxx>
> ---
> include/linux/sched.h | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 011db2f..f8af167 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -202,7 +202,8 @@ extern unsigned long long time_sync_thresh;
> #define task_is_stopped_or_traced(task) \
> ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
> #define task_contributes_to_load(task) \
> - ((task->state & TASK_UNINTERRUPTIBLE) != 0)
> + ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
> + (task->flags & PF_FROZEN) == 0)
>
> #define __set_task_state(tsk, state_value) \
> do { (tsk)->state = (state_value); } while (0)

Tested-by: Nigel Cunningham <nigel@xxxxxxxxxxxx>

Looks good to me (though I like Andrew's point about using task_frozen).

nigel@nigel-laptop:~$ cat /proc/loadavg
0.34 0.27 0.12 1/251 9001
nigel@nigel-laptop:~$ sudo hibernate
nigel@nigel-laptop:~$ cat /proc/loadavg
0.52 0.33 0.14 2/250 9807
nigel@nigel-laptop:~$


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/