---
name: "get_huge_pages"
section: "3"
platform: "linux"
package: "libhugetlbfs-dev"
version: "2.24-1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/get_huge_pages"
---

# get\_huge\_pages(3)

Allocate and free hugepages

## NAME

get\_huge\_pages, free\_huge\_pages - Allocate and free hugepages

## SYNOPSIS

**#include \<hugetlbfs.h\>**\

**void \*get\_huge\_pages(size\_t len, ghp\_t flags);**\
 **void free\_huge\_pages(void \*ptr);**

## DESCRIPTION

**get\_huge\_pages()** allocates a memory region **len** bytes in size backed by hugepages. Hugepages may be of benefit to applications that use large amounts of address space and suffer a  performance hit  due to  TLB misses.  Wall-clock  time or oprofile can be used to determine if there is a performance benefit from using hugepages or not.

The **len** parameter must be hugepage-aligned. In the current implementation, only the default hugepage size may be allocated via this function. Use **gethugepagesize** to discover what the alignment should be.

The **flags** argument changes the behaviour of the function. Flags may be or'd together.

- **GHP\_DEFAULT**

  Allocate a region of memory of the requested length backed by hugepages of the default hugepage size. Return NULL if sufficient pages are not available

**free\_huge\_pages()** frees a region of memory allocated by **get\_huge\_pages()**. The behaviour of the function if another pointer is used, valid or otherwise, is undefined.

## RETURN VALUE

On success, a pointer is returned to the allocated memory. On error, NULL is returned. errno will be set based on what the failure of mmap() was due to.

## SEE ALSO

*[oprofile(1)](/oprofile/1.md)* , *[gethugepagesize(3)](/gethugepagesize/3.md)* , *[get\_hugepage\_region(3)](/get_hugepage_region/3.md)* , *[libhugetlbfs(7)](/libhugetlbfs/7.md)*

## AUTHORS

libhugetlbfs was written by various people on the libhugetlbfs-devel mailing list.
