Skip to contentSkip to conversation

scheduler: first timeslice of the exiting thread

BUG Oleg Nesterov 2 participants 3 messages Apr 9, 2007 – Apr 10, 2007

lore
Share & tools
lore
#0 lore raw
Quoted 11 lines · Satoru Takeuchi

a) On sched_fork, the creator share its timeslice with new process.
b) On sched_exit, if the exiting process didn't exhaust its first timeslice yet, it gives its timeslice to the parent.

It has no problem on the process model since the creator is the parent. However, on the thread model, the creator is not the parent, it is same as the creator's parent. Hence, on this kind of program, the creator can't retrieve shared timeslice and exausts its timeslice at a rate of knots. In addition, somehow, the parent (typically shell?) gets extra timeslice.

Yes, this is an old oddity.

Quoted 4 lines

I believe it's a bug and the exiting process should give its timeslice to the creator. Now I have some patch plan to fix this problem as follow:

a) Add the field for the creator to task_struct. It needs extra memory.

... and locking/complications. The creator may already exited at this time.

Quoted 3 lines

b) Doesn't add extra field and have thread's parent the creater, which is same as process creation. However it has many side effects, for example, we also need to change sys_getppid() implementation.

can't understand this, sorry.

Ingo, I think sched_exit() has another buglet,

	if (unlikely(p->parent->time_slice > task_timeslice(p)))
		p->parent->time_slice = task_timeslice(p);

should be

	if (unlikely(parent->time_slice > task_timeslice(parent)))
		parent->time_slice = task_timeslice(parent);

The

	[PATCH 1/2] sched_exit: fix parent->time_slice calculation
	http://marc.info/?l=linux-kernel&m=115101842505365

was dropped because "[PATCH 2/2]" was very wrong.

Could you look at it?

Oleg.

#1 lore raw
Quoted 7 lines · Oleg Nesterov
Quoted 5 lines · Satoru Takeuchi

a) On sched_fork, the creator share its timeslice with new process.
b) On sched_exit, if the exiting process didn't exhaust its first timeslice yet, it gives its timeslice to the parent.

Quoted 8 lines
Quoted 6 lines

It has no problem on the process model since the creator is the parent. However, on the thread model, the creator is not the parent, it is same as the creator's parent. Hence, on this kind of program, the creator can't retrieve shared timeslice and exausts its timeslice at a rate of knots. In addition, somehow, the parent (typically shell?) gets extra timeslice.

Yes, this is an old oddity.

Perhaps

	void sched_exit(struct task_struct *p)
	{
		task_t *t, *did_fork = p->parent;

		if (!thread_group_leader(p))
			list_for_each_entry(t, p->thread_group)
				if (!t->exit_state) {
					did_fork = t;
					break;
				}

		... give time_slice to did_fork ..
	}

may improve things a little bit, because the rest of time_slice doesn't leak off the thread group.

However this is not very nice and we have the same problem with CLONE_PARENT.

Oleg.

#2 lore raw
In reply to Oleg Nesterov
Quoted 5 lines
Quoted 3 lines

b) Doesn't add extra field and have thread's parent the creater, which is same as process creation. However it has many side effects, for example, we also need to change sys_getppid() implementation.

can't understand this, sorry.

Sorry for my obscure English, perhaps I need more training about writing.

What I meant is ...

If thread A creates thread B and A's parent is C, B's parent is also C currently. In my idea (b), copy_process() doesn't varies B's parent by CLONE_THREAD flag and B's parent is A. In this case, there is no need to change sched_exit() and doesn't need to add extra field. However, we need to change other code as sysy_getppid(), forget_original_parent(), and so on.

It's same as past linux kernel behavior. I don't know the details when and why these code was changed (and this problem was overlooked then). Once I thought I came up with good idea, but now I'm rocking back on my heels because it seems to need many code change.

Satoru