diff --git a/kernel/include/los_memory.h b/kernel/include/los_memory.h index bfe0f023..f47d047f 100644 --- a/kernel/include/los_memory.h +++ b/kernel/include/los_memory.h @@ -490,6 +490,72 @@ extern UINT32 LOS_MemIntegrityCheck(const VOID *pool); * * @see None. */ + +/* Supposing a Second Level Index: SLI = 3. */ +#define OS_MEM_SLI 3 +/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */ +#define OS_MEM_SMALL_BUCKET_COUNT 31 +#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128 +/* Giving 2^OS_MEM_SLI free lists for each large bucket. */ +#define OS_MEM_LARGE_BUCKET_COUNT 24 +/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */ +#define OS_MEM_LARGE_START_BUCKET 7 + +/* The count of free list. */ +#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI)) +/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */ +#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1) + +struct OsMemNodeHead { +#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1) + UINT32 magic; +#endif +#if (LOSCFG_MEM_LEAKCHECK == 1) + UINTPTR linkReg[LOSCFG_MEM_RECORD_LR_CNT]; +#endif + union { + struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */ + struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */ + } ptr; +#if (LOSCFG_TASK_MEM_USED == 1) + UINT32 taskID; + UINT32 sizeAndFlag; +#elif (LOSCFG_MEM_FREE_BY_TASKID == 1) + UINT32 taskID : 6; + UINT32 sizeAndFlag : 26; +#else + UINT32 sizeAndFlag; +#endif +}; + +struct OsMemFreeNodeHead { + struct OsMemNodeHead header; + struct OsMemFreeNodeHead *prev; + struct OsMemFreeNodeHead *next; +}; + +struct OsMemPoolInfo { + VOID *pool; + UINT32 totalSize; + UINT32 attr; +#if (LOSCFG_MEM_WATERLINE == 1) + UINT32 waterLine; /* Maximum usage size in a memory pool */ + UINT32 curUsedSize; /* Current usage size in a memory pool */ +#endif +#if (LOSCFG_MEM_MUL_REGIONS == 1) + UINT32 totalGapSize; +#endif +}; + +struct OsMemPoolHead { + struct OsMemPoolInfo info; + UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS]; + struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT]; +#if (LOSCFG_MEM_MUL_POOL == 1) + VOID *nextPool; +#endif +}; + extern VOID LOS_MemUnlockEnable(VOID *pool); extern UINT32 OsMemSystemInit(VOID); diff --git a/kernel/src/mm/los_memory.c b/kernel/src/mm/los_memory.c index b153f8c2..56cf298c 100644 --- a/kernel/src/mm/los_memory.c +++ b/kernel/src/mm/los_memory.c @@ -59,21 +59,6 @@ VOID *g_poolHead = NULL; /* The following is the macro definition and interface implementation related to the TLSF. */ -/* Supposing a Second Level Index: SLI = 3. */ -#define OS_MEM_SLI 3 -/* Giving 1 free list for each small bucket: 4, 8, 12, up to 124. */ -#define OS_MEM_SMALL_BUCKET_COUNT 31 -#define OS_MEM_SMALL_BUCKET_MAX_SIZE 128 -/* Giving 2^OS_MEM_SLI free lists for each large bucket. */ -#define OS_MEM_LARGE_BUCKET_COUNT 24 -/* OS_MEM_SMALL_BUCKET_MAX_SIZE to the power of 2 is 7. */ -#define OS_MEM_LARGE_START_BUCKET 7 - -/* The count of free list. */ -#define OS_MEM_FREE_LIST_COUNT (OS_MEM_SMALL_BUCKET_COUNT + (OS_MEM_LARGE_BUCKET_COUNT << OS_MEM_SLI)) -/* The bitmap is used to indicate whether the free list is empty, 1: not empty, 0: empty. */ -#define OS_MEM_BITMAP_WORDS ((OS_MEM_FREE_LIST_COUNT >> 5) + 1) - #define OS_MEM_BITMAP_MASK 0x1FU /* Used to find the first bit of 1 in bitmap. */ @@ -120,60 +105,10 @@ STATIC INLINE UINT32 OsMemSlGet(UINT32 size, UINT32 fl) #error "When enter here, LOSCFG_BASE_CORE_TSK_LIMIT larger than 63 is not support" #endif -struct OsMemNodeHead { -#if (LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK == 1) - UINT32 magic; -#endif -#if (LOSCFG_MEM_LEAKCHECK == 1) - UINTPTR linkReg[LOSCFG_MEM_RECORD_LR_CNT]; -#endif - union { - struct OsMemNodeHead *prev; /* The prev is used for current node points to the previous node */ - struct OsMemNodeHead *next; /* The next is used for sentinel node points to the expand node */ - } ptr; -#if (LOSCFG_TASK_MEM_USED == 1) - UINT32 taskID; - UINT32 sizeAndFlag; -#elif (LOSCFG_MEM_FREE_BY_TASKID == 1) - UINT32 taskID : 6; - UINT32 sizeAndFlag : 26; -#else - UINT32 sizeAndFlag; -#endif -}; - struct OsMemUsedNodeHead { struct OsMemNodeHead header; }; -struct OsMemFreeNodeHead { - struct OsMemNodeHead header; - struct OsMemFreeNodeHead *prev; - struct OsMemFreeNodeHead *next; -}; - -struct OsMemPoolInfo { - VOID *pool; - UINT32 totalSize; - UINT32 attr; -#if (LOSCFG_MEM_WATERLINE == 1) - UINT32 waterLine; /* Maximum usage size in a memory pool */ - UINT32 curUsedSize; /* Current usage size in a memory pool */ -#endif -#if (LOSCFG_MEM_MUL_REGIONS == 1) - UINT32 totalGapSize; -#endif -}; - -struct OsMemPoolHead { - struct OsMemPoolInfo info; - UINT32 freeListBitmap[OS_MEM_BITMAP_WORDS]; - struct OsMemFreeNodeHead *freeList[OS_MEM_FREE_LIST_COUNT]; -#if (LOSCFG_MEM_MUL_POOL == 1) - VOID *nextPool; -#endif -}; - /* The memory pool support expand. */ #define OS_MEM_POOL_EXPAND_ENABLE 0x01 /* The memory pool support no lock. */