PMEM_MEMMOVE(3)
π PMEM_MEMCPY π
okay bestie, welcome to pmem_memcpy(3) β that's the manpage name, and it lives in the PMDK Programmer's Manual. we're doing optimized copying to persistent memory today and honestly? it's giving main character energy. π
β¨ NAME β¨
pmem_memmove(), pmem_memcpy(), pmem_memset(), pmem_memmove_persist(), pmem_memcpy_persist(), pmem_memset_persist(), pmem_memmove_nodrain(), pmem_memcpy_nodrain(), pmem_memset_nodrain() β functions that provide optimized copying to persistent memory πΈ
π¦ SYNOPSIS π¦
#include <libpmem.h>
void *pmem_memmove(void *pmemdest, const void *src, size_t len, unsigned flags);
void *pmem_memcpy(void *pmemdest, const void *src, size_t len, unsigned flags);
void *pmem_memset(void *pmemdest, int c, size_t len, unsigned flags);
void *pmem_memmove_persist(void *pmemdest, const void *src, size_t len);
void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len);
void *pmem_memset_persist(void *pmemdest, int c, size_t len);
void *pmem_memmove_nodrain(void *pmemdest, const void *src, size_t len);
void *pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len);
void *pmem_memset_nodrain(void *pmemdest, int c, size_t len);
look at all those lil guys π nine whole functions, all of them handing back a pointer to your destination buffer. iconic.
π DESCRIPTION π
so pmem_memmove(), pmem_memcpy() and pmem_memset() do the exact same memory copying as their namesakes memmove(3), memcpy(3) and memset(3) β except they also make sure the result is flushed to persistence before returning. yeah. they actually wait for it. (unless you passed the PMEM_F_MEM_NOFLUSH flag, in which case, no they don't π«Ά)
for example, this next lil block is functionally equivalent to pmem_memmove() (with flags equal to 0):
memmove(dest, src, len);
pmem_persist(dest, len);
but here's the tea: calling pmem_memmove() may out-perform that code, because the libpmem(7) implementation may take advantage of the fact that pmemdest is persistent memory, and use instructions such as non-temporal stores to avoid needing to flush processor caches at all. β¨
WARNING: Using these functions where pmem_is_pmem(3) returns false may not do anything useful. Use libc functions in that case. π fr fr, check first.
and unlike the libc implementation, these libpmem functions guarantee that if the destination buffer address and length are 8 byte aligned, then all stores will be performed using at least 8 byte store instructions. which means: a series of 8 byte stores followed by pmem_persist(3) can be safely replaced by a single call to one of the above functions. one call. that's it. slay. π
π the flags argument π
the flags argument of all of the above functions has the same meaning, every time. it can be 0, or a bitwise OR of one or more of the following flags:
PMEM_F_MEM_NODRAINβ modifies the behavior to skip the finalpmem_drain()step. this lets applications optimize cases where several ranges are being copied to persistent memory, followed by a single call topmem_drain(). the following example illustrates how this flag might be used to avoid multiple calls topmem_drain()when copying several ranges of memory to pmem:
/* ... write several ranges to pmem ... */
pmem_memcpy(pmemdest1, src1, len1, PMEM_F_MEM_NODRAIN);
pmem_memcpy(pmemdest2, src2, len2, PMEM_F_MEM_NODRAIN);
/* ... */
/* wait for any pmem stores to drain from HW buffers */
pmem_drain();
PMEM_F_MEM_NOFLUSHβ Donβt flush anything. This impliesPMEM_F_MEM_NODRAIN. Using this flag only makes sense when itβs followed by any function that flushes data. π
the remaining flags say how the operation should be done, and are merely hints:
PMEM_F_MEM_NONTEMPORALβ Use non-temporal instructions. This flag is mutually exclusive withPMEM_F_MEM_TEMPORAL. Onx86_64this flag is mutually exclusive withPMEM_F_MEM_NOFLUSH.PMEM_F_MEM_TEMPORALβ Use temporal instructions. This flag is mutually exclusive withPMEM_F_MEM_NONTEMPORAL.PMEM_F_MEM_WCβ Use write combining mode. This flag is mutually exclusive withPMEM_F_MEM_WB. Onx86_64this flag is mutually exclusive withPMEM_F_MEM_NOFLUSH.PMEM_F_MEM_WBβ Use write back mode. This flag is mutually exclusive withPMEM_F_MEM_WC. Onx86_64this is an alias forPMEM_F_MEM_TEMPORAL.
Using an invalid combination of flags has undefined behavior. π do NOT mix the mutually exclusive ones, bestie, i am begging.
without any of the above flags, libpmem will try to guess the best strategy based on size. see PMEM_MOVNT_THRESHOLD description in libpmem(7) for details. π
π§ the aliases (the shortcut girlies) π§
pmem_memmove_persist()is an alias forpmem_memmove()with flags equal to0.pmem_memcpy_persist()is an alias forpmem_memcpy()with flags equal to0.pmem_memset_persist()is an alias forpmem_memset()with flags equal to0.pmem_memmove_nodrain()is an alias forpmem_memmove()with flags equal toPMEM_F_MEM_NODRAIN.pmem_memcpy_nodrain()is an alias forpmem_memcpy()with flags equal toPMEM_F_MEM_NODRAIN.pmem_memset_nodrain()is an alias forpmem_memset()with flags equal toPMEM_F_MEM_NODRAIN.
β RETURN VALUE β
All of the above functions return the address of the destination buffer. every single one. same answer. π
π CAVEATS π
after calling any of the functions with the PMEM_F_MEM_NODRAIN flag, you should not expect memory to be visible to other threads before calling pmem_drain(3) or any of the _persist functions. π why? because on x86_64 those functions may use non-temporal store instructions, which are weakly ordered. see βIntel 64 and IA-32 Architectures Software Developerβs Manualβ, Volume 1, βCaching of Temporal vs. Non-Temporal Dataβ section for details. iykyk π
πΈ SEE ALSO πΈ
that's the whole page, babe π this was PMDK, dated 2025-07-24 β go forth and persist your data responsibly, no cap. π«Άβ¨
π¦ 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 2017-2020, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms