Code Monkey home page Code Monkey logo

slab-allocator's Introduction

Slab Allocator

This work is a basic implementation of The Slab Allocator: An Object-Caching Kernel Memory Allocator by Jeff Bonwick.

📋  What is a slab allocator ?

The main idea of this mechanism is that objects of the same size are stored in the corresponding slab, from here the locator takes free objects and after freeing the objects are returned to the slab from where they were obtained. There can be several slabs in memory, both for objects of the same size, and for objects of different sizes, the number of sizes is limited due to the introduction of regularity of sizes.

To get an object from slab, it is enough to check whether the corresponding object cache is not empty. If the object cache is not empty, then the object is taken from the cache, if its slab has become full (all slab objects are busy), then the slab is taken from cache. When an object is released, it is returned as free to its slab. If the slab was full to this, then it is added to its cache. If slab becomes empty (all slab objects are free), the extent slab returns to its arena. If the object cache is empty, then the allocator gets a free extent of the appropriate size and creates a slab from it and adds this slab to its cache. These actions can be implemented in constant time.

Each slab must keep track of its objects and have pointers to link the slab in its cache. This accounting is kept in the slab's header. Objects are divided into small and big. Small objects are objects whose size is smaller or comparable to the size of the slab header, objects of other sizes are called big. The slab header with small objects is stored in the slab itself. The slab header with big objects is stored in another slab object. Non-slab extent headers are stored in slab objects. If the allocator needs some memory, the allocator can request this memory from itself.

🚀  How to Run

  1. Clone this repository;

  2. Enter these commands in the console:

    >> make
    >> make test

📷  Results

The program was tested on big and small slabs. In general, I tested the basis case of

struct kmem_cache *
kmem_cache_create(char *name, size_t size, size_t align);

void *
kmem_cache_alloc(struct kmem_cache *cp, int flags);

void
kmem_cache_free(struct kmem_cache *cp, void *buf);

void
kmem_cache_destroy(struct kmem_cache *cp);

Sample Output

Sample Output

Sample Output

Sample Output

Sample Output

Sample Output

Sample Output

Sample Output

📫  Get in touch

slab-allocator's People

Contributors

jackshendrikov avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

pengzeshan

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.