SLIDE 1
Paweł Lebioda, Tomasz Kapela
SLIDE 2 2
Agenda
Introduction:
- Persistent Memory
- NVML
- PMEMCHECK
Tutorial:
- Kernel support
- NVML overview
- libpmem
- libpmemblk
- libpmemobj C API
- libpmemobj C++ API
- PMEMCHECK
SLIDE 3
Just a little bit of theory...
SLIDE 4
What is it ?
SLIDE 5 5
Persistent Memory
What is Persistent Memory ?
- Non-volatile
- Retains data without power
- Byte addressable
- Load/Store access
- Memory-like performance
- DMA-able
- NVDIMM
SLIDE 6 6
Persistent Memory use cases
- Block storage
- Volatile Memory
- Persistent Memory aware filesystem
- Persistent Memory aware applications
SLIDE 7 7
Persistent Memory characteristics
- Stores are not durable
- The data must be flushed
- 8-byte atomicity
- Virtual address may change
SLIDE 8 8
Persistent Memory kernel support
- NVDIMM subsystem
- DAX (Direct Access)
- ndctl – github.com/pmem/ndctl
- DAX support in ext2, ext4, xfs
SLIDE 9
Non-Volatile Memory Libraries https://github.com/pmem/nvml
SLIDE 10 10
Persistent Memory Programming Model
SLIDE 11 11
NVML introduction
- Set of user-space libraries
- PMEM-aware applications
- Source code on github - github.com/pmem/nvml
- BSD license
- Web page - pmem.io
- Distros (Fedora, openSUSE)
SLIDE 12 12
NVML libraries
Library Description libvmem Volatile memory allocator libvmmalloc malloc() replacement using libvmem libpmem Low-level support for persistence libpmemlog Append only log structure libpmemblk Atomic access to memory blocks libpmemobj Transactional object store libpmempool Managing library
SLIDE 13 „In theory, theory and practice are the same. In practice, they are not”
Albert Einstein
SLIDE 14
How to configure my Linux OS for persistent memory ?
SLIDE 15 15
Kernel support
- Kernel config: NVDIMM, DAX
- Persistent memory emulation:
– http://pmem.io/2016/02/22/pm-emulation.html – X86_PMEM_LEGACY – Memmap=<size>!<offset>
- Create filesystem
- Mount with DAX
SLIDE 16 16
Persistent Memory configuration
SLIDE 17
Quick insight into source tree
SLIDE 18 18
NVML overview
- Source tree organization
- Building
- Running tests
- Examples
- Packages
SLIDE 19 19
NVML packages
SLIDE 20
Low level persistent memory support
SLIDE 21 21
libpmem examples
- How to check if memory is Persistent Memory ?
- How to access Persistent Memory ?
- Debug library and log messages
- How to make memory persistent ?
- Running examples under Valgrind pmemcheck
SLIDE 22 22
How to check if memory is Persistent Memory ?
SLIDE 23 23
How to access Persistent Memory ?
SLIDE 24 24
Running pmem_is_pmem example
SLIDE 25 25
libpmem: turning on log messages
SLIDE 26 26
libpmem: pmem_persist - 1
SLIDE 27 27
libpmem: pmem_persist - 2
SLIDE 28
Persistent Memory aware tool for Valgrind github.com/pmem/valgrind
SLIDE 29 29
PMEMCHECK
- Valgrind tool
- Need to build nvml with special flags
- Checks correctness of persistent memory usage
- Checking data persistence
- Support for transactions (libpmemobj)
- NVML: make EXTRA_CFLAGS=-DUSE_VALGRIND
SLIDE 30 30
libpmem: valgrind support
SLIDE 31 31
libpmem: pmem_persist + valgrind pmemcheck
SLIDE 32 32
libpmem: pmem_persist - 2
SLIDE 33
Persistent Memory pools utils
SLIDE 34 34
pmempool: available commands
SLIDE 35
Persistent Memory resident array of blocks
SLIDE 36 36
Libpmemblk: examples
- Pmempool introduction
- Creating pmemblk pool with pmempool
- Opening pmemblk pool
- Reading pool parameters
- Reading and writing blocks
SLIDE 37 37
pmempool: create command
SLIDE 38 38
Opening pmemblk pool
SLIDE 39 39
Reading and writing block
SLIDE 40 40
libpmempool: running example
SLIDE 41
Persistent Memory Transactional Object Store
SLIDE 42 42
libpmemobj
- Creating pmemobj pool with pmempool
- Opening pmemobj pool
- PMEMoid – persistent memory pointer
- Root object
- Allocations
SLIDE 43 43
Libpmemobj: simple example
- Application which stores list of people
- Stores first and last name
- Constant size array
SLIDE 44 44
Data structures
SLIDE 45 45
Main function
SLIDE 46 46
List of people
SLIDE 47 47
Insert function - 1
SLIDE 48 48
Insert function - 2
SLIDE 49 49
Object’s constructor
SLIDE 50 50
Clear function
SLIDE 52 52
Running example
SLIDE 53 53
Missing persist
SLIDE 54 54
Valgrind pmemcheck
SLIDE 55 55
libpmemobj: type safety macros
- PMEMoid as void *
- Type safety macros for convenience
- No need to track persistent and volatile pointers
SLIDE 56 56
Type safety macros: data structures
SLIDE 57 57
Type safety macros: insert function
SLIDE 58 58
Type safety macros: clear function
SLIDE 59 59
libpmemobj: foreach macros
- API for traversing through all objects
- Foreach object per type
- Useful for recovery actions
- Avoids persistent memory leaks
SLIDE 60 60
Foreach type macro
SLIDE 61 61
libpmemobj: atomic lists API
- Circular doubly linked list
- Atomic operations
- sys/queue – like API
- Useful for hybrid persistent-volatile data structures
SLIDE 62 62
atomic lists API: data structures
SLIDE 63 63
Atomic lists API: insert function
SLIDE 64 64
Atomic lists: clear function
SLIDE 65 65
Atomic lists API: listing people
SLIDE 66 66
Atomic lists API: recovery
SLIDE 67 67
libpmemobj: transactions
- Most generic API
- No need for recovery
- Convenient macros
- Operations:
– Alloc – Free – Modify
SLIDE 68 68
Transactions: data structures
SLIDE 69 69
Transactions: insert function
SLIDE 70 70
Transactions: entry initialization
SLIDE 71 71
Transactions: inserting elements
SLIDE 72 72
Transactions: clear function
SLIDE 73 73
Transactions: listing people
SLIDE 74 74
Transactions: valgrind pmemcheck
SLIDE 75 75
Transactions: valgrind pmemcheck
SLIDE 76 76
C++ API
- Using language features
- Overloading operators
- Hiding required operations
- Scope transactions
- Lambda
SLIDE 77 77
C++ API: main function
SLIDE 78 78
C++ API: list of people class
SLIDE 79 79
C++ API: listing people
SLIDE 80 80
C++ API: insert function
SLIDE 81 81
C++ API: clear function
SLIDE 82 82
C++ API: list entry class
SLIDE 83 83
C++ API: persistent string
SLIDE 84 84
C++ API: valgrind pmemcheck
SLIDE 85 85
C++ API: valgrind pmemcheck - 1
SLIDE 86 86
C++ API: valgrind pmemcheck - 2
SLIDE 87 87
C++ STL
- STL allocator concept for libpmemobj
- Using STL containers
- Need some changes in std libraries
SLIDE 88 88
C++ STL: list of people class
SLIDE 89 89
C++ STL: list entry class
SLIDE 90
SLIDE 91