216
Listing 12-9. Example of writing to persistent memory using Valgrind macros
without flushing
33 #include
34 #include
35 #include
36 #include
37
38 int main(int argc, char *argv[]) {
39
int fd, *data;
40
41
// open the file and allocate enough space for an
42
// integer
43
fd = open("/mnt/pmem/file", O_CREAT|O_RDWR, 0666);
44
posix_fallocate(fd, 0, sizeof(int));
45
46
// memory map the file and register the mapped
47
// memory with VALGRIND
48
data = (int *) mmap(NULL, sizeof(int),
49
PROT_READ|PROT_WRITE,
50
MAP_SHARED_VALIDATE | MAP_SYNC,
51
fd, 0);
52
VALGRIND_PMC_REGISTER_PMEM_MAPPING(data,
53
sizeof(int));
54
55
// write to pmem
56
*data = 1234;
57
58
// unmap the memory and un-register it with
59
// VALGRIND
60
munmap(data, sizeof(int));
61
VALGRIND_PMC_REMOVE_PMEM_MAPPING(data,
62
sizeof(int));
63
return 0;
64 }
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 240/457

Suivant