1LIBVMMALLOC(7)             VMEM Programmer's Manual             LIBVMMALLOC(7)
2
3
4

NAME

6       libvmmalloc - general purpose volatile memory allocation library
7

SYNOPSIS

9              $ LD_PRELOAD=libvmmalloc.so.1 command [ args... ]
10
11       or
12
13              #include <stdlib.h>
14              #ifndef __FreeBSD__
15                  #include <malloc.h>
16              #else
17                  #include <malloc_np.h>
18              #endif
19              #include <libvmmalloc.h>
20
21              cc [ flag... ] file... -lvmmalloc [ library... ]
22
23              void *malloc(size_t size);
24              void free(void *ptr);
25              void *calloc(size_t number, size_t size);
26              void *realloc(void *ptr, size_t size);
27              int posix_memalign(void **memptr, size_t alignment, size_t size);
28              void *aligned_alloc(size_t alignment, size_t size);
29              void *memalign(size_t alignment, size_t size);
30              void *valloc(size_t size);
31              void *pvalloc(size_t size);
32              size_t malloc_usable_size(const void *ptr);
33              void cfree(void *ptr);
34

DESCRIPTION

36       libvmmalloc  transparently converts all dynamic memory allocations into
37       Persistent Memory allocations.
38
39       The typical usage of libvmmalloc does not require any  modification  of
40       the  target program.  It is enough to load libvmmalloc before all other
41       libraries by setting the environment variable LD_PRELOAD.  When used in
42       that  way, libvmmalloc interposes the standard system memory allocation
43       routines, as defined in  malloc(3),  posix_memalign(3)  and  malloc_us‐
44       able_size(3), and provides that all dynamic memory allocations are made
45       from a memory pool built on a memory-mapped file, instead of the system
46       heap.  The memory managed by libvmmalloc may have different attributes,
47       depending on the file system containing the memory-mapped file.
48
49       This library is no longer actively developed,  and  is  in  maintenance
50       mode, same as its underlying code backend (libvmem).  It is mature, and
51       is expected to be supported for foreseable future.
52
53       libvmmalloc may be also linked to the program, by providing the **-lvm‐
54       malloc* argument to the linker.  Then it becomes the default memory al‐
55       locator for the program.
56
57              NOTE: Due to the fact the library operates  on  a  memory-mapped
58              file,  it  may  not  work  properly  with  programs that perform
59              fork(2) not followed by exec(3). There are two variants  of  ex‐
60              perimental  fork(2)  support  available in libvmmalloc.  The de‐
61              sired library behavior may be selected  by  setting  the  VMMAL‐
62              LOC_FORK  environment  variable.   By  default variant #1 is en‐
63              abled.  See ENVIRONMENT for more details.
64
65       libvmmalloc uses the mmap(2) system call to create a pool  of  volatile
66       memory.   The library is most useful when used with Direct Access stor‐
67       age (DAX), which is memory-addressable persistent storage that supports
68       load/store  access  without  being  paged via the system page cache.  A
69       Persistent Memory-aware file system is typically used to  provide  this
70       type  of  access.  Memory-mapping a file from a Persistent Memory-aware
71       file system provides the raw memory pools, and  this  library  supplies
72       the traditional malloc interfaces on top of those pools.
73
74       The memory pool acting as a system heap replacement is created automat‐
75       ically at library initialization time.  The user may control its  loca‐
76       tion  and  size by setting the environment variables described in ENVI‐
77       RONMENT, below.  The allocated file space is reclaimed when the process
78       terminates or in case of system crash.
79
80       Under normal usage, libvmmalloc will never print messages or intention‐
81       ally cause the process to exit.  The library  uses  pthreads(7)  to  be
82       fully  MT-safe,  but never creates or destroys threads itself.  The li‐
83       brary does not make use of any signals, networking, and never calls se‐
84       lect(2) or poll(2).
85

ENVIRONMENT

87       The VMMALLOC_POOL_DIR and VMMALLOC_POOL_SIZE environment variables must
88       be set for libvmmalloc to work properly.  If  either  of  them  is  not
89       specified,  or if their values are not valid, the library prints an ap‐
90       propriate error message and terminates the process.  Any other environ‐
91       ment variables are optional.
92
93       · VMMALLOC_POOL_DIR=path
94
95       Specifies  a path to the directory where the memory pool file should be
96       created.  The directory must exist and be writable.
97
98       · VMMALLOC_POOL_SIZE=len
99
100       Defines the desired size (in bytes) of the memory pool file.   It  must
101       be  not less than the minimum allowed size VMMALLOC_MIN_POOL as defined
102       in <libvmmalloc.h>.
103
104              NOTE: Due to the fact the library adds some metadata to the mem‐
105              ory  pool,  the  amount of actual usable space is typically less
106              than the size of the memory pool file.
107
108       · VMMALLOC_FORK=val (EXPERIMENTAL)
109
110       VMMALLOC_FORK controls the behavior of libvmmalloc in case of  fork(3),
111       and can be set to the following values:
112
113       · 0  -  fork(2)  support is disabled.  The behavior of fork(2) is unde‐
114         fined in this case, but most likely results in memory pool corruption
115         and a program crash due to segmentation fault.
116
117       · 1 - The memory pool file is remapped with the MAP_PRIVATE flag before
118         the fork completes.  From this moment, any access to memory that mod‐
119         ifies  the  heap  pages, both in the parent and in the child process,
120         will  trigger  creation  of  a   copy   of   those   pages   in   RAM
121         (copy-on-write).   The  benefit  of this approach is that it does not
122         significantly increase the time of the initial  fork  operation,  and
123         does  not  require additional space on the file system.  However, all
124         subsequent memory allocations, and modifications of any memory  allo‐
125         cated  before  fork,  will consume system memory resources instead of
126         the memory pool.
127
128       This is the default option if VMMALLOC_FORK is not set.
129
130       · 2 - A copy of the entire memory pool file is created for the  use  of
131         the  child  process.  This requires additional space on the file sys‐
132         tem, but both the parent and the child process may still  operate  on
133         their memory pools, not consuming system memory resources.
134
135         NOTE: In case of large memory pools, creating a copy of the pool file
136         may stall the fork operation for a quite long time.
137
138       · 3 - The library first attempts to create a copy of  the  memory  pool
139         (as  for  option  #2),  but if it fails (i.e. because of insufficient
140         free space on the file system), it will fall back to option #1.
141
142         NOTE: Options 2 and 3 are not currently supported on FreeBSD.
143
144       Environment variables used for debugging are  described  in  DEBUGGING,
145       below.
146

