215
43
*data = 1234;
44
munmap(data, sizeof(int));
45
return 0;
46 }
• Line 38: We open /mnt/pmem/file.
• Line 39: We make sure there is enough space in the file to allocate an
integer by calling posix_fallocate().
• Line 40: We memory map /mnt/pmem/file.
• Line 43: We write 1234 to the memory.
• Line 44: We unmap the memory.
If we run pmemcheck with Listing 12-7, we will not get any useful information
because pmemcheck has no way to know which memory addresses are persistent and
which ones are volatile. This may change in future versions. To run pmemcheck, we pass
--tool=pmemcheck argument to valgrind as shown in Listing 12-8. The result shows no
issues were detected.
Listing 12-8. Running pmemcheck with code Listing 12-7
$ valgrind --tool=pmemcheck ./listing_12-7
==116951== pmemcheck-1.0, a simple persistent store checker
==116951== Copyright (c) 2014-2016, Intel Corporation
==116951== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright
info
==116951== Command: ./listing_12-9
==116951==
==116951==
==116951== Number of stores not made persistent: 0
==116951== ERROR SUMMARY: 0 errors
We can inform pmemcheck which memory regions are persistent using a VALGRIND_
PMC_REGISTER_PMEM_MAPPING macro shown on line 52 in Listing 12-9. We must include
the valgrind/pmemcheck.h header for pmemcheck, line 36, which defines the VALGRIND_
PMC_REGISTER_PMEM_MAPPING macro and others.
Chapter 12 Debugging persistent MeMory appliCations
Précédent

- 239/457

Suivant