lkml.org 
[lkml]   [2012]   [Nov]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 9/9 v2] cgroup_freezer: implement proper hierarchy support
On Thu 08-11-12 06:18:48, Tejun Heo wrote:
> Hello, Michal.
>
> On Thu, Nov 08, 2012 at 03:08:52PM +0100, Michal Hocko wrote:
> > This seems to be racy because parent->state access is not linearized.
> > Say we have parallel freeze and thawing on a tree like the following:
> > A
> > |
> > B
> > |
> > C
> >
> > pre_order will visit them in B, C order.
> > CPU1 CPU2
> > freezer_apply_state(A, true)
> > A->state & FREEZING == true freezer_apply_state(A, false)
> > A->state & FREEZING == false
> > freezer_apply_state(B, false)
> > B->state & FREEZING == false
> > freezer_apply_state(B, true)
> >
> > B->state & FREEZING == true
> > freezer_apply_state(C, true)
> > freezer_apply_state(C, false)
> >
> > So A, C are thawed while B is frozen. Or am I missing something which
> > would prevent from this kind of race?
>
> The rule is that there will be at least one inheritance operation
> after a parent is updated. The exact order of propagation doesn't
> matter as long as there's at least one inheritance event after the
> latest update to a parent. This works because inheritance operations
> are atomic to each other. If one inheritance operation "saw" an
> update to its parent, the next inheritance operation is guaranteed to
> see at least upto that update.
>
> So, in the above example in CPU2, (B->state & FREEZING) test and
> freezer_apply_state(C, false) can't be interleaved with the same
> inheritance operation from CPU1. They either happen before or after.

I am not sure I understand what you mean by inheritance operation but
you are right that the race is not possible because spin_lock makes
sure that Foo->state is done after the lock(Foo->child) and spin_unlock
then serves as a leave barrier so the other CPUs will see the correctly
updated value. The rest is handled by the fixed ordered tree walk. So
there is really no interleaving going on here.

Sorry about the confusion!

Feel free to add my Reviewed-by.
--
Michal Hocko
SUSE Labs


\
 
 \ /
  Last update: 2012-11-08 17:01    [W:0.086 / U:24.648 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site