---
name: "pmem2_vm_reservation_delete"
section: "3"
platform: "linux"
package: "libpmem2-dev"
version: "1.13.1-1.1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/pmem2_vm_reservation_new"
---

# pmem2\_vm\_reservation\_delete(3)

creates or deletes an instance of virtual memory reservation

Part of [pmem2\_vm\_reservation\_new(3)](/pmem2_vm_reservation_new/3.md).

## NAME

**pmem2\_vm\_reservation\_new**(), **pmem2\_vm\_reservation\_delete**() - creates or deletes an instance of virtual memory reservation

## SYNOPSIS

-

  ```
  #include <libpmem2.h>
  struct pmem2_vm_reservation;
  int pmem2_vm_reservation_new(struct pmem2_vm_reservation **rsv_ptr,
          void *addr, size_t size);
  int pmem2_vm_reservation_delete(struct pmem2_vm_reservation **rsv_ptr);
  ```

## DESCRIPTION

The **pmem2\_vm\_reservation\_new**() function creates a new blank mapping in the virtual address space of the calling process. Reservation serves as a placeholder of a given size on which sources can be mapped.

For the function to succeed, the *addr* must be either aligned to an appropriate allocation granularity or **NULL**, the size always has to be aligned to an appropriate OS allocation granularity.

[**libpmem2**(7)](/libpmem2/7.md) library chooses the largest page alignment for the reservation based on *size*. If the chosen alignment is different than the OS allocation granularity, then the underlying size of the reservation can be bigger than the value presented to the user. Largest page alignment functionality is limited to POSIX systems.

If the **pmem2\_vm\_reservation\_new**() succeeds in creating a reservation, it instantiates a new **struct pmem2\_vm\_reservation** object describing the reservation. The pointer to this object is stored in the user-provided variable via the *rsv\_ptr* pointer. If the function fails, an appropriate error value will be returned. For a list of possible return values please see RETURN VALUE

After instantiating an object via the **pmem2\_vm\_reservation\_new**() function, it may be disposed of using the **pmem2\_vm\_reservation\_delete**() function.

The **pmem2\_vm\_reservation\_delete**() function destroys the object describing the reservation and unmaps virtual memory region the \*struct pmem2\_vm\_reservation\*\* had assigned during the initialization. For the delete function to succeed, it is required that the reservation passed via the *rsv\_ptr* pointer does not contain any mappings.

## RETURN VALUE

The **pmem2\_vm\_reservation\_new**() and **pmem2\_vm\_reservation\_delete**() functions return 0 on success or a negative error code on failure.

The function returns 0 on success or a negative error code on failure.

## ERRORS

The **pmem2\_vm\_reservation\_new**() function can fail with the following errors:

- •

  **PMEM2\_E\_ADDRESS\_UNALIGNED** - argument *addr* is not aligned to the appropriate allocation granularity.

- •

  **PMEM2\_E\_MAPPING\_EXISTS** - mapping already exists in the range (*addr*, *addr* + *size*).

It can also return **-EAGAIN**, **-ENOMEM** from the underlying [**mmap**(2)](/mmap/2.md) function and **-ENOMEM** in case of insufficient memory to allocate an instance of *struct* *pmem2\_vm\_reservation*.

The **pmem2\_vm\_reservation\_delete**() function can fail with the following errors:

- •

  **PMEM2\_E\_RESERVATION\_NOT\_EMPTY** - reservation contains mappings.

It can also return errors from the underlying [**munmap**(2)](/munmap/2.md) function.

## SEE ALSO

[**pmem2\_config\_set\_vm\_reservation**(3)](/pmem2_config_set_vm_reservation/3.md), [**libpmem2**(7)](/libpmem2/7.md) and **\<https://pmem.io\>**
