Skip to contentSkip to conversation

sched: Ensure that a child can't gain time over it's parent after fork()

tip:sched/core tip-bot for Mike Galbraith 3 participants 4 messages Sep 8, 2009

lore
Share & tools
lore
#0 lore raw
Commit-ID:  b5d9d734a53e0204aab0089079cbde2a1285a38f
Gitweb:     http://git.kernel.org/tip/b5d9d734a53e0204aab0089079cbde2a1285a38f
Author:     Mike Galbraith <[email protected]>
AuthorDate: Tue, 8 Sep 2009 11:12:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 8 Sep 2009 13:15:34 +0200

sched: Ensure that a child can't gain time over it's parent after fork()

A fork/exec load is usually "pass the baton", so the child should never be placed behind the parent. With START_DEBIT we make room for the new task, but with child_runs_first, that room comes out of the _parent's_ hide. There's nothing to say that the parent wasn't ahead of min_vruntime at fork() time, which means that the "baton carrier", who is essentially the parent in drag, can gain time and increase scheduling latencies for waiters.

With NEW_FAIR_SLEEPERS + START_DEBIT + child_runs_first enabled, we essentially pass the sleeper fairness off to the child, which is fine, but if we don't base placement on the parent's updated vruntime, we can end up compounding latency woes if the child itself then does fork/exec. The debit incurred at fork doesn't hurt the parent who is then going to sleep and maybe exit, but the child who acquires the error harms all comers.

This improves latencies of make -j<n> kernel build workloads.

LKML-Reference: <new-submission>

---
 kernel/sched_fair.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
kernel/sched_fair.c +5 -3
index cc97ea4..e386e5d 100644
@@ -728,11 +728,11 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
 
 			vruntime -= thresh;
 		}
-
-		/* ensure we never gain time by being placed backwards. */
-		vruntime = max_vruntime(se->vruntime, vruntime);
 	}
 
+	/* ensure we never gain time by being placed backwards. */
+	vruntime = max_vruntime(se->vruntime, vruntime);
+
 	se->vruntime = vruntime;
 }
 
@@ -1756,6 +1756,8 @@ static void task_new_fair(struct rq *rq, struct task_struct *p)
 	sched_info_queued(p);
 
 	update_curr(cfs_rq);
+	if (curr)
+		se->vruntime = curr->vruntime;
 	place_entity(cfs_rq, se, 1);
 
 	/* 'curr' will be NULL if the child belongs to a different group */
#1 lore raw
Quoted 7 lines · tip-bot for Mike Galbraith
Commit-ID:  b5d9d734a53e0204aab0089079cbde2a1285a38f
Gitweb:     http://git.kernel.org/tip/b5d9d734a53e0204aab0089079cbde2a1285a38f
Author:     Mike Galbraith <[email protected]>
AuthorDate: Tue, 8 Sep 2009 11:12:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 8 Sep 2009 13:15:34 +0200
Quoted 5 lines

sched: Ensure that a child can't gain time over it's parent after fork()

This improves latencies of make -j<n> kernel build workloads.

Jens, mind trying this patch (or latest tip:master) with your make -j4 workload, does it improve in any way?

Ingo

#2 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 7 lines · tip-bot for Mike Galbraith
Commit-ID:  b5d9d734a53e0204aab0089079cbde2a1285a38f
Gitweb:     http://git.kernel.org/tip/b5d9d734a53e0204aab0089079cbde2a1285a38f
Author:     Mike Galbraith <[email protected]>
AuthorDate: Tue, 8 Sep 2009 11:12:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 8 Sep 2009 13:15:34 +0200
Quoted 8 lines
Quoted 5 lines

sched: Ensure that a child can't gain time over it's parent after fork()

This improves latencies of make -j<n> kernel build workloads.

Jens, mind trying this patch (or latest tip:master) with your make -j4 workload, does it improve in any way?

Already booted it, makes no real difference... I'm trying with NO_HZ disabled now to see if that changes the picture.

Signature · 1 line
Jens Axboe
#3 lore raw
Quoted 15 lines · Jens Axboe
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · tip-bot for Mike Galbraith
Commit-ID:  b5d9d734a53e0204aab0089079cbde2a1285a38f
Gitweb:     http://git.kernel.org/tip/b5d9d734a53e0204aab0089079cbde2a1285a38f
Author:     Mike Galbraith <[email protected]>
AuthorDate: Tue, 8 Sep 2009 11:12:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 8 Sep 2009 13:15:34 +0200

sched: Ensure that a child can't gain time over it's parent after fork()

This improves latencies of make -j<n> kernel build workloads.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Jens, mind trying this patch (or latest tip:master) with your make -j4 workload, does it improve in any way?

Already booted it, makes no real difference... I'm trying with NO_HZ disabled now to see if that changes the picture.

Oh well, BTTODB. Thanks for trying it out.

-Mike