Re: Question about memory barriers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>>>>> "Alan" == Alan Stern <[email protected]> writes:

    Alan> The kernel's documentation about memory barriers is rather
    Alan> skimpy.  I gather that rmb() guarantees that all preceding
    Alan> reads will have completed before any following reads are
    Alan> made, and wmb() guarantees that all preceding writes will
    Alan> have completed before any following writes are made.  I also
    Alan> gather that mb() is essentially the same as rmb() and wmb()
    Alan> put together.

Most of this is correct, except that mb() is stronger than just rmb()
and wmb() put together.  All memory operations before the mb() will
complete before any operations after the mb().  A better way to
understand this is to look at the sparc64 definition:

#define mb()    \
        membar_safe("#LoadLoad | #LoadStore | #StoreStore | #StoreLoad")

    Alan> But suppose I need to prevent a read from being moved past a
    Alan> write?  It doesn't look like either rmb() or wmb() will do
    Alan> this.  And if mb() is the same as "rmb(); wmb();" then it
    Alan> won't either.  So what's the right thing to do?

As described above, mb() will work in this case.  It actually
guarantees more than you need, so you could conceivably define a new
primitive, but the current barriers are hard enough for people to
figure out ;)

 - R.
-
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/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux