man-pages/man2/alloc_hugepages.2.html
2021-03-31 01:06:50 +01:00

223 lines
4.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of ALLOC_HUGEPAGES</TITLE>
</HEAD><BODY>
<H1>ALLOC_HUGEPAGES</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
alloc_hugepages, free_hugepages - allocate or free huge pages
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>void *alloc_hugepages(int </B><I>key</I><B>, void *</B><I>addr</I><B>, size_t </B><I>len</I><B>,</B>
<B> int </B><I>prot</I><B>, int </B><I>flag</I><B>);</B>
<B>int free_hugepages(void *</B><I>addr</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The system calls
<B>alloc_hugepages</B>()
and
<B>free_hugepages</B>()
were introduced in Linux 2.5.36 and removed again in 2.5.54.
They existed only on i386 and ia64 (when built with
<B>CONFIG_HUGETLB_PAGE</B>).
In Linux 2.4.20, the syscall numbers exist,
but the calls fail with the error
<B>ENOSYS</B>.
<P>
On i386 the memory management hardware knows about ordinary pages (4&nbsp;KiB)
and huge pages (2 or 4&nbsp;MiB).
Similarly ia64 knows about huge pages of
several sizes.
These system calls serve to map huge pages into the
process's memory or to free them again.
Huge pages are locked into memory, and are not swapped.
<P>
The
<I>key</I>
argument is an identifier.
When zero the pages are private, and
not inherited by children.
When positive the pages are shared with other applications using the same
<I>key</I>,
and inherited by child processes.
<P>
The
<I>addr</I>
argument of
<B>free_hugepages</B>()
tells which page is being freed: it was the return value of a
call to
<B>alloc_hugepages</B>().
(The memory is first actually freed when all users have released it.)
The
<I>addr</I>
argument of
<B>alloc_hugepages</B>()
is a hint, that the kernel may or may not follow.
Addresses must be properly aligned.
<P>
The
<I>len</I>
argument is the length of the required segment.
It must be a multiple of the huge page size.
<P>
The
<I>prot</I>
argument specifies the memory protection of the segment.
It is one of
<B>PROT_READ</B>,
<B>PROT_WRITE</B>,
<B>PROT_EXEC</B>.
<P>
The
<I>flag</I>
argument is ignored, unless
<I>key</I>
is positive.
In that case, if
<I>flag</I>
is
<B>IPC_CREAT</B>,
then a new huge page segment is created when none
with the given key existed.
If this flag is not set, then
<B>ENOENT</B>
is returned when no segment with the given key exists.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>alloc_hugepages</B>()
returns the allocated virtual address, and
<B>free_hugepages</B>()
returns zero.
On error, -1 is returned, and
<I>errno</I>
is set appropriately.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>ENOSYS</B>
<DD>
The system call is not supported on this kernel.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="2"><I>/proc/sys/vm/nr_hugepages</I>
<DD>
Number of configured hugetlb pages.
This can be read and written.
<DT id="3"><I>/proc/meminfo</I>
<DD>
Gives info on the number of configured hugetlb pages and on their size
in the three variables HugePages_Total, HugePages_Free, Hugepagesize.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
These calls are specific to Linux on Intel processors, and should not be
used in programs intended to be portable.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
These system calls are gone;
they existed only in Linux 2.5.36 through to 2.5.54.
Now the hugetlbfs filesystem can be used instead.
Memory backed by huge pages (if the CPU supports them) is obtained by
using
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
to map files in this virtual filesystem.
<P>
The maximal number of huge pages can be specified using the
<B>hugepages=</B>
boot parameter.
<P>
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">FILES</A><DD>
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
<DT id="12"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:32 GMT, March 31, 2021
</BODY>
</HTML>