Vmalloc - A Discipline and Method Library for Memory Allocation

Kiem-Phong Vo

Vmalloc is a library for dynamic memory allocation. It enables applications to create and allocate from regions of memory. Each region has an application-defined discipline and a library-provided method. A Vmalloc discipline primarily defines the memory type to be used. This may include shared, memory mapped, heap memory or even memory obtained from another region. Other uses of disciplines are for handling various exceptions that may arise during allocation. A Vmalloc method defines the allocation policy in a region. An allocation policy would then define the memory lay-out as well as the data structures and algorithms used to efficiently allocate memory. The current set of methods include:

  • Vmbest: A general purpose allocator based on a best-fit strategy but enhanced with caching strategies to improve allocation efficiency.
  • Vmlast: A strategy for building structures that are only deleted whole. Thus, only the latest allocated block can be freed or resized. This means that after a block, say a is allocated, all previously allocated blocks are frozen and only a can ever be freed or resized.
  • Vmpool: A strategy for allocating blocks of the same size.
  • Vmdebug: A general purpose allocator with stringent checking and locking. It is useful for detecting memory overwrites, resizing or freeing of unallocated blocks, etc.
  • Vmprofile: A general purpose allocator that records and prints a summary of memory usage on program exit. This can be used to tune memory usage and to detect memory leakages.

Vmalloc provides a malloc interface for backward compatibility. This implementation of malloc is instrumented with the Vmalloc methods so that an application can select a particular allocation policy at program start-up time via environment variables. For example, to debug memory errors, an application can set the environment variable VMDEBUG=1 before invocation to use the method Vmdebug instead of the default method Vmbest. Then, as memories are allocated and freed, allocation errors and memory corruptions will be reported. In this way, normal execution retains good performance but debugging is still possible when needed without recompilation or relinking.

The current distribution is Vmalloc2002. This version of library is portable to all C and C++ flavors. A number of new functions have been added including one to open a region based on memory mapping. Such regions are automatically backed up to secondary storage for data persistence. An example to build persistent containers based on the container data type library Cdt is given in the distribution.

Below are papers related to Vmalloc


Software Installation Notes

The package should be unpacked in a root installation directory, say ``Software'', to create the below directory tree:
    Software / NOTICE
               README
               include / [headers (ast_common.h, vmalloc.h)]
               lib     / [libraries (libvmalloc.a)]
               bin     / [commands (iffe)]
               man     / man1 / [command manual pages (iffe.1)]
                       / man3 / [library manual pages (vmalloc.3)]
               src     / lib  / vmalloc / [vmalloc source code]
                                          NOTICE
                                          README
                                          features   / [feature probes]
                                          Vmalloc_t  / [regression tests for Vmalloc]
                                          Vmalloc_ex / [example program(s)]
The README file tells how to build Vmalloc.

Comments/Questions/Problems

Contact Phong Vo at: kpv@research.att.com.

Except for configuration problems in building the package, a bug report should be in the form of a small program that I can compile and run. Without such a program, I will likely ignore the report since it often takes too much time for me to tell if a reported bug is real or if it's just a misuse of the code.