Git Product home page Git Product logo

ssmem's Introduction

ssmem

ssmem is a fast and simple object-based memory allocator with epoch-based garbage collection. In other words, the freed memory is not reused by the allocator until it is certain that no other threads might be accessing that memory. ssmem can for example be used in lock-free data structures, where the removal of an element from the structure might happen while other threads are holding a reference to the same element.

You can create multiple allocators with ssmem, however, each allocator can handle a single object size. For example, you can create an ssmem allocator to always allocate and release 64 bytes memory chunks.

  • Website : http://lpd.epfl.ch/site/ascylib
  • Author : Vasileios Trigonakis [email protected]
  • Related Publications: ssmem was developed for: Asynchronized Concurrency: The Secret to Scaling Concurrent Search Data Structures, Tudor David, Rachid Guerraoui, Vasileios Trigonakis (alphabetical order), ASPLOS '15

Installation

Execute make in the ssmem base folder. This should compile libssmem.a and ssmem_test.

ssmem_test contains a few tests for verifying the correctness and testing the performance of ssmem.

Execute: ssmem_test -h for the available options.

If you want to customize the installation of ssmem, you can add a custom configuration for a platform in the Makefile.

You can also compile with make VERSION=DEBUG to generate a debug build of ssmem.

Using ssmem

To use ssmem you need to include ssmem.h and link with -lssmem. ssmem.h contains the interface of ssmem.

In short, you can:

  • ssmem_alloc_init, or ssmem_alloc_init_fs_size to initialize and allocator
  • ssmem_term to terminate ssmem
  • ssmem_alloc to allocate memory
  • ssmem_free to free memory (when it is safe, within the allocator)
  • ssmem_release to free memory (when it is safe, to the system -- with free)

Refer to ssmem.h for more details and operations.

Memory reclaimation

Each thread holds a version/timestamp number. By default, this timestamp is incremented every time the thread takes some steps with ssmem (i.e., either allocates, or frees memory). ssmem batches multiple frees together (in a free set) and once the set is full, it tries to garbage collect memory. The free set is timestamped with a vector clock (an array of the timestamps from all threads). The garbage collection (reclamation of the freed memory) decides if a free set is safe to release (i.e., whether all threads had made progress since it was timestamped) and if it is, it makes the memory of this (and of "older") free sets available to the allocator.

Nevertheless, in certain cases, allocating and/or freeing memory might not be the correct place to increase the local timestamp. In a sense, incrementing the timestamp is some sort of barrier: by incrementing the timestamp the thread indicates that it does not hold any earlier references to ssmem-allocated memory. Accordingly, if the software allocating and/or freeing memory is not the correct "barrier" place for an application, ssmem includes a flag (in ssmem.h) to control when the timestamp is incremented.

In brief, the flag SSMEM_TS_INCR_ON can takes the following values (if the value is changed, recompilation is required):

  • SSMEM_TS_INCR_ON_NONE: the timestamp is never automatically incremented. Applications should manually include SSMEM_SAFE_TO_RECLAIM() calls at points when it is safe (for other threads) to reclaim memory,
  • SSMEM_TS_INCR_ON_BOTH: the timestamp is incremented both upon allocating and freeing memory,
  • SSMEM_TS_INCR_ON_ALLOC: the timestamp is incremented only upon allocating memory,
  • SSMEM_TS_INCR_ON_FREE: the timestamp is incremented only upon freeing memory.

ssmem's People

Contributors

trigonak avatar

Watchers

Kai Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.