Re: [PATCH] Fix race between attach_task and cpuset_exit

Srivatsa Vaddagiri
2007-03-26T11:43:20Z

On Sun, Mar 25, 2007 at 11:22:15PM +0530, Balbir Singh wrote:
> >+ struct cpuset *oldcs_tobe_released = NULL;
>
> How about oldcs_to_be_released?

Yes, I wanted to use that, but my typo I guess.

> >@@ -2242,19 +2241,20 @@ void cpuset_exit(struct task_struct *tsk
> > {
> > struct cpuset *cs;
> >
> >+ task_lock(tsk);
> > cs = tsk->cpuset;
> > tsk->cpuset = &top_cpuset; /* the_top_cpuset_hack - see above */
> >+ atomic_dec(&cs->count);
>
> How about using a local variable like ref_count and using
>
> ref_count = atomic_dec_and_test(&cs->count); This will avoid the two
> atomic operations, atomic_dec() and atomic_read() below.

Well, someone may have attached to this cpuset while we were waiting on the
mutex_lock(). So we need to do a atomic_read again to ensure it is still
unused. But I notice that check_for_release() has that
atomic_read-and-check-for-zero-refcount inbuilt into it, which means we can
blindly call it. Modified patch in another mail.

--
Regards,
vatsa