Initial commit, with incomplete header file

This commit is contained in:
Yaloalo 2025-07-03 16:10:27 +02:00
parent 938f15d0ee
commit 9bc1cf03aa
29 changed files with 50 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

50
include/slab.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef KARLOS_SLAB_H
#define KARLOS_SLAB_H
#include <stdint.h>
#include <stddef.h>
#include <paging.h>
/* Forward declaration of per-page descriptor */
typedef struct slab_page slab_page_t;
/*------------------------------------------------------------------------*/
/* Per-cache descriptor: one cache per object size */
/*------------------------------------------------------------------------*/
typedef struct slab_cache {
size_t obj_size; // bytes per object
size_t slots_per_slab; // = PAGE_SIZE / obj_size
slab_page_t *empty_slabs; // slabs with all slots free
slab_page_t *partial_slabs; // slabs with some free slots
slab_page_t *full_slabs; // slabs with no free slots
void (*constructor)(void *obj, size_t size);
void (*destructor)(void *obj, size_t size);
} slab_cache_t;
/*------------------------------------------------------------------------*/
/* Per-slab descriptor: one page carved into fixed-size slots */
/*------------------------------------------------------------------------*/
typedef struct slab_page {
void **free_stack; // stack of free slots in this page
size_t free_index; // current head of stack (also free_count)
size_t free_count; // how many slots are free right now
void *page_base; // base address of the slab's page
struct slab_page *next; // link to next slab_page in cache list
} slab_page_t;
/*------------------------------------------------------------------------*/
/* API: implemented in KARLOS_SLAB.c */
/*------------------------------------------------------------------------*/
slab_cache_t *slab_cache_create(
size_t obj_size,
size_t align,
void (*constructor)(void*, size_t),
void (*destructor)(void*, size_t)
);
void *slab_alloc(slab_cache_t *cache);
void slab_free(slab_cache_t *cache, void *obj);
void slab_destroy(slab_cache_t *cache);
#endif /* KARLOS_SLAB_H */

0
src/slab.c Normal file
View file