Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Memory Management

thinkingfish edited this page Nov 28, 2012 · 1 revision

Overview

Twemcache manages the memory for storing key-value pairs directly. The most important concepts include slab, item, slab profile and slab class. The memory subsystem allocates memory in fixed sized chunks, called slabs. By default, a slab is 1 MiB in size, although it can be configured to be larger or smaller. In most cases, a slab is much bigger than what is needed to store a key-value pair, so it is evenly divided into smaller units, called items, to store a key-value pair in each item. Both slabs and items need some memory for bookkeeping. To cater to variable data sizes, different slabs can be sliced up in different ways. Twemcache uses a data structure called a slab profile to determine this. Slab profile provides a list of item sizes, in ascending order, that a slab can be slice into, and slabs that have the same item size belong to the same slab class. When a new slab is allocated to fulfill the latest key-value storage request, it is assigned the lowest slab class necessary to satisfy the request. Slab allocation reduces external fragmentation, and the slab profile keeps internal fragmentation under control.

Notes

The following header files provides more details on memory management at the item and slab level: src/mc_items.h, src/mc_slabs.h

Clone this wiki locally