Blame man/hbwmalloc.3

Packit 345191
.\"
Packit 345191
.\" Copyright (C) 2014 - 2019 Intel Corporation.
Packit 345191
.\" All rights reserved.
Packit 345191
.\"
Packit 345191
.\" Redistribution and use in source and binary forms, with or without
Packit 345191
.\" modification, are permitted provided that the following conditions are met:
Packit 345191
.\" 1. Redistributions of source code must retain the above copyright notice(s),
Packit 345191
.\"    this list of conditions and the following disclaimer.
Packit 345191
.\" 2. Redistributions in binary form must reproduce the above copyright notice(s),
Packit 345191
.\"    this list of conditions and the following disclaimer in the documentation
Packit 345191
.\"    and/or other materials provided with the distribution.
Packit 345191
.\"
Packit 345191
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY EXPRESS
Packit 345191
.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
Packit 345191
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
Packit 345191
.\" EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit 345191
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 345191
.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Packit 345191
.\" PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Packit 345191
.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
Packit 345191
.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Packit 345191
.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 345191
.\"
Packit 345191
.TH "HBWMALLOC" 3 "2015-03-31" "Intel Corporation" "HBWMALLOC" \" -*- nroff -*-
Packit 345191
.SH "NAME"
Packit 345191
hbwmalloc \- The high bandwidth memory interface
Packit 345191
.br
Packit 345191
.BR Note:
Packit 345191
.I hbwmalloc.h
Packit 345191
functionality is considered as stable API (STANDARD API).
Packit 345191
.SH "SYNOPSIS"
Packit 345191
.nf
Packit 345191
.B #include <hbwmalloc.h>
Packit 345191
.sp
Packit 345191
.B Link with -lmemkind
Packit 345191
.sp
Packit 345191
.B int hbw_check_available(void);
Packit 345191
.br
Packit 345191
.BI "void* hbw_malloc(size_t " "size" );
Packit 345191
.br
Packit 345191
.BI "void* hbw_calloc(size_t " "nmemb" ", size_t " "size" );
Packit 345191
.br
Packit 345191
.BI "void* hbw_realloc (void " "*ptr" ", size_t " "size" );
Packit 345191
.br
Packit 345191
.BI "void hbw_free(void " "*ptr" );
Packit 345191
.br
Packit 345191
.BI "size_t hbw_malloc_usable_size(void " "*ptr" );
Packit 345191
.br
Packit 345191
.BI "int hbw_posix_memalign(void " "**memptr" ", size_t " "alignment" ", size_t " "size" );
Packit 345191
.br
Packit 345191
.BI "int hbw_posix_memalign_psize(void " "**memptr" ", size_t " "alignment" ", size_t " "size" ", hbw_pagesize_t " "pagesize" );
Packit 345191
.br
Packit 345191
.B hbw_policy_t hbw_get_policy(void);
Packit 345191
.br
Packit 345191
.BI "int hbw_set_policy(hbw_policy_t " "mode" );
Packit 345191
.br
Packit 345191
.BI "int hbw_verify_memory_region(void " "*addr" ", size_t " "size" ", int " "flags" );
Packit 345191
.fi
Packit 345191
.SH "DESCRIPTION"
Packit 345191
.BR hbw_check_available ()
Packit 345191
returns zero if high bandwidth memory is available or an error code
Packit 345191
described in the
Packit 345191
.B ERRORS
Packit 345191
section if not.
Packit 345191
.PP
Packit 345191
.BR hbw_malloc ()
Packit 345191
allocates
Packit 345191
.I size
Packit 345191
bytes of uninitialized high bandwidth memory. The allocated space is
Packit 345191
suitably aligned (after possible pointer coercion) for storage of any
Packit 345191
type of object. If
Packit 345191
.I size
Packit 345191
is zero then
Packit 345191
.BR hbw_malloc ()
Packit 345191
returns
Packit 345191
.IR "NULL" .
Packit 345191
.PP
Packit 345191
.BR hbw_calloc ()
Packit 345191
allocates space for
Packit 345191
.I nmemb
Packit 345191
objects in high bandwidth memory, each
Packit 345191
.I size
Packit 345191
bytes in length. The result is identical to calling
Packit 345191
.BR hbw_malloc ()
Packit 345191
with an argument of
Packit 345191
.IR "nmemb"
Packit 345191
*
Packit 345191
.IR "size" ,
Packit 345191
with the exception that the allocated memory is explicitly
Packit 345191
initialized to zero bytes.  If
Packit 345191
.I nmemb
Packit 345191
or
Packit 345191
.I size
Packit 345191
is 0, then
Packit 345191
.BR hbw_calloc ()
Packit 345191
returns
Packit 345191
.IR "NULL" .
Packit 345191
.PP
Packit 345191
.BR hbw_realloc ()
Packit 345191
changes the size of the previously allocated high bandwidth memory
Packit 345191
referenced by
Packit 345191
.I ptr
Packit 345191
to
Packit 345191
.I size
Packit 345191
bytes. The contents of the memory remain unchanged up to the lesser of
Packit 345191
the new and old sizes. If the new size is larger, the contents of the
Packit 345191
newly allocated portion of the memory are undefined. Upon success, the
Packit 345191
memory referenced by
Packit 345191
.I ptr
Packit 345191
is freed and a pointer to the newly allocated high bandwidth memory is
Packit 345191
returned.
Packit 345191
Packit 345191
.B Note:
Packit 345191
.BR hbw_realloc ()
Packit 345191
may move the memory allocation, resulting in a different return value
Packit 345191
than
Packit 345191
.IR "ptr" .
Packit 345191
Packit 345191
If
Packit 345191
.I ptr
Packit 345191
is
Packit 345191
.IR "NULL" ,
Packit 345191
the
Packit 345191
.BR hbw_realloc ()
Packit 345191
function behaves identically to
Packit 345191
.BR hbw_malloc ()
Packit 345191
for the specified size.
Packit 345191
If
Packit 345191
.I size
Packit 345191
is equal to zero, and
Packit 345191
.I ptr
Packit 345191
is not
Packit 345191
.IR "NULL" ,
Packit 345191
then the call is equivalent to
Packit 345191
.I hbw_free(ptr)
Packit 345191
and
Packit 345191
.I NULL
Packit 345191
is returned. The address
Packit 345191
.IR "ptr" ,
Packit 345191
if not
Packit 345191
.IR "NULL" ,
Packit 345191
was returned by a previous call to
Packit 345191
.BR hbw_malloc (),
Packit 345191
.BR hbw_calloc (),
Packit 345191
.BR hbw_realloc ()
Packit 345191
or
Packit 345191
.BR hbw_posix_memalign ().
Packit 345191
Otherwise, or if
Packit 345191
.I hbw_free(ptr)
Packit 345191
was called before, undefined behavior occurs.
Packit 345191
Packit 345191
.B Note:
Packit 345191
.BR hbw_realloc ()
Packit 345191
cannot be used with a pointer returned by
Packit 345191
.BR hbw_posix_memalign_psize ().
Packit 345191
Packit 345191
.PP
Packit 345191
.BR hbw_free ()
Packit 345191
causes the allocated memory referenced by
Packit 345191
.I ptr
Packit 345191
to be made available for future allocations. If
Packit 345191
.I ptr
Packit 345191
is
Packit 345191
.IR "NULL" ,
Packit 345191
no action occurs.
Packit 345191
The address
Packit 345191
.IR "ptr" ,
Packit 345191
if not
Packit 345191
.IR "NULL" ,
Packit 345191
must have been returned by a previous call to
Packit 345191
.BR hbw_malloc (),
Packit 345191
.BR hbw_calloc (),
Packit 345191
.BR hbw_realloc (),
Packit 345191
.BR hbw_posix_memalign ()
Packit 345191
or
Packit 345191
.BR hbw_posix_memalign_psize ().
Packit 345191
Otherwise, if
Packit 345191
.I hbw_free(ptr)
Packit 345191
was called before, undefined behavior occurs.
Packit 345191
.PP
Packit 345191
.BR hbw_malloc_usable_size ()
Packit 345191
returns the number of usable bytes in the block pointed to by
Packit 345191
.IR "ptr" ,
Packit 345191
a pointer to a block of memory allocated by
Packit 345191
.BR hbw_malloc (),
Packit 345191
.BR hbw_calloc (),
Packit 345191
.BR hbw_realloc (),
Packit 345191
.BR hbw_posix_memalign (),
Packit 345191
or
Packit 345191
.BR hbw_posix_memalign_psize ().
Packit 345191
.PP
Packit 345191
.BR hbw_posix_memalign ()
Packit 345191
allocates
Packit 345191
.I size
Packit 345191
bytes of high bandwidth memory such that the allocation's base address
Packit 345191
is an even multiple of
Packit 345191
.IR "alignment" ,
Packit 345191
and returns the allocation in the value pointed to by
Packit 345191
.IR "memptr" .
Packit 345191
The requested
Packit 345191
.I alignment
Packit 345191
must be a power of 2 at least as large as
Packit 345191
.IR "sizeof(void*)" .
Packit 345191
If
Packit 345191
.I size
Packit 345191
is 0, then
Packit 345191
.BR hbw_posix_memalign ()
Packit 345191
returns 0, with a
Packit 345191
.I NULL
Packit 345191
returned in
Packit 345191
.IR "memptr" .
Packit 345191
.PP
Packit 345191
.BR hbw_posix_memalign_psize ()
Packit 345191
allocates
Packit 345191
.I size
Packit 345191
bytes of high bandwidth memory such that the allocation's base address
Packit 345191
is an even multiple of
Packit 345191
.IR "alignment" ,
Packit 345191
and returns the allocation in the value pointed to by
Packit 345191
.IR "memptr" .
Packit 345191
The requested
Packit 345191
.I alignment
Packit 345191
must be a power of 2 at least as large as
Packit 345191
.IR "sizeof(void*)" .
Packit 345191
The memory will be allocated using pages determined by the
Packit 345191
.IR "pagesize"
Packit 345191
variable which may be one of the following enumerated values:
Packit 345191
.TP
Packit 345191
.B HBW_PAGESIZE_4KB
Packit 345191
The four kilobyte page size option. Note that with transparent huge
Packit 345191
pages enabled these allocations may be promoted by the operating
Packit 345191
system to two megabyte pages.
Packit 345191
.TP
Packit 345191
.B HBW_PAGESIZE_2MB
Packit 345191
The two megabyte page size option.
Packit 345191
.BR Note:
Packit 345191
This page size requires huge pages configuration described in
Packit 345191
.BR "SYSTEM CONFIGURATION"
Packit 345191
section.
Packit 345191
.TP
Packit 345191
.B HBW_PAGESIZE_1GB (DEPRECATED)
Packit 345191
This option allows the user to specify arbitrary sizes backed by
Packit 345191
1GB chunks of huge pages. Huge pages are allocated even if the
Packit 345191
size is not a modulo of 1GB.
Packit 345191
.BR Note:
Packit 345191
This page size requires huge pages configuration described in
Packit 345191
.BR "SYSTEM CONFIGURATION"
Packit 345191
section.
Packit 345191
.TP
Packit 345191
.B HBW_PAGESIZE_1GB_STRICT (DEPRECATED)
Packit 345191
The total size of the allocation must be a multiple of 1GB with
Packit 345191
this option, otherwise the allocation will fail.
Packit 345191
.BR Note:
Packit 345191
This page size requires huge pages configuration described in
Packit 345191
.BR "SYSTEM CONFIGURATION"
Packit 345191
section.
Packit 345191
.PP
Packit 345191
.BR Note:
Packit 345191
.BR HBW_PAGESIZE_2MB ,
Packit 345191
.BR HBW_PAGESIZE_1GB
Packit 345191
and
Packit 345191
.BR HBW_PAGESIZE_1GB_STRICT
Packit 345191
options are not supported with
Packit 345191
.BR HBW_POLICY_INTERLEAVE
Packit 345191
policy.
Packit 345191
.PP
Packit 345191
.BR hbw_get_policy ()
Packit 345191
returns the current fallback policy when insufficient high bandwidth
Packit 345191
memory is available.
Packit 345191
.PP
Packit 345191
.BR hbw_set_policy ()
Packit 345191
sets the current fallback policy. The policy can be modified only once in the lifetime of an application and before calling
Packit 345191
.BR hbw_malloc (),
Packit 345191
.BR hbw_calloc (),
Packit 345191
.BR hbw_realloc (),
Packit 345191
.BR hbw_posix_memalign (),
Packit 345191
or
Packit 345191
.BR hbw_posix_memalign_psize ()
Packit 345191
function.
Packit 345191
.br
Packit 345191
.BR Note:
Packit 345191
If the policy is not set, than
Packit 345191
.B HBW_POLICY_PREFERRED
Packit 345191
will be used by default.
Packit 345191
.TP
Packit 345191
.B HBW_POLICY_BIND
Packit 345191
If insufficient high bandwidth memory from the nearest NUMA node is
Packit 345191
available to satisfy a request, the allocated pointer is set to
Packit 345191
.I NULL
Packit 345191
and
Packit 345191
.I errno
Packit 345191
is set to
Packit 345191
.BR ENOMEM .
Packit 345191
If insufficient high bandwidth memory pages are
Packit 345191
available at fault time the Out Of Memory (OOM) Killer is triggered.
Packit 345191
Note that pages are faulted exclusively from the high bandwidth NUMA
Packit 345191
node nearest at time of allocation, not at time of fault.
Packit 345191
.TP
Packit 345191
.B HBW_POLICY_BIND_ALL
Packit 345191
If insufficient high bandwidth memory is available to satisfy a request,
Packit 345191
the allocated pointer is set to
Packit 345191
.I NULL
Packit 345191
and
Packit 345191
.I errno
Packit 345191
is set to
Packit 345191
.BR ENOMEM .
Packit 345191
If insufficient high bandwidth memory pages are
Packit 345191
available at fault time the Out Of Memory (OOM) Killer is triggered.
Packit 345191
Note that pages are faulted from the high bandwidth NUMA nodes.
Packit 345191
Nearest NUMA node is selected at time of page fault.
Packit 345191
.TP
Packit 345191
.B HBW_POLICY_PREFERRED
Packit 345191
If insufficient memory is available from the high bandwidth NUMA node
Packit 345191
closest at allocation time, fall back to standard memory (default)
Packit 345191
with the smallest NUMA distance.
Packit 345191
.TP
Packit 345191
.B HBW_POLICY_INTERLEAVE
Packit 345191
Interleave faulted pages from across all high bandwidth NUMA nodes
Packit 345191
using standard size pages (the Transparent Huge Page feature is
Packit 345191
disabled).
Packit 345191
.PP
Packit 345191
.BR hbw_verify_memory_region ()
Packit 345191
verifies if memory region fully falls into high bandwidth memory. Returns
Packit 345191
0 if memory address range from
Packit 345191
.IR "addr"
Packit 345191
to
Packit 345191
.IR "addr"
Packit 345191
+
Packit 345191
.IR "size"
Packit 345191
is allocated in high bandwidth memory,
Packit 345191
-1 if any fragment of memory was not backed by high bandwidth memory (e.g. when memory is not initialized)
Packit 345191
or one of error codes described in
Packit 345191
.B ERRORS
Packit 345191
section.
Packit 345191
Packit 345191
Using this function in production code may result in serious performance penalty.
Packit 345191
Packit 345191
The
Packit 345191
.IR Flags
Packit 345191
argument may include optional flags that modify function behavior:
Packit 345191
.TP
Packit 345191
.B HBW_TOUCH_PAGES
Packit 345191
Before checking pages, function will touch first byte of all pages in address range starting from
Packit 345191
.IR "addr"
Packit 345191
to
Packit 345191
.IR "addr"
Packit 345191
+
Packit 345191
.IR "size"
Packit 345191
by read and write (so the content will be overwritten by the same data as it was read).
Packit 345191
Using this option may trigger Out Of Memory Killer.
Packit 345191
.SH "RETURN VALUE"
Packit 345191
.BR hbw_get_policy ()
Packit 345191
returns
Packit 345191
.BR HBW_POLICY_BIND,
Packit 345191
.BR HBW_POLICY_BIND_ALL,
Packit 345191
.BR HBW_POLICY_PREFERRED
Packit 345191
or
Packit 345191
.BR HBW_POLICY_INTERLEAVE
Packit 345191
which represents the current high bandwidth policy.
Packit 345191
.BR hbw_free ()
Packit 345191
do not have return value.
Packit 345191
.BR hbw_malloc ()
Packit 345191
.BR hbw_calloc ()
Packit 345191
and
Packit 345191
.BR hbw_realloc ()
Packit 345191
return the pointer to the allocated memory, or
Packit 345191
.I NULL
Packit 345191
if the request fails.
Packit 345191
.BR hbw_posix_memalign (),
Packit 345191
.BR hbw_posix_memalign_psize ()
Packit 345191
and
Packit 345191
.BR hbw_set_policy ()
Packit 345191
return zero on success and return an error code
Packit 345191
as described in the
Packit 345191
.B ERRORS
Packit 345191
section below on failure.
Packit 345191
.SH ERRORS
Packit 345191
.TP
Packit 345191
Error codes described here are the POSIX standard error codes as defined in
Packit 345191
.I <errno.h>
Packit 345191
.TP
Packit 345191
.BR hbw_check_available ()
Packit 345191
returns
Packit 345191
.BR ENODEV
Packit 345191
if high-bandwidth memory is unavailable.
Packit 345191
.TP
Packit 345191
.BR "hbw_posix_memalign" "() and " "hbw_posix_memalign_psize" "()"
Packit 345191
If the
Packit 345191
.I alignment
Packit 345191
parameter is not a power of two, or was not a multiple of
Packit 345191
.IR "sizeof(void*)" ,
Packit 345191
then
Packit 345191
.B EINVAL
Packit 345191
is returned.
Packit 345191
If the policy and
Packit 345191
.I pagesize
Packit 345191
combination is unsupported then
Packit 345191
.B EINVAL
Packit 345191
is returned.
Packit 345191
If there was insufficient memory to satisfy the request then
Packit 345191
.B ENOMEM
Packit 345191
is returned.
Packit 345191
.TP
Packit 345191
.BR hbw_set_policy ()
Packit 345191
returns
Packit 345191
.B EPERM
Packit 345191
if
Packit 345191
.BR hbw_set_policy ()
Packit 345191
was called more than once, or
Packit 345191
.B EINVAL
Packit 345191
if
Packit 345191
.I mode
Packit 345191
argument was neither
Packit 345191
.BR HBW_POLICY_PREFERRED ,
Packit 345191
.BR HBW_POLICY_BIND ,
Packit 345191
.BR HBW_POLICY_BIND_ALL
Packit 345191
nor
Packit 345191
.BR HBW_POLICY_INTERLEAVE .
Packit 345191
.TP
Packit 345191
.BR hbw_verify_memory_region ()
Packit 345191
returns
Packit 345191
.B EINVAL
Packit 345191
if
Packit 345191
.IR "addr"
Packit 345191
is
Packit 345191
.IR "NULL" ,
Packit 345191
.IR "size"
Packit 345191
equals 0 or
Packit 345191
.IR "flags"
Packit 345191
contained unsupported bit set. If memory pointed by
Packit 345191
.IR "addr"
Packit 345191
could not be verified then
Packit 345191
.B EFAULT
Packit 345191
is returned.
Packit 345191
.SH "NOTES"
Packit 345191
The
Packit 345191
.I <hbwmalloc.h>
Packit 345191
file defines the external functions and enumerations for the hbwmalloc
Packit 345191
library. These interfaces define a heap manager that targets high
Packit 345191
bandwidth memory numa nodes.
Packit 345191
.SH "FILES"
Packit 345191
.TP
Packit 345191
.I /usr/bin/memkind-hbw-nodes
Packit 345191
Prints a comma-separated list of high bandwidth nodes.
Packit 345191
.SH "ENVIRONMENT"
Packit 345191
.TP
Packit 345191
.B MEMKIND_HBW_NODES
Packit 345191
This environment variable is a comma-separated list of NUMA nodes that
Packit 345191
are treated as high bandwidth. Uses the
Packit 345191
.I libnuma
Packit 345191
routine
Packit 345191
.BR numa_parse_nodestring ()
Packit 345191
for parsing, so the syntax described in the
Packit 345191
.BR numa (3)
Packit 345191
man page for this routine applies for example: 1-3,5 is a valid setting.
Packit 345191
.TP
Packit 345191
.B MEMKIND_ARENA_NUM_PER_KIND
Packit 345191
This environment variable allows leveraging internal mechanism of
Packit 345191
the library for setting number of arenas per kind. Value should be
Packit 345191
a positive integer (not greater than
Packit 345191
.B INT_MAX
Packit 345191
defined in
Packit 345191
.IR <limits.h> ).
Packit 345191
The user should set the value based on the characteristics
Packit 345191
of application that is using the library. Higher value can
Packit 345191
provide better performance in extremely multithreaded applications at
Packit 345191
the cost of memory overhead. See section
Packit 345191
.BR "IMPLEMENTATION NOTES"
Packit 345191
of
Packit 345191
.BR jemalloc (3)
Packit 345191
for more details about arenas.
Packit 345191
.TP
Packit 345191
.B MEMKIND_HEAP_MANAGER
Packit 345191
Controls heap management behavior in memkind library by switching to one of the available heap managers.
Packit 345191
.br
Packit 345191
Values:
Packit 345191
.br
Packit 345191
    JEMALLOC - sets the jemalloc heap manager
