Skip to content

Commit 4909b87

Browse files
wdfk-progRbb666
authored andcommitted
[mem] Remove useless code And Update mem documentation
1 parent a4a4949 commit 4909b87

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed
51.5 KB
Loading

documentation/memory/memory.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ Any or none of these memory heap management algorithms can be chosen when the sy
4343
4444
### Small Memory Management Algorithm
4545

46-
The small memory management algorithm is a simple memory allocation algorithm. Initially, it is a large piece of memory. When a memory block needs to be allocated, the matching memory block is segmented from the large memory block, and then this matching free memory block is returned to the heap management system. Each memory block contains data head for management use through which the used block and the free block are linked by a doubly linked list, as shown in the following figure:
46+
The small memory management algorithm is a simple memory allocation algorithm. Initially, it is a large piece of memory. When a memory block needs to be allocated, the matching memory block is segmented from the large memory block, and then this matching free memory block is returned to the heap management system. Each memory block contains data head for management use through which the used block and the free block are linked by a doubly linked list.
47+
48+
49+
50+
**Use this implementation before 4.1.0**
51+
52+
As shown in the following figure:
4753

4854
![Small Memory Management Working Mechanism Diagram](figures/08smem_work.png)
4955

@@ -55,6 +61,22 @@ Each memory block (whether it is an allocated memory block or a free memory bloc
5561

5662
The performance of memory management is mainly reflected in the allocation and release of memory. The small memory management algorithm can be embodied by the following examples.
5763

64+
65+
66+
**4.1.0 and later use this implementation**
67+
68+
As shown in the following figure:
69+
70+
![](figures/08smem_work4.png)
71+
72+
**Heap Start**: The heap head address stores memory usage information, the heap head address pointer, the heap end address pointer, the minimum heap free address pointer, and the memory size.
73+
74+
Each memory block (whether it is an allocated memory block or a free memory block) contains a data head, including:
75+
76+
**pool_ptr**: Small memory object address. If the last bit of the memory block is 1, it is used. If the last bit of the memory block is 0, it is not used. When used, the structure members of the small memory algorithm can be quickly obtained by calc.
77+
78+
79+
5880
As shown in the following figure, the free list pointer lfree initially points to a 32-byte block of memory. When the user thread wants to allocate a 64-byte memory block, since the memory block pointed to by this lfree pointer is only 32 bytes and does not meet the requirements, the memory manager will continue to search for the next memory block. When the next memory block with 128 bytes is found, it meets the requirements of the allocation. Because this memory block is large, the allocator will split the memory block, and the remaining memory block (52 bytes) will remain in the lfree linked list, as shown in the following table which is after 64 bytes is allocated.
5981

6082
![Small Memory Management Algorithm Linked List Structure Diagram 1](figures/08smem_work2.png)

examples/utest/testcases/kernel/mem_tc.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
struct rt_small_mem_item
1616
{
1717
rt_ubase_t pool_ptr; /**< small memory object addr */
18-
#ifdef ARCH_CPU_64BIT
19-
rt_uint32_t resv;
20-
#endif /* ARCH_CPU_64BIT */
2118
rt_size_t next; /**< next free item */
2219
rt_size_t prev; /**< prev free item */
2320
#ifdef RT_USING_MEMTRACE

src/mem.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@
5959
struct rt_small_mem_item
6060
{
6161
rt_ubase_t pool_ptr; /**< small memory object addr */
62-
#ifdef ARCH_CPU_64BIT
63-
rt_uint32_t resv;
64-
#endif /* ARCH_CPU_64BIT */
6562
rt_size_t next; /**< next free item */
6663
rt_size_t prev; /**< prev free item */
6764
#ifdef RT_USING_MEMTRACE
@@ -85,8 +82,6 @@ struct rt_small_mem
8582
rt_size_t mem_size_aligned; /**< aligned memory size */
8683
};
8784

88-
#define HEAP_MAGIC 0x1ea0
89-
9085
#define MIN_SIZE (sizeof(rt_ubase_t) + sizeof(rt_size_t) + sizeof(rt_size_t))
9186

9287
#define MEM_MASK ((~(rt_size_t)0) - 1)

0 commit comments

Comments
 (0)