58
Consistency
Consistency means that a transaction can only move a data structure from one valid
state to another. For persistent memory, programmers usually find that the locking they
use to make updates thread-safe often indicates consistency points as well. If it is not
valid for a thread to see an intermediate state, locking prevents it from happening, and
when it is safe to drop the lock, that is because it is safe for another thread to observe the
current state of the data structure.
Isolation
Multithreaded (concurrent) execution is commonplace in modern applications. When
making transactional updates, the isolation is what allows the concurrent updates
to have the same effect as if they were executed sequentially. At runtime, isolation
for persistent memory updates is typically achieved by locking. Since the memory is
persistent, the isolation must be considered for transactions that were in-flight when
the application was interrupted. Persistent memory programmers typically detect
this situation on restart and roll partially done transactions forward or backward
appropriately before allowing general-purpose threads access to the data structures.
Durability
A transaction is considered durable if it is on persistent media when it is complete. Even if the
system loses power or crashes at that point, the transaction remains completed. As described
in Chapter 2, this usually means the changes must be flushed from the CPU caches. This can
be done using standard APIs, such as the Linux msync() call, or platform-specific instructions
such as Intel’s CLWB. When implementing transactions on persistent memory, pay careful
attention to ensure that log entries are flushed to persistence before changes are started and
flush changes to persistence before a transaction is considered complete.
Another aspect of the durable property is the ability to find the persistent
information again when an application starts up. This is so fundamental to how storage
works that we take it for granted. Metadata such as file names and directory names are
used to find the durable state of an application on storage. For persistent memory, the
same is true due to the programming model described in Chapter 3, where persistent
memory is accessed by first opening a file on a direct access (DAX) file system and then
memory mapping that file. However, a memory-mapped file is just a range of raw data;
Chapter 4 Fundamental ConCepts oF persistent memory programming
Consistency
Consistency means that a transaction can only move a data structure from one valid
state to another. For persistent memory, programmers usually find that the locking they
use to make updates thread-safe often indicates consistency points as well. If it is not
valid for a thread to see an intermediate state, locking prevents it from happening, and
when it is safe to drop the lock, that is because it is safe for another thread to observe the
current state of the data structure.
Isolation
Multithreaded (concurrent) execution is commonplace in modern applications. When
making transactional updates, the isolation is what allows the concurrent updates
to have the same effect as if they were executed sequentially. At runtime, isolation
for persistent memory updates is typically achieved by locking. Since the memory is
persistent, the isolation must be considered for transactions that were in-flight when
the application was interrupted. Persistent memory programmers typically detect
this situation on restart and roll partially done transactions forward or backward
appropriately before allowing general-purpose threads access to the data structures.
Durability
A transaction is considered durable if it is on persistent media when it is complete. Even if the
system loses power or crashes at that point, the transaction remains completed. As described
in Chapter 2, this usually means the changes must be flushed from the CPU caches. This can
be done using standard APIs, such as the Linux msync() call, or platform-specific instructions
such as Intel’s CLWB. When implementing transactions on persistent memory, pay careful
attention to ensure that log entries are flushed to persistence before changes are started and
flush changes to persistence before a transaction is considered complete.
Another aspect of the durable property is the ability to find the persistent
information again when an application starts up. This is so fundamental to how storage
works that we take it for granted. Metadata such as file names and directory names are
used to find the durable state of an application on storage. For persistent memory, the
same is true due to the programming model described in Chapter 3, where persistent
memory is accessed by first opening a file on a direct access (DAX) file system and then
memory mapping that file. However, a memory-mapped file is just a range of raw data;
Chapter 4 Fundamental ConCepts oF persistent memory programming
