Revision 5cc1e1f8 lib/slab.c

View differences:

lib/slab.c
8 8
 *	Can be freely distributed and used under the terms of the GNU GPL.
9 9
 */
10 10

  
11
/**
12
 * DOC: Slabs
13
 *
14
 * Slabs are collections of memory blocks of a fixed size.
15
 * They support very fast allocation and freeing of such blocks, prevent memory
16
 * fragmentation and optimize L2 cache usage. Slabs have been invented by Jeff Bonwick
17
 * and published in USENIX proceedings as `The Slab Allocator: An Object-Caching Kernel
18
 * Memory Allocator'. Our implementation follows this article except that we don't use
19
 * constructors and destructors.
20
 *
21
 * When the |DEBUGGING| switch is turned on, we automatically fill all
22
 * newly allocated and freed blocks with a special patterns to make detection
23
 * of use of uninitialized or already freed memory easier.
24
 *
25
 * Example: Nodes of a FIB are allocated from a Slab.
26
 */
27

  
11 28
#include <stdlib.h>
12 29

  
13 30
#include "nest/bird.h"
......
139 156
  int x[0];
140 157
};
141 158

  
159
/**
160
 * sl_new - create a new Slab
161
 * @p: resource pool
162
 * @size: block size
163
 *
164
 * This function creates a new Slab resource from which
165
 * objects of size @size can be allocated.
166
 */
142 167
slab *
143 168
sl_new(pool *p, unsigned size)
144 169
{
......
183 208
  return h;
184 209
}
185 210

  
211
/**
212
 * sl_alloc - allocate an object from Slab
213
 * @s: slab
214
 *
215
 * sl_alloc() allocates space for a single object from the
216
 * Slab and returns a pointer to the object.
217
 */
186 218
void *
187 219
sl_alloc(slab *s)
188 220
{
......
223 255
  goto okay;
224 256
}
225 257

  
258
/**
259
 * sl_free - return a free object back to a Slab
260
 * @s: slab
261
 * @oo: object returned by sl_alloc()
262
 *
263
 * This function frees memory associated with the object @oo
264
 * and returns it back to the Slab @s.
265
 */
226 266
void
227 267
sl_free(slab *s, void *oo)
228 268
{

Also available in: Unified diff