Beginning and experienced programmers will use this comprehensive guide to persistent memory programming. You will understand how persistent memory brings together several new software/hardware requirements, and offers great promise for better performance and faster application startup times—a huge leap forward in byte-addressable capacity compared with current DRAM offerings. This revolutionary new technology gives applications significant performance and capacity improvements over existing technologies. It requires a new way of thinking and developing, which makes this highly disruptive to the IT/computing industry. The full spectrum of industry sectors that will benefit from this technology include, but are not limited to, in-memory and traditional databases, AI, analytics, HPC, virtualization, and big data. Programming Persistent Memory describes the technology and why it is exciting the industry. It covers the operating system and hardware requirements as well as how to create development environments using emulated or real persistent memory hardware. The book explains fundamental concepts; provides an introduction to persistent memory programming APIs for C, C++, JavaScript, and other languages; discusses RMDA with persistent memory; reviews security features; and presents many examples. Source code and examples that you can run on your own systems are included. What You’ll Learn:
Understand what persistent memory is, what it does, and the value it brings to the industry
Become familiar with the operating system and hardware requirements to use persistent memory
Know the fundamentals of persistent memory programming: why it is different from current programming methods, and what developers need to keep in mind when programming for persistence
Look at persistent memory application development by example using the Persistent Memory Development Kit (PMDK)
Design and optimize data structures for persistent memory
Study how real-world applications are modified to leverage persistent memory
Utilize the tools available for persistent memory programming, application performance profiling, and debugging
Who This Book Is For: C, C++, Java, and Python developers, but will also be useful to software, cloud, and hardware architects across a broad spectrum of sectors, including cloud service providers, independent software vendors, high performance compute, artificial intelligence, data analytics, big data, etc.
Author(s): Steve Scargall
Publisher: Apress
Year: 2020
Language: English
Pages: 457
Tags: Computer Communication Networks
Table of Contents......Page 4
About the Author......Page 14
About the Technical Reviewer......Page 15
About the Contributors......Page 16
Acknowledgments......Page 20
Preface......Page 21
Chapter 1: Introduction to Persistent Memory Programming......Page 30
A High-Level Example Program......Page 31
What’s Different?......Page 34
The Performance Difference......Page 35
Program Complexity......Page 36
How Does libpmemkv Work?......Page 37
Summary......Page 38
Chapter 2: Persistent Memory Architecture......Page 40
Persistent Memory Characteristics......Page 41
Platform Support for Persistent Memory......Page 42
Cache Hierarchy......Page 43
Power-Fail Protected Domains......Page 45
The Need for Flushing, Ordering, and Fencing......Page 48
Data Visibility......Page 52
Intel Machine Instructions for Persistent Memory......Page 53
Detecting Platform Capabilities......Page 54
Application Startup and Recovery......Page 56
Summary......Page 58
Operating System Support for Memory and Storage......Page 60
Persistent Memory As Block Storage......Page 62
Persistent Memory-Aware File Systems......Page 63
Memory-Mapped Files......Page 64
Persistent Memory Direct Access (DAX)......Page 72
Summary......Page 82
What’s Different?......Page 84
Atomic Updates......Page 85
Atomicity......Page 86
Durability......Page 87
Start-Time Responsibilities......Page 88
Summary......Page 89
Background......Page 91
Choosing the Right Semantics......Page 92
libmemkind......Page 93
libvmemcache......Page 94
libpmem......Page 95
libpmemobj-cpp......Page 96
libpmemblk......Page 97
pmemcheck......Page 98
Summary......Page 99
Chapter 6: libpmem: Low-Level Persistent Memory Support......Page 101
Using the Library......Page 102
Mapping a File......Page 103
Copying to Persistent Memory......Page 104
Separating the Flush Steps......Page 105
Summary......Page 107
What is libpmemobj?......Page 108
Why not malloc()?......Page 109
Creating Memory Pools......Page 110
Pool Object Pointer (POP) and the Root Object......Page 114
Opening and Reading from Memory Pools......Page 115
Concatenated Poolsets......Page 117
Replica Poolsets......Page 118
Typed Object Identifiers (TOIDs)......Page 119
Allocating Memory......Page 120
Atomic Operations......Page 121
Reserve/Publish API......Page 124
Transactional API......Page 127
Persisting Data Summary......Page 131
Guarantees of libpmemobj's APIs......Page 132
Debugging and Error Handling......Page 133
Summary......Page 135
Introduction......Page 137
Persistent Pointers......Page 138
Transactions......Page 139
Snapshotting......Page 141
Allocating......Page 142
C++ Standard limitations......Page 144
An Object’s Lifetime......Page 145
Trivial Types......Page 146
Object Layout......Page 148
Pointers......Page 149
Limitations Summary......Page 151
Persistence Simplified......Page 152
The Ecosystem......Page 159
Persistent Containers......Page 160
Examples of Persistent Containers......Page 161
Summary......Page 164
Chapter 9: pmemkv: A Persistent In-Memory Key-Value Store......Page 166
pmemkv Architecture......Page 168
A Phonebook Example......Page 172
Bringing Persistent Memory Closer to the Cloud......Page 176
Summary......Page 177
Introduction......Page 179
How it Works......Page 180
Supported “Kinds” of Memory......Page 181
Kind Management API......Page 183
Creating a Fixed-Size Heap......Page 184
Automatic Kind Detection......Page 186
Memory Kind Detection......Page 187
Heap Management API......Page 188
Allocating Memory......Page 189
Freeing Allocated Memory......Page 190
Memory Usage Policy......Page 191
C++ Allocator for PMEM Kind......Page 192
Nested Containers......Page 193
Using the pmem::allocator......Page 194
Creating a Vector of Strings......Page 195
Expanding Volatile Memory Using Persistent Memory......Page 197
libvmemcache: An Efficient Volatile Key-Value Cache for Large-Capacity Persistent Memory......Page 201
libvmemcache Overview......Page 202
Extent-Based Allocator......Page 204
Scalable Replacement Policy......Page 206
Using libvmemcache......Page 207
Summary......Page 210
Contiguous Data Structures and Fragmentation......Page 211
Internal and External Fragmentation......Page 212
Transactions......Page 213
Copy-on-Write and Versioning......Page 216
Example Data Structures......Page 217
Hash Table with Transactions......Page 218
Hash Table with Transactions and Selective Persistence......Page 221
Sorted Array with Versioning......Page 226
Summary......Page 230
Chapter 12: Debugging Persistent Memory Applications......Page 231
Stack Overflow Example......Page 232
Memory Leak Example......Page 233
Intel Inspector – Persistence Inspector......Page 234
Stack Overflow Example......Page 235
Memory Leak Example......Page 236
Nonpersistent Stores......Page 238
Stores Not Added into a Transaction......Page 252
Memory Added to Two Different Transactions......Page 257
Memory Overwrites......Page 264
Unnecessary Flushes......Page 266
Out-of-Order Writes......Page 271
Summary......Page 283
Chapter 13: Enabling Persistence Using a Real-World Application......Page 285
Different Persistent Memory Enablement Approaches......Page 286
Developing a Persistent Memory-Aware MariaDB* Storage Engine......Page 287
Understanding the Storage Layer......Page 288
Creating a Storage Engine Class......Page 289
Creating a Database Table......Page 290
Opening a Database Table......Page 291
INSERT Operation......Page 292
UPDATE Operation......Page 294
DELETE Operation......Page 296
SELECT Operation......Page 299
Summary......Page 300
Chapter 14: Concurrency and Persistent Memory......Page 301
Transactions and Multithreading......Page 302
Mutexes on Persistent Memory......Page 306
Lock-Free Algorithms and Persistent Memory......Page 309
Concurrent Data Structures for Persistent Memory......Page 310
Concurrent Ordered Map......Page 311
Find Operation......Page 312
Insert Operation......Page 313
Concurrent Hash Map......Page 315
Insert Operation......Page 316
Summary......Page 317
Compute-Bound vs. Memory-Bound......Page 319
Memory Access Patterns......Page 320
Determining the Suitability of Workloads for Persistent Memory......Page 321
Identifying Workloads That Are Memory-Capacity Bound......Page 322
Identifying the Hot Working Set Size of a Workload......Page 324
Use Cases Requiring Persistence......Page 325
Performance Analysis of Workloads Using Persistent Memory......Page 326
Memory Bandwidth and Latency......Page 327
Non-Uniform Memory Architecture (NUMA) Behavior......Page 329
Addressable Memory Capacity......Page 330
Guided Data Placement......Page 331
Memory Access Optimization......Page 332
Data Allocation vs. First Access......Page 333
Thread Migration......Page 334
Summary......Page 335
A Pool of Persistent Memory: High-Level Architecture Overview......Page 337
The Uncertainty of Memory Mapping: Persistent Memory Object Identifier......Page 339
Persistent Thread Local Storage: Using Lanes......Page 342
Transaction Redo Logging......Page 344
Transaction Undo Logging......Page 345
libpmemobj Unified Logging......Page 346
Persistent Allocations: The Interface of a Transactional Persistent Allocator......Page 347
Persistent Memory Heap Management: Allocator Design for Persistent Memory......Page 348
ACID Transactions: Efficient Low-Level Persistent Transactions......Page 352
Lazy Reinitialization of Variables: Storing the Volatile State on Persistent Memory......Page 354
Summary......Page 355
Dealing with Uncorrectable Errors......Page 356
Consumed Uncorrectable Error Handling......Page 357
Unconsumed Uncorrectable Error Handling......Page 359
Patrol Scrub......Page 360
Address Range Scrub......Page 361
Device Health......Page 362
Vendor-Specific Device Health (_DSMs)......Page 365
Unsafe/Dirty Shutdown......Page 366
Application Utilization of Data Loss Count (DLC)......Page 367
Summary......Page 369
Chapter 18: Remote Persistent Memory......Page 370
RDMA Networking Protocols......Page 371
Guaranteeing Remote Persistence......Page 374
General-Purpose Remote Replication Method......Page 376
How Does the General-Purpose Remote Replication Method Make Data Persistent?......Page 377
Appliance Remote Replication Method......Page 378
General Software Architecture......Page 380
librpmem Architecture and Its Use in Replication......Page 381
Performance Considerations......Page 385
Say Hello to the Replicated World......Page 387
Execution Example......Page 392
Summary......Page 393
Nonuniform Memory Access (NUMA)......Page 395
NUMACTL Linux Utility......Page 396
NDCTL Linux Utility......Page 398
Intel Memory Latency Checker Utility......Page 400
NUMASTAT Utility......Page 402
IPMCTL Utility......Page 403
Automatic NUMA Balancing......Page 404
Using Volume Managers with Persistent Memory......Page 405
The mmap() MAP_SYNC Flag......Page 407
Summary......Page 408
Prerequisites......Page 410
Installing NDCTL and DAXCTL Using the Linux Distribution Package Repository......Page 411
Searching for Packages Within a Package Repository......Page 412
Installing NDCTL and DAXCTL from the Package Repository......Page 413
Installing PMDK on RHEL and CentOS 7.5 or Later......Page 414
Installing PMDK on Ubuntu 18.04 or Later......Page 415
Installing PMDK Using the Linux Distribution Package Repository......Page 416
Searching for Packages Within a Package Repository......Page 417
Installing PMDK Libraries from the Package Repository......Page 419
Installing PMDK on Fedora 22 or Later......Page 420
Installing PMDK on SLES 12 and OpenSUSE or Later......Page 421
Installing PMDK on Ubuntu 18.04 or Later......Page 422
Installing PMDK on Microsoft Windows......Page 423
Appendix C: How to Install IPMCTL on Linux and Windows......Page 424
IPMCTL for Microsoft Windows......Page 425
Using ipmctl......Page 426
Volatile Use of Persistent Memory......Page 431
Heap Allocation on Alternative Memory Devices......Page 432
Partial Heap Allocation on Alternative Memory Devices......Page 434
Non-volatile Mapped Byte Buffers......Page 435
Persistent Collections for Java (PCJ)......Page 436
Using PCJ in Java Applications......Page 437
Low-Level Persistent Library (LLPL)......Page 438
Summary......Page 439
Appendix E: The Future of Remote Persistent Memory Replication......Page 441
Glossary......Page 445
Index......Page 448