mem: add basic slab allocator
This commit is contained in:
parent
4239ca1b7e
commit
74a58d6641
5 changed files with 117 additions and 0 deletions
20
include/kernel/slab.h
Normal file
20
include/kernel/slab.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef _SLAB_H_
|
||||
#define _SLAB_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/mem.h>
|
||||
|
||||
struct slab {
|
||||
size_t size; /* size of each object */
|
||||
size_t num; /* number of objects in this slab */
|
||||
size_t free; /* number of free objects */
|
||||
uintptr_t *nextfree;
|
||||
struct slab *next;
|
||||
};
|
||||
|
||||
struct slab *slab_create(size_t size);
|
||||
void *slab_alloc(struct slab *slab);
|
||||
void slab_free(struct slab *slab, void *ptr);
|
||||
|
||||
#endif /* _SLAB_H_ */
|
||||
Loading…
Reference in a new issue