Skip to content

Commit 84db21f

Browse files
committed
mm: Add pending configuration for mm node struct and precding
pending memory block node precding and the entire struct, after turning on this bit, the size of each memory block wil be aligned to MM_ALIGN Signed-off-by: wangmingrong1 <[email protected]>
1 parent 5f4a15b commit 84db21f

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

mm/Kconfig

+8
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ config MM_DEFAULT_ALIGNMENT
6969
memory default alignment is equal to sizoef(uintptr), if this value
7070
is not 0, this value must be 2^n and at least sizeof(uintptr).
7171

72+
config MM_NODE_PENDING
73+
bool "Enable pending memory node"
74+
default n
75+
---help---
76+
Pending memory block node precding and the entire struct,
77+
After turning on this bit, the size of each memory block
78+
will be aligned to MM_ALIGN
79+
7280
config MM_SMALL
7381
bool "Small memory model"
7482
default n

mm/mm_heap/mm.h

+33-7
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@
143143
* previous freenode
144144
*/
145145

146-
#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
146+
#ifdef CONFIG_MM_NODE_PENDING
147+
# define MM_NODE_PENDING aligned_data(MM_ALIGN)
148+
# define MMSIZE_T_LEN MM_ALIGN
149+
#else
150+
# define MM_NODE_PENDING
151+
# define MMSIZE_T_LEN sizeof(mmsize_t)
152+
#endif
153+
154+
#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - MMSIZE_T_LEN)
147155

148156
/* Get the node size */
149157

@@ -173,23 +181,41 @@ typedef size_t mmsize_t;
173181

174182
struct mm_allocnode_s
175183
{
176-
mmsize_t preceding; /* Physical preceding chunk size */
177-
mmsize_t size; /* Size of this chunk */
184+
union
185+
{
186+
mmsize_t preceding; /* Physical preceding chunk size */
187+
uint8_t preceding_align[MMSIZE_T_LEN];
188+
};
189+
union
190+
{
191+
mmsize_t size; /* Physical preceding chunk size */
192+
uint8_t size_align[MMSIZE_T_LEN];
193+
};
194+
178195
#if CONFIG_MM_BACKTRACE >= 0
179196
pid_t pid; /* The pid for caller */
180197
unsigned long seqno; /* The sequence of memory malloc */
181198
# if CONFIG_MM_BACKTRACE > 0
182199
FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */
183200
# endif
184201
#endif
185-
};
202+
}MM_NODE_PENDING;
186203

187204
/* This describes a free chunk */
188205

189206
struct mm_freenode_s
190207
{
191-
mmsize_t preceding; /* Physical preceding chunk size */
192-
mmsize_t size; /* Size of this chunk */
208+
union
209+
{
210+
mmsize_t preceding; /* Physical preceding chunk size */
211+
uint8_t preceding_align[MMSIZE_T_LEN];
212+
};
213+
union
214+
{
215+
mmsize_t size; /* Physical preceding chunk size */
216+
uint8_t size_align[MMSIZE_T_LEN];
217+
};
218+
193219
#if CONFIG_MM_BACKTRACE >= 0
194220
pid_t pid; /* The pid for caller */
195221
unsigned long seqno; /* The sequence of memory malloc */
@@ -199,7 +225,7 @@ struct mm_freenode_s
199225
#endif
200226
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
201227
FAR struct mm_freenode_s *blink;
202-
};
228+
}MM_NODE_PENDING;
203229

204230
static_assert(MM_SIZEOF_ALLOCNODE <= MM_MIN_CHUNK,
205231
"Error size for struct mm_allocnode_s\n");

mm/mm_heap/mm_realloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ FAR void *mm_realloc(FAR struct mm_heap_s *heap, FAR void *oldmem,
153153
heap->mm_curused += newsize - oldsize;
154154
mm_shrinkchunk(heap, oldnode, newsize);
155155
kasan_poison((FAR char *)oldnode + MM_SIZEOF_NODE(oldnode) +
156-
sizeof(mmsize_t), oldsize - MM_SIZEOF_NODE(oldnode));
156+
MMSIZE_T_LEN, oldsize - MM_SIZEOF_NODE(oldnode));
157157
}
158158

159159
/* Then return the original address */

0 commit comments

Comments
 (0)