alloc_hugepages(2)

πŸ’– alloc_hugepages β€” bestie edition πŸ’–

okay so this is a Linux manual page, and the two stars of the show are alloc_hugepages and free_hugepages β€” they allocate or free huge pages. that's it, that's the name section, we're keeping it cute and keeping it accurate. ✨


🌸 SYNOPSIS 🌸

void *syscall(size_t size;
              SYS_alloc_hugepages, int key,
              void addr[size], size_t size,
              int prot, int flag);
int syscall(SYS_free_hugepages, void *addr);
🚨 REAL TALK: glibc provides no wrappers for these system calls, bestie. none. zero. so you have to go through syscall(2). that's not optional, that's the vibe. πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

not me about to tell you the most tragic lore ever: alloc_hugepages() and free_hugepages() were introduced in Linux 2.5.36 and then removed again in Linux 2.5.54. they literally existed only on i386 and ia64 (and only when built with CONFIG_HUGETLB_PAGE). and if you're on Linux 2.4.20? the syscall numbers exist, but the calls just fail with the error ENOSYS. it's giving ghosted. 😭

so on i386, the memory management hardware knows about ordinary pages (4 KiB) and huge pages (2 or 4 MiB). same energy on ia64, except it knows about huge pages of several sizes. these system calls are here to map huge pages into the process's memory, or free them again. and the whole point? huge pages are locked into memory, and are not swapped. periodt.

the key argument is an identifier. here's the tea:

  • when it's zero, the pages are private, and not inherited by children.
  • when it's positive, the pages are shared with other applications using the same key, and inherited by child processes.

the addr argument of free_hugepages() tells which page is being freed: it was the return value of a call to alloc_hugepages(). (quick note bestie β€” the memory is first actually freed when all users have released it.) and the addr argument of alloc_hugepages()? that one's just a hint, and the kernel may or may not follow it. πŸ™ˆ

⭐ WARNING: addresses must be properly aligned. do not skip this.

the size argument is the size of the required segment. it must be a multiple of the huge page size. no exceptions, she's strict. πŸ‘‘

the prot argument specifies the memory protection of the segment. it is one of PROT_READ, PROT_WRITE, PROT_EXEC.

the flag argument is ignored, unless key is positive. in that case, if flag is IPC_CREAT, then a new huge page segment is created when none with the given key existed. if this flag is not set, then ENOENT is returned when no segment with the given key exists. ikyk. πŸ’…


🌈 RETURN VALUE 🌈

on success, alloc_hugepages() returns the allocated virtual address, and free_hugepages() returns zero. she ate that. πŸŽ€

on error, -1 is returned, and errno is set to indicate the error. unfortunate but we move.


πŸ”₯ ERRORS πŸ”₯

  • ENOSYS β€” the system call is not supported on this kernel. literally doesn't exist on your machine, sorry bestie. πŸ’€

πŸ“ FILES πŸ“

  • /proc/sys/vm/nr_hugepages β€” number of configured hugetlb pages. this can be read and written. flexible queen.
  • /proc/meminfo β€” gives info on the number of configured hugetlb pages and on their size in the three variables HugePages_Total, HugePages_Free, Hugepagesize. three icons in one file honestly.

✨ STANDARDS ✨

Linux on Intel processors. that's the whole section, keep scrolling. 🫢


πŸ‘‘ HISTORY πŸ‘‘

these system calls are gone. they existed only in Linux 2.5.36 through to Linux 2.5.54. a limited run, a cult classic, we mourn her. πŸ¦‹


πŸ’œ NOTES πŸ’œ

now the hugetlbfs filesystem can be used instead. memory backed by huge pages (if the CPU supports them) is obtained by using mmap(2) to map files in this virtual filesystem. that's the modern upgrade, no cap.

the maximal number of huge pages can be specified using the hugepages= boot parameter. 🌸


and that's the whole page, bestie!! πŸ’–βœ¨πŸŽ€ this little legend is from Linux man-pages 6.20, dated 2026-02-08, so you know it's fresh. mwah πŸ’…πŸ«Ά

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms