|
Packit Service |
724aca |
# Memkind examples
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
The example directory contains example codes that use the memkind
|
|
Packit Service |
724aca |
interface.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
## PMEM
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
The pmem_*.c(pp) demonstrates how to create and use a file-backed memory kind.
|
|
Packit Service |
724aca |
The default pmem path is "/tmp/".
|
|
Packit Service |
724aca |
Custom directory is pass as first argument to all of PMEM example programs,
|
|
Packit Service |
724aca |
e.g. to execute pmem_malloc example in /mnt/pmem location, call:
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
./pmem_malloc /mnt/pmem/
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_kinds.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to create and destroy pmem kind with defined or unlimited size.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_malloc.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to allocate memory and possibility to exceed pmem kind size.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_malloc_unlimited.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to allocate memory with unlimited kind size.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_usable_size.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows difference between the expected and the actual allocation size.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_alignment.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to use memkind alignment and how it affects allocations.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_multithreads.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to use multithreading with independent pmem kinds.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_multithreads_onekind.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to use multithreading with one main pmem kind.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_and_dax_kmem_kind.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to allocate to PMEM memory using file-backed memory (pmem kind)
|
|
Packit Service |
724aca |
and persistent memory NUMA node (MEMKIND_DAX_KMEM).
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_and_default_kind.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to allocate in standard memory and file-backed memory (pmem kind).
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_detect_kind.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to distinguish allocation from different kinds using detect kind function.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_config.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to use custom configuration to create pmem kind.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_free_with_unknown_kind.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to allocate in standard memory and file-backed memory (pmem kind)
|
|
Packit Service |
724aca |
and free memory without a need to remember which kind it belongs to.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### pmem_cpp_allocator.cpp
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows usage of C++ allocator mechanism designed for file-backed memory
|
|
Packit Service |
724aca |
kind with different data structures like: vector, list and map.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
## Other memkind examples
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### memkind_get_stat.c
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows how to get information about allocator and kind statistics.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### other
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
The simplest example is the hello_example.c which is a hello world
|
|
Packit Service |
724aca |
variant. The filter_example.c shows how you would use high bandwidth
|
|
Packit Service |
724aca |
memory to store a reduction of a larger data set stored in DDR. There is
|
|
Packit Service |
724aca |
also an example of how to create user defined kinds. This example
|
|
Packit Service |
724aca |
creates kinds which isolate allocations to a single NUMA node each
|
|
Packit Service |
724aca |
backed by a single arena.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
### memkind_cpp_allocator.cpp
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
This example shows usage of C++ allocator mechanism designed for static
|
|
Packit Service |
724aca |
kinds with different data structures like: forward list, deque and multiset.
|
|
Packit Service |
724aca |
|
|
Packit Service |
724aca |
The memkind_allocated example is simple usage of memkind in C++11 which
|
|
Packit Service |
724aca |
shows how memkind can be used to allocate objects, and consists of two files:
|
|
Packit Service |
724aca |
memkind_allocated.hpp - which is definition of template class that should be
|
|
Packit Service |
724aca |
inherited and parametrized by derived type (curiously recurring template
|
|
Packit Service |
724aca |
pattern), to let deriving class allocate their objects using specified kind.
|
|
Packit Service |
724aca |
memkind_allocated_example.cpp - which is usage example of this approach.
|
|
Packit Service |
724aca |
Logic of memkind_allocated is based on overriding operator new() in template,
|
|
Packit Service |
724aca |
and allocating memory on kind specified in new() parameter, or by overridable
|
|
Packit Service |
724aca |
static method getClassKind(). This implementation also supports alignment
|
|
Packit Service |
724aca |
specifier's (alignas() - new feature in C++11).
|
|
Packit Service |
724aca |
The downside of this approach is that it will work properly only if
|
|
Packit Service |
724aca |
memkind_allocated template is inherited once in inheritance chain (which
|
|
Packit Service |
724aca |
probably makes that not very useful for most scenarios). Other thing is that it
|
|
Packit Service |
724aca |
overriding class new() operator which can cause various problems if used
|
|
Packit Service |
724aca |
unwisely.
|