CAVEATS

148       libvmmalloc relies on the library destructor being called from the main
149       thread.  For this reason, all functions that might trigger  destruction
150       (e.g.  dlclose(3)) should be called in the main thread.  Otherwise some
151       of the resources associated with that thread might not  be  cleaned  up
152       properly.
153

DEBUGGING

155       Two  versions  of  libvmmalloc are typically available on a development
156       system.  The normal version is optimized for performance.  That version
157       skips  checks that impact performance and never logs any trace informa‐
158       tion or performs any run-time assertions.  A second  version,  accessed
159       when using libraries from /usr/lib/vmem_debug, contains run-time asser‐
160       tions and trace points.  The typical way to access the debug version is
161       to  set the LD_LIBRARY_PATH environment variable to /usr/lib/vmem_debug
162       or /usr/lib64/vmem_debug, as appropriate.   Debugging  output  is  con‐
163       trolled  using  the  following  environment variables.  These variables
164       have no effect on the non-debug version of the library.
165
166       · VMMALLOC_LOG_LEVEL
167
168       The value of VMMALLOC_LOG_LEVEL enables trace points in the debug  ver‐
169       sion of the library, as follows:
170
171       · 0  -  Tracing  is  disabled.   This  is the default level when VMMAL‐
172         LOC_LOG_LEVEL is not set.
173
174       · 1 - Additional details on any errors detected are logged, in addition
175         to returning the errno-based errors as usual.
176
177       · 2 - A trace of basic operations is logged.
178
179       · 3 - Enables a very verbose amount of function call tracing in the li‐
180         brary.
181
182       · 4 - Enables voluminous tracing information about all  memory  alloca‐
183         tions and deallocations.
184
185       Unless VMMALLOC_LOG_FILE is set, debugging output is written to stderr.
186
187       · VMMALLOC_LOG_FILE
188
189       Specifies  the  name  of a file where all logging information should be
190       written.  If the last character in the name is “-”, the PID of the cur‐
191       rent  process  will  be  appended to the file name when the log file is
192       created.  If VMMALLOC_LOG_FILE is not set, output is written to stderr.
193
194       · VMMALLOC_LOG_STATS
195
196       Setting VMMALLOC_LOG_STATS to 1 enables logging human-readable  summary
197       statistics at program termination.
198

NOTES

200       Unlike the normal malloc(3), which asks the system for additional memo‐
201       ry when it runs out, libvmmalloc allocates the size it is told  to  and
202       never attempts to grow or shrink that memory pool.
203

BUGS

205       libvmmalloc  may  not  work properly with programs that perform fork(2)
206       and do not call exec(3) immediately afterwards.   See  ENVIRONMENT  for
207       more details about experimental fork(2) support.
208
209       If  logging  is  enabled  in  the  debug version of the library and the
210       process performs fork(2), no new log file  is  created  for  the  child
211       process,  even if the configured log file name ends with “-”.  All log‐
212       ging information from the child process will be written to the log file
213       owned  by  the  parent process, which may lead to corruption or partial
214       loss of log data.
215
216       Malloc hooks (see malloc_hook(3)), are not supported when using  libvm‐
217       malloc.
218

ACKNOWLEDGEMENTS

220       libvmmalloc  depends  on  jemalloc,  written  by Jason Evans, to do the
221       heavy  lifting   of   managing   dynamic   memory   allocation.    See:
222       <http://www.canonware.com/jemalloc>
223

SEE ALSO

225       fork(2),   dlclose(3),   exec(3),   malloc(3),   malloc_usable_size(3),
226       posix_memalign(3), libpmem(7), libvmem(7) and <http://pmem.io>
227
228       On Linux:
229
230       jemalloc(3), malloc_hook(3), pthreads(7), ld.so(8)
231
232       On FreeBSD:
233
234       ld.so(1), pthread(3)
235
236
237
238VMEM - vmmalloc API version 1.1   2020-01-27                    LIBVMMALLOC(7)
Impressum