Understanding of pmem_flush and pmem_drain api

35 views
Skip to first unread message

王涛

unread,
Aug 10, 2017, 7:59:24 AM8/10/17
to pmem
Hi, 

I have 3 questions about pmem_flush and pmem_drain.

1) My understanding is that pmem_flush guarantees the ordering of two sequential pmem writes because hardware 
    buffer works in order, and pmem_drain with a previous pmem_flush guarantees the persistency of a pmem write. 
    Is it right?

    a  power down happens during do_copy_to_pmem function, the content of pmem will be: a portion of well written content
    followed by a portion of torn written content. Is it right?

3) Is there any guarantees of persistent ordering within a single pmem_memcpy function? 

Thanks a lot~

Tao

Krzysztof Czurylo

unread,
Aug 10, 2017, 10:03:09 AM8/10/17
to pmem


On Thursday, August 10, 2017 at 1:59:24 PM UTC+2, 王涛 wrote:
Hi, 

I have 3 questions about pmem_flush and pmem_drain.

1) My understanding is that pmem_flush guarantees the ordering of two sequential pmem writes because hardware 
    buffer works in order, and pmem_drain with a previous pmem_flush guarantees the persistency of a pmem write. 
    Is it right?

The pmem_flush does not guarantee any memory ordering, only pmem_drain (or pmem_persist) does.
Same applies to pmem_memcpy_nodrain/pmem_memset_nodrain. These functions do not guarantee
any write ordering with respect to previous/next memcpy/memset operations.
 
    a  power down happens during do_copy_to_pmem function, the content of pmem will be: a portion of well written content
    followed by a portion of torn written content. Is it right?

In such case, you can't do any assumptions on which portion of the data is written to persistence or not.
If pmem_memcpy_nodrain would be replaced with pmem_memcpy_persist, or if you put pmem_drain after each call
to memcpy (inside while loop), then (because data is copied in 4K chunks), you may assume N blocks of 4K
were fully written, one is partially written (see below) and the remaining blocks contain old data.
 

3) Is there any guarantees of persistent ordering within a single pmem_memcpy function? 

Nope. In case of power failure, you may see the old (o) and new (x) data mixed in any order.
xxxooooo - likely, but not guaranteed
xxxoxooo - could be this...
ooooooxx - ... or that

 
Thanks a lot~

Tao

王涛

unread,
Aug 12, 2017, 8:31:58 AM8/12/17
to pmem
OK, I got it, thanks very much!

在 2017年8月10日星期四 UTC+8下午10:03:09,Krzysztof Czurylo写道:
Reply all
Reply to author
Forward
0 new messages