Re: memory barrier question

From: Miklos Szeredi
Date: Mon Sep 20 2010 - 12:02:18 EST


On Sun, 19 Sep 2010, Paul E. McKenney wrote:
> > > Again, please put at least an ACCESS_ONCE() in. Trivial to do now,
> > > possibly saving much pain and headache later on.
> >
> > OK, lost you here. ACCESS_ONCE() is only needed in certain situations
> > (like list traversal) because some compilers can reload cached values
> > across an explicit barrier (which isn't here).
>
> ACCESS_ONCE() also tells the compiler not to try to guess.

If the code is written like this:

if (ACCESS_ONCE(dentry->d_inode)) {
blah = dentry->d_inode->i_some_field
...
}

does the compiler guarantee anything or does it need a full compiler
barrier to prevent reordering?

Because that pattern is, again, pretty much all over the place. Yeah
it can be rewritten but that's not always feasable since it's
difficult to audit, would possibly need extra function arguments,
etc...

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