160
Kind Creation
Use the memkind_create_pmem() function to create a PMEM kind of memory from a
file-backed source. This file is created as a tmpfile(3) in a specified directory (PMEM_DIR)
and is unlinked, so the file name is not listed under the directory. The temporary file is
automatically removed when the program terminates.
Use memkind_create_pmem() to create a fixed or dynamic heap size depending on
the application requirement. Additionally, configurations can be created and supplied
rather than passing in configuration options to the *_create_* function.
Creating a Fixed-Size Heap
Applications that require a fixed amount of memory can specify a nonzero value for the
PMEM_MAX_SIZE argument to memkind_create_pmem(), shown below. This defines the
size of the memory pool to be created for the specified kind of memory. The value of
PMEM_MAX_SIZE should be less than the available capacity of the file system specified in
PMEM_DIR to avoid ENOMEM or ENOSPC errors. An internal data structure struct memkind is
populated internally by the library and used by the memory management functions.
int memkind_create_pmem(PMEM_DIR, PMEM_MAX_SIZE, &pmem_kind)
The arguments to memkind_create_pmem() are
• PMEM_DIR is the directory where the temp file is created.
• PMEM_MAX_SIZE is the size, in bytes, of the memory region to be
passed to jemalloc.
• &pmem_kind is the address of a memkind data structure.
If successful, memkind_create_pmem() returns zero. On failure, an error number is
returned that memkind_error_message() can convert to an error message string.
Listing 10-2 shows how a 32MiB PMEM kind is created on a /daxfs file system. Included in
this listing is the definition of memkind_fatal() to print a memkind error message and exit.
The rest of the examples in this chapter assume this routine is defined as shown below.
Listing 10-2. Creating a 32MiB PMEM kind
void memkind_fatal(int err)
{
char error_message[MEMKIND_ERROR_MESSAGE_SIZE];
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 184/457

Suivant