Blame man2/alloc_hugepages.2

Packit 7cfc04
.\" Copyright 2003 Andries E. Brouwer (aeb@cwi.nl)
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.TH ALLOC_HUGEPAGES 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
alloc_hugepages, free_hugepages \- allocate or free huge pages
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.BI "void *alloc_hugepages(int " key ", void *" addr ", size_t " len ,
Packit 7cfc04
.BI "                      int " prot ", int " flag );
Packit 7cfc04
.\" asmlinkage unsigned long sys_alloc_hugepages(int key, unsigned long addr,
Packit 7cfc04
.\" unsigned long len, int prot, int flag);
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int free_hugepages(void *" addr );
Packit 7cfc04
.\" asmlinkage int sys_free_hugepages(unsigned long addr);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The system calls
Packit 7cfc04
.BR alloc_hugepages ()
Packit 7cfc04
and
Packit 7cfc04
.BR free_hugepages ()
Packit 7cfc04
were introduced in Linux 2.5.36 and removed again in 2.5.54.
Packit 7cfc04
They existed only on i386 and ia64 (when built with
Packit 7cfc04
.BR CONFIG_HUGETLB_PAGE ).
Packit 7cfc04
In Linux 2.4.20, the syscall numbers exist,
Packit 7cfc04
but the calls fail with the error
Packit 7cfc04
.BR ENOSYS .
Packit 7cfc04
.PP
Packit 7cfc04
On i386 the memory management hardware knows about ordinary pages (4\ KiB)
Packit 7cfc04
and huge pages (2 or 4\ MiB).
Packit 7cfc04
Similarly ia64 knows about huge pages of
Packit 7cfc04
several sizes.
Packit 7cfc04
These system calls serve to map huge pages into the
Packit 7cfc04
process's memory or to free them again.
Packit 7cfc04
Huge pages are locked into memory, and are not swapped.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I key
Packit 7cfc04
argument is an identifier.
Packit 7cfc04
When zero the pages are private, and
Packit 7cfc04
not inherited by children.
Packit 7cfc04
When positive the pages are shared with other applications using the same
Packit 7cfc04
.IR key ,
Packit 7cfc04
and inherited by child processes.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I addr
Packit 7cfc04
argument of
Packit 7cfc04
.BR free_hugepages ()
Packit 7cfc04
tells which page is being freed: it was the return value of a
Packit 7cfc04
call to
Packit 7cfc04
.BR alloc_hugepages ().
Packit 7cfc04
(The memory is first actually freed when all users have released it.)
Packit 7cfc04
The
Packit 7cfc04
.I addr
Packit 7cfc04
argument of
Packit 7cfc04
.BR alloc_hugepages ()
Packit 7cfc04
is a hint, that the kernel may or may not follow.
Packit 7cfc04
Addresses must be properly aligned.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I len
Packit 7cfc04
argument is the length of the required segment.
Packit 7cfc04
It must be a multiple of the huge page size.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I prot
Packit 7cfc04
argument specifies the memory protection of the segment.
Packit 7cfc04
It is one of
Packit 7cfc04
.BR PROT_READ ,
Packit 7cfc04
.BR PROT_WRITE ,
Packit 7cfc04
.BR PROT_EXEC .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I flag
Packit 7cfc04
argument is ignored, unless
Packit 7cfc04
.I key
Packit 7cfc04
is positive.
Packit 7cfc04
In that case, if
Packit 7cfc04
.I flag
Packit 7cfc04
is
Packit 7cfc04
.BR IPC_CREAT ,
Packit 7cfc04
then a new huge page segment is created when none
Packit 7cfc04
with the given key existed.
Packit 7cfc04
If this flag is not set, then
Packit 7cfc04
.B ENOENT
Packit 7cfc04
is returned when no segment with the given key exists.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR alloc_hugepages ()
Packit 7cfc04
returns the allocated virtual address, and
Packit 7cfc04
.BR free_hugepages ()
Packit 7cfc04
returns zero.
Packit 7cfc04
On error, \-1 is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
is set appropriately.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B ENOSYS
Packit 7cfc04
The system call is not supported on this kernel.
Packit 7cfc04
.SH FILES
Packit 7cfc04
.TP
Packit 7cfc04
.I /proc/sys/vm/nr_hugepages
Packit 7cfc04
Number of configured hugetlb pages.
Packit 7cfc04
This can be read and written.
Packit 7cfc04
.TP
Packit 7cfc04
.I /proc/meminfo
Packit 7cfc04
Gives info on the number of configured hugetlb pages and on their size
Packit 7cfc04
in the three variables HugePages_Total, HugePages_Free, Hugepagesize.
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
These calls are specific to Linux on Intel processors, and should not be
Packit 7cfc04
used in programs intended to be portable.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
These system calls are gone;
Packit 7cfc04
they existed only in Linux 2.5.36 through to 2.5.54.
Packit 7cfc04
Now the hugetlbfs filesystem can be used instead.
Packit 7cfc04
Memory backed by huge pages (if the CPU supports them) is obtained by
Packit 7cfc04
using
Packit 7cfc04
.BR mmap (2)
Packit 7cfc04
to map files in this virtual filesystem.
Packit 7cfc04
.PP
Packit 7cfc04
The maximal number of huge pages can be specified using the
Packit 7cfc04
.B hugepages=
Packit 7cfc04
boot parameter.
Packit 7cfc04
.PP
Packit 7cfc04
.\" requires CONFIG_HUGETLB_PAGE (under "Processor type and features")
Packit 7cfc04
.\" and CONFIG_HUGETLBFS (under "Filesystems").
Packit 7cfc04
.\" mount -t hugetlbfs hugetlbfs /huge
Packit 7cfc04
.\" SHM_HUGETLB
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.