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

384 lines
7.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GET_MEMPOLICY</TITLE>
</HEAD><BODY>
<H1>GET_MEMPOLICY</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>
get_mempolicy - retrieve NUMA memory policy for a thread
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/numaif.h">numaif.h</A>&gt;</B>
<PRE>
<B>long get_mempolicy(int *</B><I>mode</I><B>, unsigned long *</B><I>nodemask</I><B>,</B>
<B> unsigned long </B><I>maxnode</I><B>, void *</B><I>addr</I><B>,</B>
<B> unsigned long </B><I>flags</I><B>);</B>
Link with <I>-lnuma</I>.
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>get_mempolicy</B>()
retrieves the NUMA policy of the calling thread or of a memory address,
depending on the setting of
<I>flags</I>.
<P>
A NUMA machine has different
memory controllers with different distances to specific CPUs.
The memory policy defines from which node memory is allocated for
the thread.
<P>
If
<I>flags</I>
is specified as 0,
then information about the calling thread's default policy
(as set by
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2))
is returned, in the buffers pointed to by
<I>mode</I>
and
<I>nodemask</I>.
The value returned in these arguments
may be used to restore the thread's policy to its state at
the time of the call to
<B>get_mempolicy</B>()
using
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2).
When
<I>flags</I>
is 0,
<I>addr</I>
must be specified as NULL.
<P>
If
<I>flags</I>
specifies
<B>MPOL_F_MEMS_ALLOWED</B>
(available since Linux 2.6.24), the
<I>mode</I>
argument is ignored and the set of nodes (memories) that the
thread is allowed to specify in subsequent calls to
<B><A HREF="/cgi-bin/man/man2html?2+mbind">mbind</A></B>(2)
or
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2)
(in the absence of any
<I>mode flags</I>)
is returned in
<I>nodemask</I>.
It is not permitted to combine
<B>MPOL_F_MEMS_ALLOWED</B>
with either
<B>MPOL_F_ADDR</B>
or
<B>MPOL_F_NODE</B>.
<P>
If
<I>flags</I>
specifies
<B>MPOL_F_ADDR</B>,
then information is returned about the policy governing the memory
address given in
<I>addr</I>.
This policy may be different from the thread's default policy if
<B><A HREF="/cgi-bin/man/man2html?2+mbind">mbind</A></B>(2)
or one of the helper functions described in
<B><A HREF="/cgi-bin/man/man2html?3+numa">numa</A></B>(3)
has been used to establish a policy for the memory range containing
<I>addr</I>.
<P>
If the
<I>mode</I>
argument is not NULL, then
<B>get_mempolicy</B>()
will store the policy mode and any optional
<I>mode flags</I>
of the requested NUMA policy in the location pointed to by this argument.
If
<I>nodemask</I>
is not NULL, then the nodemask associated with the policy will be stored
in the location pointed to by this argument.
<I>maxnode</I>
specifies the number of node IDs
that can be stored into
<I>nodemask</I>---that
is, the maximum node ID plus one.
The value specified by
<I>maxnode</I>
is always rounded to a multiple of
<I>sizeof(unsigned&nbsp;long)*8</I>.
<P>
If
<I>flags</I>
specifies both
<B>MPOL_F_NODE</B>
and
<B>MPOL_F_ADDR</B>,
<B>get_mempolicy</B>()
will return the node ID of the node on which the address
<I>addr</I>
is allocated into the location pointed to by
<I>mode</I>.
If no page has yet been allocated for the specified address,
<B>get_mempolicy</B>()
will allocate a page as if the thread had performed a read
(load) access to that address, and return the ID of the node
where that page was allocated.
<P>
If
<I>flags</I>
specifies
<B>MPOL_F_NODE</B>,
but not
<B>MPOL_F_ADDR</B>,
and the thread's current policy is
<B>MPOL_INTERLEAVE</B>,
then
<B>get_mempolicy</B>()
will return in the location pointed to by a non-NULL
<I>mode</I>
argument,
the node ID of the next node that will be used for
interleaving of internal kernel pages allocated on behalf of the thread.
These allocations include pages for memory-mapped files in
process memory ranges mapped using the
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2)
call with the
<B>MAP_PRIVATE</B>
flag for read accesses, and in memory ranges mapped with the
<B>MAP_SHARED</B>
flag for all accesses.
<P>
Other flag values are reserved.
<P>
For an overview of the possible policies see
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
On success,
<B>get_mempolicy</B>()
returns 0;
on error, -1 is returned and
<I>errno</I>
is set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="1"><B>EFAULT</B>
<DD>
Part of all of the memory range specified by
<I>nodemask</I>
and
<I>maxnode</I>
points outside your accessible address space.
<DT id="2"><B>EINVAL</B>
<DD>
The value specified by
<I>maxnode</I>
is less than the number of node IDs supported by the system.
Or
<I>flags</I>
specified values other than
<B>MPOL_F_NODE</B>
or
<B>MPOL_F_ADDR</B>;
or
<I>flags</I>
specified
<B>MPOL_F_ADDR</B>
and
<I>addr</I>
is NULL,
or
<I>flags</I>
did not specify
<B>MPOL_F_ADDR</B>
and
<I>addr</I>
is not NULL.
Or,
<I>flags</I>
specified
<B>MPOL_F_NODE</B>
but not
<B>MPOL_F_ADDR</B>
and the current thread policy is not
<B>MPOL_INTERLEAVE</B>.
Or,
<I>flags</I>
specified
<B>MPOL_F_MEMS_ALLOWED</B>
with either
<B>MPOL_F_ADDR</B>
or
<B>MPOL_F_NODE</B>.
(And there are other
<B>EINVAL</B>
cases.)
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
The
<B>get_mempolicy</B>()
system call was added to the Linux kernel in version 2.6.7.
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
This system call is Linux-specific.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
For information on library support, see
<B><A HREF="/cgi-bin/man/man2html?7+numa">numa</A></B>(7).
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+getcpu">getcpu</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mbind">mbind</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+mmap">mmap</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+set_mempolicy">set_mempolicy</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+numa">numa</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?7+numa">numa</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?8+numactl">numactl</A></B>(8)
<A NAME="lbAK">&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="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="8"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
<DT id="11"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="12"><A HREF="#lbAK">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>