Question about the semantics of sfence/clwb

54 views
Skip to first unread message

Hayley LeBlanc

unread,
Oct 28, 2020, 3:26:44 PM10/28/20
to pmem
Hi folks,

I have a question about when writes ordered with sfence/flushed with clwb will be flushed to persistent memory. I basically want to make sure that my understanding of how these instructions work is correct. Suppose A and B are two addresses in persistent memory. If we do the following operations:

Write to A
sfence
Write to B
clwb(B)
sfence

What guarantees do the use of sfence and clwb make about when the data written to A and B is made persistent? My thought is that clwb(B); sfence would immediately flush the data at B to PM. Since the write to A is ordered before the write to B with the first sfence, the write to A would also be made persistent at this point. Is this correct?

Thanks,
Hayley LeBlanc

Andy Rudoff

unread,
Oct 28, 2020, 4:10:00 PM10/28/20
to pmem
Hi Hayley,

To keep this answer simple, let's assume that both stores are normal, write-back cached memory stores and that A and B are in different 64-byte cache lines.

Remember that the order of visibility is not necessarily the same as the order of persistence.  In your example, you never take steps to make A persistent.  I agree that B will become globally-visible after A.  Even without the first SFENCE instruction that's true because of Total Store Ordering (TSO).  But the store to A may or may not be sitting in the cache after the CLWB+SFENCE that flushes B.  The only way to ensure the order of persistence is the same as the store order would be to insert a CLWB A after storing to A in your example.

Thanks,

-andy

Reply all
Reply to author
Forward
0 new messages