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:

  1. use the persist operation (see pmem2_get_persist_fn(3)), or
  2. follow pmem2_flush_fn with a drain operation (see pmem2_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 until pmem2_flush_fn is called to be flushed β€” they can be flushed at any time before pmem2_flush_fn is 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 🌈


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