PMEM2_VM_RESERVATION_SHRINK(3)
π pmem2_vm_reservation_extend(3), pmem2_vm_reservation_shrink(3) π
okay so bestie, we're in the PMDK Programmer's Manual today and we are talking about growing and shrinking your virtual memory reservation. no cap, this is the glow-up and the downsize of the reservation world π¦
β¨ NAME β¨
pmem2_vm_reservation_extend(), pmem2_vm_reservation_shrink() β the two functions that extend and shrink an existing virtual memory reservation. it's giving personal trainer for memory. πͺ
πΈ SYNOPSIS πΈ
#include <libpmem2.h>
struct pmem2_vm_reservation;
int pmem2_vm_reservation_extend(struct pmem2_vm_reservation *rsv, size_t size);
int pmem2_vm_reservation_shrink(struct pmem2_vm_reservation *rsv, size_t offset,
size_t size);
π DESCRIPTION π
so, pmem2_vm_reservation_extend() takes an existing virtual memory reservation and extends it by the given size. for this to actually work, size has to be aligned to an appropriate allocation granularity β the universe (and the allocator) does not accept unaligned chaos, periodt. β¨
if pmem2_vm_reservation_extend() succeeds in extending a reservation, it hands you a placeholder virtual memory range that starts from an address at the end of the old reservation. and the best part? mappings made to the reservation before extending are preserved. nothing lost, everything gained, we love to see it π«Ά
then we have pmem2_vm_reservation_shrink(), which shrinks the reservation by a region specified by offset into the reservation and the size. for this one to succeed, both the size and offset variables have to be aligned to an appropriate allocation granularity. also the region formed by offset and size has to belong to the reservation, has to be empty, and it needs to cover the beginning or the end of the reservation. and listen β shrinking a reservation from the middle? not supported. shrinking the whole reservation? also not supported. it's giving "no, you can't just delete the middle of the sandwich" π₯ͺπ
if pmem2_vm_reservation_shrink() succeeds in shrinking a reservation, it releases the placeholder virtual memory range that was designated by the offset and size variables. mappings made to the reservation before shrinking are preserved. iconic. π
and if either of those functions fails, the reservation will be left as it was and an appropriate error value will be returned. no half-done mess, no drama, the reservation stays exactly how it woke up. π
β RETURN VALUE β
both pmem2_vm_reservation_extend() and pmem2_vm_reservation_shrink() return 0 on success, or a negative error code on failure. simple as that, fr fr.
π₯ ERRORS π₯
π
pmem2_vm_reservation_extend() can fail with:
PMEM2_E_MAPPING_EXISTSβ the range that the reservation would be extended by is already occupied by an existing mapping. someone else is literally already sitting there. π
it can also return -EAGAIN, -ENOMEM from the underlying mmap(2) function.
π
pmem2_vm_reservation_shrink() can fail with:
PMEM2_E_OFFSET_UNALIGNEDβ the provided offset isn't aligned to an appropriate allocation granularity. alignment vibes check: failed. πPMEM2_E_LENGTH_UNALIGNEDβ the provided size isn't aligned to an appropriate allocation granularity. same energy, different variable. π«PMEM2_E_OFFSET_OUT_OF_RANGEβ the provided offset is out of the reservation range available to be shrunk.PMEM2_E_LENGTH_OUT_OF_RANGEβ the provided size is out of the reservation range available to be shrunk.PMEM2_E_NOSUPPβ the interval designated by the offset and size variables covers only the middle or the whole reservation range. (see above: no middle-shrinking, no whole-shrinking, we said what we said π«)PMEM2_VM_RESERVATION_NOT_EMPTYβ the interval designated by the offset and size variable is not empty.
it can also return -EAGAIN and -ENOMEM from the underlying munmap(2) function.
lowkey important: those-EAGAINand-ENOMEMones aren't this library's own errors, they come straight from the underlying syscalls, iykyk.
π SEE ALSO π
pmem2_vm_reservation_new(3)pmem2_config_set_vm_reservation(3)libpmem2(7)- <https://pmem.io> β no wait, just:
https://pmem.ioβ¨
and that's the whole page bestie, you ate it up π
this little love letter comes from the PMDK Programmer's Manual, dated 2025-07-24 β mwah, go extend something responsibly. π ππ¦
π¦ 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 2021-2022, Intel Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms