53
space. Pointer pmemaddr is set to the beginning of that region. The
pmem_map_file function can also be used for memory mapping diskbased files through kernel main memory as well as directly mapping
persistent memory, so is_pmem is set to TRUE if the file resides on
persistent memory and FALSE if mapped through main memory.
• Line 72: We write a string into persistent memory.
• Lines 75-78: If the file resides on persistent memory, the pmem_
persist function uses the user space machine instructions
(described in Chapter 2) to ensure our string is flushed through
CPU cache levels to the power-fail safe domain and ultimately to
persistent memory. If our file resided on disk-based storage, Linux
mmap or Windows FlushViewOfFile would be used to flushed to
storage. Note that we can pass small sizes here (the size of the string
written is used in this example) instead of requiring flushes at page
granularity when using msync() or FlushViewOfFile().
• Line 81: Finally, we unmap the persistent memory region.
Summary
Figure 3-6 shows the complete view of the operating system support that this chapter
describes. As we discussed, an application can use persistent memory as a fast SSD,
more directly through a persistent memory-aware file system, or mapped directly into
the application’s memory space with the DAX option. DAX leverages operating system
services for memory-mapped files but takes advantage of the server hardware’s ability
to map persistent memory directly into the application’s address space. This avoids the
need to move data between main memory and storage. The next few chapters describe
considerations for working with data directly in persistent memory and then discuss the
APIs for simplifying development.
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
space. Pointer pmemaddr is set to the beginning of that region. The
pmem_map_file function can also be used for memory mapping diskbased files through kernel main memory as well as directly mapping
persistent memory, so is_pmem is set to TRUE if the file resides on
persistent memory and FALSE if mapped through main memory.
• Line 72: We write a string into persistent memory.
• Lines 75-78: If the file resides on persistent memory, the pmem_
persist function uses the user space machine instructions
(described in Chapter 2) to ensure our string is flushed through
CPU cache levels to the power-fail safe domain and ultimately to
persistent memory. If our file resided on disk-based storage, Linux
mmap or Windows FlushViewOfFile would be used to flushed to
storage. Note that we can pass small sizes here (the size of the string
written is used in this example) instead of requiring flushes at page
granularity when using msync() or FlushViewOfFile().
• Line 81: Finally, we unmap the persistent memory region.
Summary
Figure 3-6 shows the complete view of the operating system support that this chapter
describes. As we discussed, an application can use persistent memory as a fast SSD,
more directly through a persistent memory-aware file system, or mapped directly into
the application’s memory space with the DAX option. DAX leverages operating system
services for memory-mapped files but takes advantage of the server hardware’s ability
to map persistent memory directly into the application’s address space. This avoids the
need to move data between main memory and storage. The next few chapters describe
considerations for working with data directly in persistent memory and then discuss the
APIs for simplifying development.
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
