Programming Persistent Memory : A Comprehensive Guide for Developers
eBook - ePub

Programming Persistent Memory : A Comprehensive Guide for Developers

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Programming Persistent Memory : A Comprehensive Guide for Developers

About this book

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.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Programming Persistent Memory : A Comprehensive Guide for Developers by Steve Scargall in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming. We have over one million books available in our catalogue for you to explore.

Information

© The Author(s) 2020
S. ScargallProgramming Persistent Memoryhttps://doi.org/10.1007/978-1-4842-4932-1_1
Begin Abstract

1. Introduction to Persistent Memory Programming

Steve Scargall1
(1)
Santa Clara, CA, USA
End Abstract
This book describes programming techniques for writing applications that use persistent memory. It is written for experienced software developers, but we assume no previous experience using persistent memory. We provide many code examples in a variety of programming languages. Most programmers will understand these examples, even if they have not previously used the specific language.

Note

All code examples are available on a GitHub repository (https://github.com/Apress/programming-persistent-memory), along with instructions for building and running it.
Additional documentation for persistent memory, example programs, tutorials, and details on the Persistent Memory Development Kit (PMDK), which is used heavily in this book, can be found on http://pmem.io.
The persistent memory products on the market can be used in various ways, and many of these ways are transparent to applications. For example, all persistent memory products we encountered support the storage interfaces and standard file API’s just like any solid-state disk (SSD). Accessing data on an SSD is simple and well-understood, so we consider these use cases outside the scope of this book. Instead, we concentrate on memory-style access, where applications manage byte-addressable data structures that reside in persistent memory. Some use cases we describe are volatile, using the persistent memory only for its capacity and ignoring the fact it is persistent. However, most of this book is dedicated to the persistent use cases, where data structures placed in persistent memory are expected to survive crashes and power failures, and the techniques described in this book keep those data structures consistent across those events.

A High-Level Example Program

To illustrate how persistent memory is used, we start with a sample program demonstrating the key-value store provided by a library called libpmemkv. Listing 1-1 shows a full C++ program that stores three key-value pairs in persistent memory and then iterates through the key-value store, printing all the pairs. This example may seem trivial, but there are several interesting components at work here. Descriptions below the listing show what the program does.
37 #include <iostream>
38 #include <cassert>
39 #include <libpmemkv.hpp>
40
41 using namespace pmem::kv;
42 using std::cerr;
43 using std::cout;
44 using std::endl;
45 using std::string;
46
47 /*
48 * for this example, create a 1 Gig file
49 * called "/daxfs/kvfile"
50 */
51 auto PATH = "/daxfs/kvfile";
52 const uint64_t SIZE = 1024 * 1024 * 1024;
53
54 /*
55 * kvprint -- print a single key-value pair
56 */
57 int kvprint(string_view k, string_view v) {
58 cout << "key: " << k.data() <<
59 " value: " << v.data() << endl;
60 return 0;
61 }
62
63 int main() {
64 // start by creating the db object
65 db *kv = new db();
66 assert(kv != nullptr);
67
68 // create the config information for
69 // libpmemkv's open method
70 config cfg;
71
72 if (cfg.put_string("path", PATH) != status::OK) {
73 cerr << pmemkv_errormsg() << endl;
74 exit(1);
75 }
76 if (cfg.put_uint64("force_create", 1) != status::OK) {
77 cerr << pmemkv_errormsg() << endl;
78 exit(1);
79 }
80 if (cfg.put_uint64("size", SIZE) != status::OK) {
81 cerr << pmemkv_errormsg() << endl;
82 exit(1);
83 }
84
85
86 // open the key-value store, using the cmap engine
87 if (kv->open("cmap", std::move(cfg)) != status::OK) {
88 cerr << db::errormsg() << endl;
89 exit(1);
90 }
91
92 // add some keys and values
93 if (kv->put("key1", "value1") != status::OK) {
94 cerr << db::errormsg() << endl;
95 exit(1);
96 }
97 if (kv->put("key2", "value2") != status::OK) {
98 cerr << db::errormsg() << endl;
99 exit(1);
100 }
101 if (kv->put("key3", "value3") != status::OK) {
102 cerr << db::errormsg() << endl;
103 exit(1);
104 }
105
106 // iterate through the key-value store, printing them
107 kv->get_all(kvprint);
108
109 // stop the pmemkv engine
110 delete kv;
111
112 exit(0);
113 }
Listing 1-1
A sample program using libpmemkv
  • Line 57: We define a small helper routine, kvprint() , which prints a key-value pair when called.
  • Line 63: This is the first line of main() which is where every C++ program begins execution. We start by instantiating a key-value engine using the engine name "cmap". We discuss other engine types in Chapter 9.
  • Line 70: The cmap engine takes config parameters from a config structure. The parameter "path" is configured to "/daxfs/kvfile", which is the path to a persistent memory file on a DAX file system; the parameter "size" is set to SIZE. Chapter 3 describes how to create and mount DAX file systems.
  • Line 93: We add several key-value pairs to the store. The trademark of a key-value store is the use of simple operations like put() and get(); we only show put() in this example.
  • Line 107: Using the get_all() method , we iterate through the entire key-value store, printing each pair when get_all() calls our kvprint() routine.

What’s Different?

A wide variety of key-value libraries are available in practically every programming language. The persistent memory example in Listing 1-1 is different because the key-value store itself resides in persistent memory. For comparison, Figure 1-1 shows how a key-value store using traditional storage is laid out.
../images/477774_1_En_1_Chapter/477774_1_En_1_Fig1_HTML.webp
Figure 1-1
A key-value store on traditional storage
When the application in Figure 1-1 wants to fetch a value from the key-value store, a buffer must be allocated in memory to hold the result. This is because the values are kept on block storage, which cannot be addressed directly by the application. The only way to access a value is to bring it into memory, and the only way to do that is to read full blocks from the storage device, which can only be accessed via block I/O. Now consider Figure 1-2, where the key-value store resides in persistent memory like our sample code.
../images/477774_1_En_1_Chapter/477774_1_En_1_Fig2_HTML.webp
Figure 1-2
A key-value store in persistent memory
With the persistent memory key-value store, values are accessed by the application directly, without the need to first allocate buffers in memory. The kvprint() routine in Listing 1-1 will be called with references to the actual keys and values, directly where they live in persistence – something that...

Table of contents

  1. Cover
  2. Front Matter
  3. 1. Introduction to Persistent Memory Programming
  4. 2. Persistent Memory Architecture
  5. 3. Operating System Support for Persistent Memory
  6. 4. Fundamental Concepts of Persistent Memory Programming
  7. 5. Introducing the Persistent Memory Development Kit
  8. 6. libpmem: Low-Level Persistent Memory Support
  9. 7. libpmemobj: A Native Transactional Object Store
  10. 8. libpmemobj-cpp: The Adaptable Language - C++ and Persistent Memory
  11. 9. pmemkv: A Persistent In-Memory Key-Value Store
  12. 10. Volatile Use of Persistent Memory
  13. 11. Designing Data Structures for Persistent Memory
  14. 12. Debugging Persistent Memory Applications
  15. 13. Enabling Persistence Using a Real-World Application
  16. 14. Concurrency and Persistent Memory
  17. 15. Profiling and Performance
  18. 16. PMDK Internals: Important Algorithms and Data Structures
  19. 17. Reliability, Availability, and Serviceability (RAS)
  20. 18. Remote Persistent Memory
  21. 19. Advanced Topics
  22. Back Matter