Table of Content

Name

lua-sharedtable:

lua-sharetable is a key value store table and can shared between processes.

Features:

  • Table is associative array, that can be indexed not only with number but also with string.

  • Table value can not only be integer, string, float, but also table reference.

  • No fixed size, you can add as many elements as you want to a table dynamically. memory space is dynamic extended.

  • Low memory fragment, in bottom layer, memory space split into region, pages, slab chunk. it can choose the best fit size to allocate.

  • High memory allocation performance

    • memory space is occupied in init phase, but not bind physical page, so no memory use. when table use space, it just trigger page fault to bind virtual memory with physical page, so no system call to delay.

    • there are some kind of chunks in slab pool, and some kind of pages in page pool, so alloc memory to user, just to search in array or tree data structure.

  • No redundant memory occupied, when free memory reach threshold, the memory will release to system through unbind virtual memory from physical page.

  • No afraid process died, if process died, it's share memory will be release. even the died process hold the lock, the lock will be recovered.

Status

This library is in development phase.

It has been used in our object storage service.

Description

Module List

There is a README.md for each module.

name description
array dynamic and static array
atomic atomic operation
btree btree operation
binary binary operation
bitmap bitmap operation
list double linked list operation
rbtree red–black tree operation
robustlock robustlock can avoid dead lock
str string utility
region manage system alloced big memory
pagepool manage pages which split from region

Install

It requires gcc 4.9+ and c11 standard.

For now the latest centos still has no gcc-4.9 included. We need to install gcc-4.9 with devtoolset-3.

To install gcc 4.9 on centos:

yum install centos-release-scl-rh -y
yum install devtoolset-3-gcc -y

To use gcc-4.9 in devtoolset-3, start a new bash with devtoolset-3 enabled:

scl enable devtoolset-3 bash

To enable devtoolset-3 for ever, add the following line into .bashrc:

source /opt/rh/devtoolset-3/enable

Usage

Configuration

Contribute

Preprocessor

  • st_assert(expr, fmt...): is used to detect unsolvable problems, Such as operating on a NULL pointer.

    If expr is evaluated to 0, it kills the entire process by sending a signal. A failure assert means there is severe problem happening, nothing else should be done.

    In our project we assume arguments passed in are always valid. Otherwise, there must be a programming mistake.

    Invalid input should be filtered out in upper layer.

  • st_dassert(expr, fmt...): is the same as st_assert, except without debug enabled, it will be stripped.

  • st_must(expr, optional_return_value): is used to check non-critical invalid input, such as:

    • freeing a NULL pointer(this is can be just ignored and return),

Code style

  • Use astyle to format .c and .h source code.

    There is an astylerc that defines code style for this project.

    Usage:

    1. Using env variable to specify config file:

      export ARTISTIC_STYLE_OPTIONS=$PWD/util/astylerc
      astyle src/str/str.c
      
    2. Or copy it to home folder then astyle always use it.

      copy util/astylerc ~/.astylerc
      astyle src/str/str.c
      

Test

Author