PMEM2_GET_FLUSH_FN(3)
π pmem2_get_flush_fn() β get a flush function π
okay bestie, so this one lives in the PMDK Programmer's Manual (yes, the libpmem2 era, we love her) and it's genuinely one of the cutest little lookups in the whole API. let's get into it π«Ά
β¨ NAME β¨
pmem2_get_flush_fn() β get a flush function
πΈ SYNOPSIS πΈ
#include <libpmem2.h>
typedef void (*pmem2_flush_fn)(const void *ptr, size_t size);
struct pmem2_map;
pmem2_flush_fn pmem2_get_flush_fn(struct pmem2_map *map);
π¦ DESCRIPTION π¦
So pmem2_get_flush_fn() hands you back a pointer to a function β and that function's whole job is efficiently flushing data in the range that's owned by the map. that's it. that's the gig. π
β οΈ and now the important part, bestie, listen up: flushing your data with pmem2_flush_fn does not guarantee that the data is stored durably by the time it returns. like, it's a vibe, not a promise. π
To actually get that guarantee, your application has two options:
- use the persist operation (see
pmem2_get_persist_fn(3)), or - follow
pmem2_flush_fnwith a drain operation (seepmem2_get_drain_fn(3)).
There are no alignment restrictions on the range described by ptr and size, which is very generous of her ngl β but heads up, pmem2_flush_fn may expand the range as necessary to meet platform alignment requirements. so it might do a little more than you asked. it's giving overachiever energy. β¨
There is nothing atomic or transactional about pmem2_flush_fn. fr fr. any unwritten stores in the given range will be written, but some stores may have already been written by virtue of normal cache eviction/replacement policies. so:
π Correctly written code must not depend on stores waiting untilpmem2_flush_fnis called to be flushed β they can be flushed at any time beforepmem2_flush_fnis called. no cap, this will bite you if you get cocky.
And here's a fun little bonus fact π β if two (or more) mappings share the same pmem2_flush_fn and they're adjacent to each other, it is safe to call this function for a range spanning those mappings. besties sharing a flush fn, iconic.
π RETURN VALUE π
pmem2_get_flush_fn() never returns NULL. never ever. periodt. π
Also, pmem2_get_flush_fn() for the same map always returns the same function. which means it's totally safe to cache its return value β go off, cache it. π
BUT (and this is the gag) this function is very cheap anyway, because it just returns a precomputed value. so honestly? caching may not even be necessary. do with that information what you will. π
π SEE ALSO π
pmem2_get_drain_fn(3)pmem2_get_persist_fn(3)pmem2_map_new(3)libpmem2(7)- and
https://pmem.iofor the full lore β¨
and that's the whole page, bestie!! this one comes to you from the PMDK girlies, dated 2025-07-24 β go flush something responsibly (with a persist or a drain after it, obviously π). mwah π
π¦ where this page comes from
- fedora 43: libpmem2-devel 2.1.0-4.fc43 Β· BSD-3-Clause
- π the page's license: BSD-3-Clause
- Copyright 2020, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms