---
name: "memkind_default"
section: "3"
platform: "linux"
package: "libmemkind-dev"
version: "1.14.0-2"
release: "Debian 12 (Bookworm)"
platforms: ["linux"]
url: "https://new.carta.tech/memkind_default"
---

# memkind\_default(3)

default implementations for memkind operations. Note: This is EXPERIMENTAL API. The functionality and the header file itself can be changed (including non-backward compatible changes), or removed.

## NAME

memkind\_default - default implementations for memkind operations.\
 **Note:** This is EXPERIMENTAL API. The functionality and the header file itself can be changed (including non-backward compatible changes), or removed.

## SYNOPSIS

**int memkind\_default\_create(struct memkind** *\*kind***, struct memkind\_ops** *\*ops***, const char** *\*name***);**\
 **int memkind\_default\_destroy(struct memkind** *\*kind***);**\
 **void \*memkind\_default\_malloc(struct memkind** *\*kind***, size\_t** *size***);**\
 **void \*memkind\_default\_calloc(struct memkind** *\*kind***, size\_t** *num***, size\_t** *size***);**\
 **int memkind\_default\_posix\_memalign(struct memkind** *\*kind***, void** *\*\*memptr***, size\_t** *alignment***, size\_t** *size***);**\
 **void \*memkind\_default\_realloc(struct memkind** *\*kind***, void** *\*ptr***, size\_t** *size***);**\
 **void memkind\_default\_free(struct memkind** *\*kind***, void** *\*ptr***);**\
 **void \*memkind\_default\_mmap(struct memkind** *\*kind***, void** *\*addr***, size\_t** *size***);**\
 **int memkind\_default\_mbind(struct memkind** *\*kind***, void** *\*ptr***, size\_t** *len***);**\
 **int memkind\_default\_get\_mmap\_flags(struct memkind** *\*kind***, int** *\*flags***);**\
 **int memkind\_default\_get\_mbind\_mode(struct memkind** *\*kind***, int** *\*mode***);**\
 **size\_t memkind\_default\_malloc\_usable\_size(struct memkind** *\*kind***, void** *\*ptr***);**\
 **int memkind\_preferred\_get\_mbind\_mode(struct memkind** *\*kind***, int** *\*mode***);**\
 **int memkind\_interleave\_get\_mbind\_mode(struct memkind** *\*kind***, int** *\*mode***);**\
 **int memkind\_nohugepage\_madvise(struct memkind** *\*kind***, void** *\*addr***, size\_t** *size***);**\
 **int memkind\_posix\_check\_alignment(struct memkind** *\*kind***, size\_t** *alignment***);**\
 **int memkind\_default\_get\_mbind\_nodemask(struct memkind** *\*kind***, unsigned long** *\*nodemask***, unsigned long** *maxnode***);**\
 **void memkind\_default\_init\_once(void);**\
 **bool size\_out\_of\_bounds(size\_t** *size***);**\

## DESCRIPTION

Default implementations for memkind operations which include a several useful methods that are not part of the **MEMKIND\_DEFAULT** kind which is a fall through to the jemalloc implementation.

**memkind\_default\_create**() implements the required start up for every kind. If a kind does not point to this function directly for its **ops.create**() operation, then the function that it points to must call **memkind\_default\_create**() at its start.

**memkind\_default\_destroy**() implements the required shutdown for every kind. If a kind does not point to this function directly for its **ops.destroy**() operation, then the function that it points to must call **memkind\_default\_destroy**() at its end.

**memkind\_default\_malloc**() is a direct call through the jemalloc's **malloc**().

**memkind\_default\_calloc**() is a direct call through the jemalloc's **calloc**().

**memkind\_default\_posix\_memalign**() is a direct call through the jemalloc's **posix\_memalign**().

**memkind\_default\_realloc**() is a direct call through the jemalloc's **realloc**().

**memkind\_default\_free**() is a direct call through the jemalloc's **free**(). Note that this method can be called on any pointer returned by a jemalloc allocation, and in particular, all of the arena allocations described in [**memkind\_arena**(3)](/memkind_arena/3.md) can use this function for freeing.

**memkind\_default\_mmap**() This calls the ops-\>get\_mmap\_flags() operations for the kind, or falls back on the default implementations if the function pointers are *NULL*. The results of these calls are passed to the [**mmap**(2)](/mmap/2.md) call to allocate pages from the operating system.  The *addr* is the hint passed through to [**mmap**(2)](/mmap/2.md) and *size* is the size of the buffer to be allocated.  The return value is the allocated buffer or **MAP\_FAILED** in the case of an error.

**memkind\_default\_mbind**() makes calls the kind's **ops.get\_mbind\_nodemask**() and **ops.get\_mbind\_mode**() operations to gather inputs and then calls the [**mbind**(2)](/mbind/2.md) system call using the results along with and user input *ptr* and *len*.

**memkind\_default\_get\_mmap\_flags**() sets *flags* to **MAP\_PRIVATE \| MAP\_ANONYMOUS**. See [**mmap**(2)](/mmap/2.md) for more information about these flags.

**memkind\_default\_get\_mbind\_mode**() sets *mode* to **MPOL\_BIND**. See [**mbind**(2)](/mbind/2.md) for more information about this flag.

**memkind\_default\_malloc\_usable\_size**() is a direct call through the jemalloc's **malloc\_usable\_size**().

**memkind\_preferred\_get\_mbind\_mode**() sets *mode* to **MPOL\_PREFERRED**. See [**mbind**(2)](/mbind/2.md) for more information about this flag.

**memkind\_interleave\_get\_mbind\_mode**() sets *mode* to **MPOL\_INTERLEAVE**. See [**mbind**(2)](/mbind/2.md) for more information about this flag.

**memkind\_nohugepage\_madvise**() calls [**madvise**(2)](/madvise/2.md) with the **MADV\_NOHUGEPAGE** advice. See [**madvise**(2)](/madvise/2.md) for more information about this option.

**memkind\_posix\_check\_alignment**() can be used to check the alignment value for **memkind\_posix\_memalign**() to ensure that is abides by the POSIX requirements: alignment must be a power of 2 at least as large as *sizeof(void\*)*.

**memkind\_default\_get\_mbind\_nodemask**() wraps jemalloc's **copy\_bitmask\_to\_bitmask**. This function copies body of the bitmask structure into passed pointer.

**memkind\_default\_init\_once**() initializes heap manager.

**size\_out\_of\_bounds**() returns true if given size is out of bounds, otherwise will return false.

## COPYRIGHT

Copyright (C) 2014 - 2020 Intel Corporation. All rights reserved.

## SEE ALSO

[**memkind**(3)](/memkind/3.md), [**memkind\_arena**(3)](/memkind_arena/3.md), [**memkind\_hbw**(3)](/memkind_hbw/3.md), [**memkind\_hugetlb**(3)](/memkind_hugetlb/3.md), [**memkind\_pmem**(3)](/memkind_pmem/3.md), [**jemalloc**(3)](/jemalloc/3.md), [**mbind**(2)](/mbind/2.md), [**mmap**(2)](/mmap/2.md)
