60
memory, however, allows direct access, which removes the kernel from the data path
once the file is memory mapped.
As a programmer, you may be tempted to map persistent memory and start using it,
as shown in the Chapter 3 examples. For production-quality programming, you want to
ensure these start-time responsibilities are met. For example, if you skip the checks in
Figure 2-5, you will end up with an application that flushes CPU caches even when it is
not required, and that will perform poorly on hardware that does not need the flushing.
If you skip the checks in Figure 2-6, you will have an application that ignores media
errors and may use corrupted data resulting in unpredictable and undefined behavior.
Tuning for Hardware Configurations
When storing a large data structure to persistent memory, there are several ways to copy
the data and make it persistent. You can either copy the data using the common store
operations and then flush the caches (if required) or use special instructions like Intel’s
non-temporal store instructions that bypass the CPU caches. Another consideration
is that persistent memory write performance may be slower than writing to normal
memory, so you may want to take steps to store to persistent memory as efficiently as
possible, by combining multiple small writes into larger changes before storing them to
persistent memory. The optimal write size for persistent memory will depend on both
the platform it is plugged into and the persistent memory product itself. These examples
show that different platforms will have different characteristics when using persistent
memory, and any production-quality application will be tuned to perform best on the
intended target platforms. Naturally, one way to help with this tuning work is to leverage
libraries or middleware that has already been tuned and validated.
Summary
This chapter provides an overview of the fundamental concepts of persistent memory
programming. When developing an application that uses persistent memory, you must
carefully consider several areas:
• Atomic updates.
• Flushing is not transactional.
Chapter 4 Fundamental ConCepts oF persistent memory programming
memory, however, allows direct access, which removes the kernel from the data path
once the file is memory mapped.
As a programmer, you may be tempted to map persistent memory and start using it,
as shown in the Chapter 3 examples. For production-quality programming, you want to
ensure these start-time responsibilities are met. For example, if you skip the checks in
Figure 2-5, you will end up with an application that flushes CPU caches even when it is
not required, and that will perform poorly on hardware that does not need the flushing.
If you skip the checks in Figure 2-6, you will have an application that ignores media
errors and may use corrupted data resulting in unpredictable and undefined behavior.
Tuning for Hardware Configurations
When storing a large data structure to persistent memory, there are several ways to copy
the data and make it persistent. You can either copy the data using the common store
operations and then flush the caches (if required) or use special instructions like Intel’s
non-temporal store instructions that bypass the CPU caches. Another consideration
is that persistent memory write performance may be slower than writing to normal
memory, so you may want to take steps to store to persistent memory as efficiently as
possible, by combining multiple small writes into larger changes before storing them to
persistent memory. The optimal write size for persistent memory will depend on both
the platform it is plugged into and the persistent memory product itself. These examples
show that different platforms will have different characteristics when using persistent
memory, and any production-quality application will be tuned to perform best on the
intended target platforms. Naturally, one way to help with this tuning work is to leverage
libraries or middleware that has already been tuned and validated.
Summary
This chapter provides an overview of the fundamental concepts of persistent memory
programming. When developing an application that uses persistent memory, you must
carefully consider several areas:
• Atomic updates.
• Flushing is not transactional.
Chapter 4 Fundamental ConCepts oF persistent memory programming
