52
66
perror("pmem_map_file");
67
exit(1);
68
}
69
70
/* Store a string to the persistent memory. */
71
char s[] = "This is new data written to the file";
72
strcpy(pmemaddr, s);
73
74
/* Flush our string to persistence. */
75
if (is_pmem)
76
pmem_persist(pmemaddr, sizeof(s));
77
else
78
pmem_msync(pmemaddr, sizeof(s));
79
80
/* Delete the mappings. */
81
pmem_unmap(pmemaddr, mapped_len);
82
83
printf("Done.\n");
84
exit(0);
85 }
• Lines 38-42: We handle the differences between Linux and Windows
for the include files.
• Line 44: We include the header file for the libpmem API used in this
example.
• Lines 56-60: We take the pathname argument from the command
line argument.
• Line 63-68: The pmem_map_file function in libpmem handles
opening the file and mapping it into our address space on both
Windows and Linux. Since the file resides on persistent memory, the
operating system programs the hardware MMU in the CPU to map
the persistent memory region into our application’s virtual address
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
66
perror("pmem_map_file");
67
exit(1);
68
}
69
70
/* Store a string to the persistent memory. */
71
char s[] = "This is new data written to the file";
72
strcpy(pmemaddr, s);
73
74
/* Flush our string to persistence. */
75
if (is_pmem)
76
pmem_persist(pmemaddr, sizeof(s));
77
else
78
pmem_msync(pmemaddr, sizeof(s));
79
80
/* Delete the mappings. */
81
pmem_unmap(pmemaddr, mapped_len);
82
83
printf("Done.\n");
84
exit(0);
85 }
• Lines 38-42: We handle the differences between Linux and Windows
for the include files.
• Line 44: We include the header file for the libpmem API used in this
example.
• Lines 56-60: We take the pathname argument from the command
line argument.
• Line 63-68: The pmem_map_file function in libpmem handles
opening the file and mapping it into our address space on both
Windows and Linux. Since the file resides on persistent memory, the
operating system programs the hardware MMU in the CPU to map
the persistent memory region into our application’s virtual address
Chapter 3 Operating SyStem SuppOrt fOr perSiStent memOry
