214
Common Persistent Memory Programming
Problems
This section reviews several coding and performance problems you are likely to
encounter, how to catch them using the pmemcheck and Intel Inspector tools, and how to
resolve the issues.
The tools we use highlight deliberately added issues in our code that can cause
bugs, data corruption, or other problems. For pmemcheck, we show how to bypass data
sections that should not be checked by the tool and use macros to assist the tool in better
understanding our intent.
Nonpersistent Stores
Nonpersistent stores refer to data written to persistent memory but not flushed explicitly.
It is understood that if the program writes to persistent memory, it wishes for those
writes to be persistent. If the program ends without explicitly flushing writes, there is an
open possibility for data corruption. When a program exits gracefully, all the pending
writes in the CPU caches are flushed automatically. However, if the program were to
crash unexpectedly, writes still residing in the CPU caches could be lost.
Consider the code in Listing 12-7 that writes data to a persistent memory device
mounted to /mnt/pmem without flushing the data.
Listing 12-7. Example of writing to persistent memory without flushing
32 #include
33 #include
34 #include
35
36 int main(int argc, char *argv[]) {
37
int fd, *data;
38
fd = open("/mnt/pmem/file", O_CREAT|O_RDWR, 0666);
39
posix_fallocate(fd, 0, sizeof(int));
40
data = (int *) mmap(NULL, sizeof(int), PROT_READ |
41
PROT_WRITE, MAP_SHARED_VALIDATE |
42
MAP_SYNC, fd, 0);
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 238/457

Suivant