Packit 345191
.br
Packit 345191
    TBB - sets the Intel Threading Building Blocks heap manager. This option requires installed
Packit 345191
    Intel Threading Building Blocks library.
Packit 345191
.PP
Packit 345191
.BR Note:
Packit 345191
If the
Packit 345191
.B MEMKIND_HEAP_MANAGER
Packit 345191
is not set then the jemalloc heap manager will be used by default.
Packit 345191
.SH "SYSTEM CONFIGURATION"
Packit 345191
Interfaces for obtaining 2MB (HUGETLB) memory need allocated
Packit 345191
huge pages in the kernel's huge page pool.
Packit 345191
.TP
Packit 345191
.B HUGETLB (huge pages)
Packit 345191
Current number of "persistent" huge pages can be read from
Packit 345191
.I /proc/sys/vm/nr_hugepages
Packit 345191
file.
Packit 345191
Proposed way of setting hugepages is:
Packit 345191
.BR "sudo sysctl vm.nr_hugepages=<number_of_hugepages>" .
Packit 345191
More information can be found here:
Packit 345191
.UR https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
Packit 345191
.UE
Packit 345191
.SH "KNOWN ISSUES"
Packit 345191
.TP
Packit 345191
.B HUGETLB (huge pages)
Packit 345191
There might be some overhead in huge pages consumption caused by heap management.
Packit 345191
If your allocation fails because of OOM, please try to allocate extra huge pages (e.g. 8 huge pages).
Packit 345191
.SH "COPYRIGHT"
Packit 345191
Copyright (C) 2014 - 2019 Intel Corporation. All rights reserved.
Packit 345191
.SH "SEE ALSO"
Packit 345191
.BR malloc (3),
Packit 345191
.BR numa (3),
Packit 345191
.BR numactl (8),
Packit 345191
.BR mbind (2),
Packit 345191
.BR mmap (2),
Packit 345191
.BR move_pages (2),
Packit 345191
.BR jemalloc (3),
Packit 345191
.BR memkind (3)