PMEM_CHECK_VERSION(3)
π PMEM_CHECK_VERSION(3) π
okay so this is the PMDK Programmer's Manual page for pmem_check_version(3), and it's all about libpmem, the persistent memory support library. it's giving low-level pmem bestie energy, no cap. π
β¨ NAME β¨
libpmem β persistent memory support library. that's the whole vibe. π«Ά
β¨ SYNOPSIS β¨
#include <libpmem.h>
cc ... -lpmem
Library API versioning:
const char *pmem_check_version(
unsigned major_required,
unsigned minor_required);
Error handling:
const char *pmem_errormsg(void);
Other library functions:
A description of other libpmem functions can be found on the following manual pages:
- most commonly used functions:
pmem_is_pmem(3) - partial flushing operations:
pmem_flush(3) - copying to persistent memory:
pmem_memmove_persist(3)
β¨ DESCRIPTION β¨
libpmem provides low-level persistent memory (pmem) support for applications using direct access storage (DAX), which is storage that supports load/store access without paging blocks from a block storage device. Some types of non-volatile memory DIMMs (NVDIMMs) provide this type of byte addressable access to storage. A persistent memory aware file system is typically used to expose the direct access to applications. Memory mapping a file from this type of file system results in the load/store, non-paged access to pmem. π¦
This library is for applications that use persistent memory directly, without the help of any library-supplied transactions or memory allocation. A higher-level library that relies on libpmem is available and recommended for most applications, see:
libpmemobj(7), a general use persistent memory API, providing memory allocation and transactional operations on variable-sized objects.
Under normal usage, libpmem will never print messages or intentionally cause the process to exit. The only exception to this is the debugging information, when enabled, as described under DEBUGGING AND ERROR HANDLING below. periodt. π
β¨ CAVEATS β¨
libpmem relies on the library destructor being called from the main thread. For this reason, all functions that might trigger destruction (e.g. dlclose(3)) should be called in the main thread. Otherwise some of the resources associated with that thread might not be cleaned up properly. π
bestie, do not play with this. main thread only for the destructor-triggering stuff. iykyk.
β¨ LIBRARY API VERSIONING β¨
This section describes how the library API is versioned, allowing applications to work with an evolving API. slay, evolution. π
The pmem_check_version() function is used to determine whether the installed libpmem supports the version of the library API required by an application. The easiest way to do this is for the application to supply the compile-time version information, supplied by defines in <libpmem.h>, like this:
reason = pmem_check_version(PMEM_MAJOR_VERSION, PMEM_MINOR_VERSION);
if (reason != NULL) {
/* version check failed, reason string tells you why */
}
Any mismatch in the major version number is considered a failure, but a library with a newer minor version number will pass this check since increasing minor versions imply backwards compatibility. π
An application can also check specifically for the existence of an interface by checking for the version where that interface was introduced. These versions are documented in this man page as follows: unless otherwise specified, all interfaces described here are available in version 1.0 of the library. Interfaces added after version 1.0 will contain the text introduced in version x.y in the section of this manual describing the feature.
When the version check performed by pmem_check_version() is successful, the return value is NULL. Otherwise the return value is a static string describing the reason for failing the version check. The string returned by pmem_check_version() must not be modified or freed. π
β¨ ENVIRONMENT β¨
libpmem can change its default behavior based on the following environment variables. These are largely intended for testing and are not normally required. π
PMEM_IS_PMEM_FORCE=valβ Ifvalis0(zero), thenpmem_is_pmem(3)will always return false. Settingvalto1causespmem_is_pmem(3)to always return true. This variable is mostly used for testing but can be used to force pmem behavior on a system where a range of pmem is not detectable as pmem for some reason.
NOTE: Unlike the other variables, the value ofPMEM_IS_PMEM_FORCEis not queried (and cached) at library initialization time, but on the first call topmem_is_pmem(3). This means that in case oflibpmemobj(7),PMEM_IS_PMEM_FORCEmay still be set or modified by the program until the first attempt to create or open the persistent memory pool.
PMEM_NO_CLWB=1β Setting this environment variable to1forces libpmem to never issue theCLWBinstruction on Intel hardware, falling back to other cache flush instructions instead (CLFLUSHOPTorCLFLUSHon Intel hardware). Without this environment variable, libpmem will always use theCLWBinstruction for flushing processor caches on platforms that support the instruction. This variable is intended for use during library testing but may be required for some rare cases where usingCLWBhas a negative impact on performance.PMEM_NO_CLFLUSHOPT=1β Setting this environment variable to1forces libpmem to never issue theCLFLUSHOPTinstruction on Intel hardware, falling back to theCLFLUSHinstructions instead. Without this environment variable, libpmem will always use theCLFLUSHOPTinstruction for flushing processor caches on platforms that support the instruction, but whereCLWBis not available. This variable is intended for use during library testing.PMEM_NO_FLUSH=1β Setting this environment variable to1forces most libpmem functions to never issue any ofCLFLUSH,CLFLUSHOPTorCLWBinstructions on Intel hardware. The only exceptions arepmem_deep_flush(3)andpmem_deep_persist(3)functions.PMEM_NO_FLUSH=0β Setting this environment variable to0forces to always flush CPU caches using one ofCLFLUSH,CLFLUSHOPTorCLWBinstructions even ifpmem_has_auto_flush(3)function returns true and the platform supports flushing the processor caches on power loss or system crash.PMEM_NO_MOVNT=1β Setting this environment variable to1forces libpmem to never use the non-temporal move instructions on Intel hardware. Without this environment variable, libpmem will use the non-temporal instructions for copying larger ranges to persistent memory on platforms that support the instructions. This variable is intended for use during library testing.PMEM_MOVNT_THRESHOLD=valβ This environment variable allows overriding the minimum length of thepmem_memmove_persist(3)operations, for which libpmem uses non-temporal move instructions. Setting this environment variable to0forces libpmem to always use the non-temporal move instructions if available. It has no effect ifPMEM_NO_MOVNTis set to1. This variable is intended for use during library testing.PMEM_MMAP_HINT=valβ This environment variable allows overriding the hint address used bypmem_map_file(). If set, it also disables mapping address randomization. This variable is intended for use during library testing and debugging. Setting it to some fairly large value (i.e.0x10000000000) will very likely result in mapping the file at the specified address (if not used) or at the first unused region above given address, without adding any random offset. When debugging, this makes it easier to calculate the actual address of the persistent memory block, based on its offset in the file. In case of libpmemobj it simplifies conversion of a persistent object identifier (OID) into a direct pointer to the object.
NOTE: Setting this environment variable affects all the PMDK libraries, disabling mapping address randomization and causing the specified address to be used as a hint about where to place the mapping.
β¨ ERROR HANDLING β¨
If an error is detected during the call to a libpmem function, the application may retrieve an error message describing the reason of the failure from pmem_errormsg(). This function returns a pointer to a static buffer containing the last error message logged for the current thread. If errno was set, the error message may include a description of the corresponding error code as returned by strerror(3). The error message buffer is thread-local; errors encountered in one thread do not affect its value in other threads. The buffer is never cleared by any library function; its content is significant only when the return value of the immediately preceding call to a libpmem function indicated an error. The application must not modify or free the error message string. Subsequent calls to other library functions may modify the previous message. π
In parallel to the above mechanism, all logging messages are written to syslog(3) and/or stderr(3) or passed to the user-provided logging function. Please see pmem_log_set_function(3) for details. The influx of the reported messages can be controlled by setting a respective threshold value. Please see pmem_log_set_threshold(3) for details. π
β¨ DEBUGGING β¨
Two versions of libpmem are typically available on a development system. The normal version, accessed when a program is linked using the -lpmem option, is optimized for performance. That version skips checks that impact performance and never logs any trace information or performs any run-time assertions. π₯
A second version of libpmem, accessed when a program uses the libraries under /usr/lib/pmdk_debug, contains run-time assertions and trace points. The typical way to access the debug version is to set the environment variable LD_LIBRARY_PATH to /usr/lib/pmdk_debug or /usr/lib64/pmdk_debug, as appropriate. π§
π LOGGING (DEPRECATED) π
Okay bestie, listen up β this whole logging situation is deprecated, which is the polite way of saying "it still works, but the cool kids moved on." π«Ά
Debugging output is controlled using the following environment variables. These variables have no effect on the non-debug version of the library. Like, none. Zero. The non-debug build simply does not care. π
PMEM_LOG_LEVEL
The value of the PMEM_LOG_LEVEL environment variable enables trace points in the debug version of the library, as follows:
0β This is the default level whenPMEM_LOG_LEVELis not set. No log messages are emitted at this level. Silence. Peace. Nothing. π€«1β Additional details on any errors detected are logged, in addition to returning theerrno-based errors as usual. The same information may be retrieved usingpmem_errormsg(). β¨2β A trace of basic operations is logged. π3β Enables a very verbose amount of function call tracing in the library. Very verbose. Like, it will not stop talking. π4β Enables voluminous and fairly obscure tracing information that is likely only useful to thelibpmemdevelopers. This is the deep lore tier. π
Unless the PMEM_LOG_FILE environment variable is set, the debugging output is written to stderr.
PMEM_LOG_FILE
Specifies the name of a file where all logging information should be written. π
Here's the little trick you gotta know: if the last character in the name is β-β, the PID of the current process will be appended to the file name when the log file is created. So every process gets its own file, no more fighting over one log. π¦
If PMEM_LOG_FILE is not set, output is written to stderr.
Heads up bestie: Whenever eitherPMEM_LOG_LEVELorPMEM_LOG_FILEenvironment variable is set, the messages are not passed via the routes described in the ERROR HANDLING section β except for thepmem_errormsg()which works unconditionally. That one is the main character and always shows up. π
πΈ EXAMPLE πΈ
The following example uses libpmem to flush changes made to raw, memory-mapped persistent memory.
β οΈ WARNING: There is nothing transactional about thepmem_persist(3)orpmem_msync(3)calls in this example. Interrupting the program may result in a partial write to pmem. Use a transactional library such aslibpmemobj(7)to avoid torn updates. fr fr, do not skip this part. π
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <libpmem.h>
/* using 4k of pmem for this example */
#define PMEM_LEN 4096
#define PATH "/pmem-fs/myfile"
int
main(int argc, char *argv[])
{
char *pmemaddr;
size_t mapped_len;
int is_pmem;
/* create a pmem file and memory map it */
if ((pmemaddr = pmem_map_file(PATH, PMEM_LEN, PMEM_FILE_CREATE,
0666, &mapped_len, &is_pmem)) == NULL) {
perror("pmem_map_file");
exit(1);
}
/* store a string to the persistent memory */
strcpy(pmemaddr, "hello, persistent memory");
/* flush above strcpy to persistence */
if (is_pmem)
pmem_persist(pmemaddr, mapped_len);
else
pmem_msync(pmemaddr, mapped_len);
/*
* Delete the mappings. The region is also
* automatically unmapped when the process is
* terminated.
*/
pmem_unmap(pmemaddr, mapped_len);
}
See https://pmem.io/pmdk/libpmem for more examples using the libpmem API. π
π ACKNOWLEDGEMENTS π
libpmem builds on the persistent memory programming model recommended by the SNIA NVM Programming Technical Work Group: https://snia.org/nvmp π§
π SEE ALSO π
dlclose(3)pmem_flush(3)pmem_is_pmem(3)pmem_memmove_persist(3)pmem_msync(3)pmem_persist(3)strerror(3)libpmemobj(7)https://pmem.io
and that's the whole page bestie π This one's from the PMDK collection, dated 2025-07-24, and that lil empty () at the bottom is where the version info would go β iconic, honestly. Go forth and flush your writes properly. periodt. π
β¨
π¦ where this page comes from
- fedora 43: libpmem-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2016-2018, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms