Skip to contentSkip to conversation

sched: sync with the prev cfs when changing cgroup within a cpu

PATCH Superseded [email protected] 2 participants 3 messages Aug 12, 2015 Scheduler

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 sched: sync with the prev cfs when changing cgroup within a cpu

From: Byungchul Park <[email protected]>

change from v2 to v3
* rebase to tip git

change from v1 to v2
* use #ifdef CONFIG_SMP to load tracking code
* make commit message compact which made confused

----->8-----

Quoted 1 line

From 31c4509d09cd43bf52c12ef85716aa4c3b729b57 Mon Sep 17 00:00:00 2001

From: Byungchul Park <[email protected]>
Date: Wed, 12 Aug 2015 15:51:21 +0900
Subject: [PATCH v3] sched: sync with the prev cfs when changing cgroup within
a cpu

current code seems to be wrong with cfs_rq's avg loads when changing a task's cgroup(=cfs_rq) to another. i tested with "echo pid > cgroup" and found that e.g. cfs_rq->avg.load_avg became larger and larger whenever i changed a cgroup to another again and again.

we have to sync se's average load with both *prev* cfs_rq and next cfs_rq when changing its group.

---
 kernel/sched/fair.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
kernel/sched/fair.c +22 -2
index 2a33d7b..25028b9 100644
@@ -8017,8 +8017,28 @@ static void task_move_group_fair(struct task_struct *p, int queued)
 	if (!queued && (!se->sum_exec_runtime || p->state == TASK_WAKING))
 		queued = 1;
 
-	if (!queued)
-		se->vruntime -= cfs_rq_of(se)->min_vruntime;
+	if (!queued) {
+		cfs_rq = cfs_rq_of(se);
+		se->vruntime -= cfs_rq->min_vruntime;
+
+#ifdef CONFIG_SMP
+		/*
+		 * synchronize task with its prev cfs_rq
+		 * remove our load when we leave
+		 */
+		__update_load_avg(cfs_rq->avg.last_update_time, cpu_of(rq_of(cfs_rq)), &se->avg,
+				se->on_rq * scale_load_down(se->load.weight), cfs_rq->curr == se, NULL);
+
+		cfs_rq->avg.load_avg =
+			max_t(long, cfs_rq->avg.load_avg - se->avg.load_avg, 0);
+		cfs_rq->avg.load_sum =
+			max_t(s64, cfs_rq->avg.load_sum - se->avg.load_sum, 0);
+		cfs_rq->avg.util_avg =
+			max_t(long, cfs_rq->avg.util_avg - se->avg.util_avg, 0);
+		cfs_rq->avg.util_sum =
+			max_t(s32, cfs_rq->avg.util_sum - se->avg.util_sum, 0);
+#endif
+	}
 	set_task_rq(p, task_cpu(p));
 	se->depth = se->parent ? se->parent->depth + 1 : 0;
 	if (!queued) {
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 9 lines · On Wed, Aug 12, 2015 at 04:05:15PM +0900, [email protected] wrote:

current code seems to be wrong with cfs_rq's avg loads when changing a task's cgroup(=cfs_rq) to another. i tested with "echo pid > cgroup" and found that e.g. cfs_rq->avg.load_avg became larger and larger whenever i changed a cgroup to another again and again.

we have to sync se's average load with both *prev* cfs_rq and next cfs_rq when changing its group.

I think you are right in general, it has nothing to do with migrate_task_rq_fair() and the load should be carried to new cfs_rq.

But whether it is queued or not should be doing the same thing, so what about:

/* if queued, the previous dequeue_task() should have already done it */ if (!queued)

	__upload_load_avg()

remove_from_old_cfs_rq();

/* virtually catch up because of the skew between cfs_rqs */ task's last_update_time = cfs_rq's last_update_time; add_to_new_cfs_rq();

Thanks,
Yuyang

#2 lore raw
Quoted 7 lines · Yuyang Du
Quoted 6 lines · On Wed, Aug 12, 2015 at 04:05:15PM +0900, [email protected] wrote:

current code seems to be wrong with cfs_rq's avg loads when changing a task's cgroup(=cfs_rq) to another. i tested with "echo pid > cgroup" and found that e.g. cfs_rq->avg.load_avg became larger and larger whenever i changed a cgroup to another again and again.

Quoted 8 lines
Quoted 3 lines

we have to sync se's average load with both *prev* cfs_rq and next cfs_rq when changing its group.

I think you are right in general, it has nothing to do with migrate_task_rq_fair() and the load should be carried to new cfs_rq.

But whether it is queued or not should be doing the same thing, so what about:

hello yuyang,

i worked with code based on torvalds git, but now.. in tip git where sched code is renewed much, i think you are right. i will fix it.

thank you much. :)
Byungchul

Quoted 18 lines

/* if queued, the previous dequeue_task() should have already done it */ if (!queued)

	__upload_load_avg()

remove_from_old_cfs_rq();

/* virtually catch up because of the skew between cfs_rqs */ task's last_update_time = cfs_rq's last_update_time; add_to_new_cfs_rq();

Thanks,
Yuyang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/