34#ifndef _LOS_SLAB_PRI_H
35#define _LOS_SLAB_PRI_H
44#ifdef LOSCFG_KERNEL_MEM_SLAB_EXTENTION
47#define SLAB_MEM_COUNT 4
50#define SLAB_MEM_CLASS_STEP_SIZE 0x10U
53#define SLAB_MEM_MAX_SIZE (SLAB_MEM_CLASS_STEP_SIZE << (SLAB_MEM_COUNT - 1))
55typedef struct tagLosSlabStatus {
63typedef struct tagOsSlabBlockNode {
74typedef struct tagOsSlabAllocator {
77 struct AtomicBitset *bitset;
80#ifdef LOSCFG_KERNEL_MEM_SLAB_AUTO_EXPANSION_MODE
81typedef struct tagOsSlabMemAllocator {
82 struct tagOsSlabMemAllocator *next;
83 OsSlabAllocator *slabAlloc;
87typedef struct tagOsSlabMem {
91#ifdef LOSCFG_KERNEL_MEM_SLAB_AUTO_EXPANSION_MODE
93 OsSlabMemAllocator *bucket;
95 OsSlabAllocator *alloc;
99struct LosSlabControlHeader {
101#ifdef LOSCFG_KERNEL_MEM_SLAB_AUTO_EXPANSION_MODE
102 OsSlabAllocator *allocatorBucket;
104 OsSlabMem slabClass[SLAB_MEM_COUNT];
107#ifdef LOSCFG_KERNEL_MEM_SLAB_AUTO_EXPANSION_MODE
108#define SLAB_MEM_DEFAULT_BUCKET_CNT 1
111#define OS_SLAB_MAGIC 0xdede
112#define OS_SLAB_BLOCK_HEAD_GET(ptr) ((OsSlabBlockNode *)(VOID *)((UINT8 *)(ptr) - \
113 sizeof(OsSlabBlockNode)))
114#define OS_SLAB_BLOCK_MAGIC_SET(slabNode) (((OsSlabBlockNode *)(slabNode))->magic = (UINT16)OS_SLAB_MAGIC)
115#define OS_SLAB_BLOCK_MAGIC_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->magic)
116#define OS_SLAB_BLOCK_SIZE_SET(slabNode, size) (((OsSlabBlockNode *)(slabNode))->blkSz = (UINT8)(size))
117#define OS_SLAB_BLOCK_SIZE_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->blkSz)
118#define OS_SLAB_BLOCK_ID_SET(slabNode, id) (((OsSlabBlockNode *)(slabNode))->recordId = (id))
119#define OS_SLAB_BLOCK_ID_GET(slabNode) (((OsSlabBlockNode *)(slabNode))->recordId)
120#define OS_ALLOC_FROM_SLAB_CHECK(slabNode) (((OsSlabBlockNode *)(slabNode))->magic == (UINT16)OS_SLAB_MAGIC)
121#define OS_SLAB_LOG2(value) ((UINT32)(32 - CLZ(value) - 1))
122#define OS_SLAB_CLASS_LEVEL_GET(size) \
123 (OS_SLAB_LOG2((size - 1) >> (OS_SLAB_LOG2(SLAB_MEM_CLASS_STEP_SIZE - 1))))
126extern VOID OsSlabAllocatorDestroy(
VOID *pool, OsSlabAllocator *allocator);
127extern VOID *OsSlabAllocatorAlloc(OsSlabAllocator *allocator);
128extern BOOL OsSlabAllocatorFree(OsSlabAllocator *allocator,
VOID* ptr);
129extern BOOL OsSlabAllocatorEmpty(
const OsSlabAllocator *allocator);
130extern VOID OsSlabAllocatorGetSlabInfo(
const OsSlabAllocator *allocator,
UINT32 *itemSize,
132extern BOOL OsSlabAllocatorCheck(
const OsSlabAllocator *allocator,
const VOID *ptr);
134extern VOID OsSlabMemDeinit(
VOID *pool);
138extern UINT32 OsSlabStatisticsGet(
const VOID *pool, LosSlabStatus *status);
139extern UINT32 OsSlabGetMaxFreeBlkSize(
const VOID *pool);
140extern VOID *OsSlabCtrlHdrGet(
const VOID *pool);
141extern VOID *OsSlabAllocatorGetIdxP(
const OsSlabAllocator *allocator,
UINT32 idx);
145 struct LosSlabControlHeader *header = (
struct LosSlabControlHeader *)OsSlabCtrlHdrGet(pool);
148 OsSlabMemInit(pool, size);
152 header->enabled = slabEnable;
#define NULL
Definition common_def.h:21
#define STATIC
Definition common_def.h:57
#define INLINE
Definition common_def.h:65
STATIC INLINE VOID OsSlabMemProcInitFlag(VOID *pool, UINT32 size, BOOL slabEnable)
Definition los_slab_pri.h:157
STATIC INLINE UINT32 OsSlabMemCheck(const VOID *pool, const VOID *ptr)
Definition los_slab_pri.h:178
STATIC INLINE BOOL OsSlabMemFree(VOID *pool, VOID *ptr)
Definition los_slab_pri.h:171
STATIC INLINE VOID * OsSlabMemAlloc(VOID *pool, UINT32 size)
Definition los_slab_pri.h:164
unsigned short UINT16
Definition los_typedef.h:51
#define VOID
Definition los_typedef.h:88
#define FALSE
Definition los_typedef.h:94
unsigned char UINT8
Definition los_typedef.h:50
unsigned int UINT32
Definition los_typedef.h:52
size_t BOOL
Definition los_typedef.h:83