This commit is contained in:
Mike. 2025-01-12 01:29:17 +08:00 committed by GitHub
commit 5b50ea7d34
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 3 deletions

View file

@ -69,6 +69,14 @@ config MM_DEFAULT_ALIGNMENT
memory default alignment is equal to sizoef(uintptr), if this value memory default alignment is equal to sizoef(uintptr), if this value
is not 0, this value must be 2^n and at least sizeof(uintptr). is not 0, this value must be 2^n and at least sizeof(uintptr).
config MM_NODE_PENDING
bool "Enable pending memory node"
default n
---help---
Pending memory block node precding and the entire struct,
After turning on this bit, the size of each memory block
will be aligned to MM_ALIGN
config MM_SMALL config MM_SMALL
bool "Small memory model" bool "Small memory model"
default n default n

View file

@ -143,7 +143,17 @@
* previous freenode * previous freenode
*/ */
#define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t)) #ifdef CONFIG_MM_NODE_PENDING
# define MM_NODE_STRUCT_PENDING aligned_data(MM_ALIGN)
#else
# define MM_NODE_STRUCT_PENDING
#endif
#ifdef CONFIG_MM_NODE_PENDING
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - MM_ALIGN)
#else
# define MM_ALLOCNODE_OVERHEAD (MM_SIZEOF_ALLOCNODE - sizeof(mmsize_t))
#endif
/* Get the node size */ /* Get the node size */
@ -173,7 +183,16 @@ typedef size_t mmsize_t;
struct mm_allocnode_s struct mm_allocnode_s
{ {
#ifdef CONFIG_MM_NODE_PENDING
union
{
mmsize_t preceding; /* Physical preceding chunk size */
uint8_t align[MM_ALIGN];
};
#else
mmsize_t preceding; /* Physical preceding chunk size */ mmsize_t preceding; /* Physical preceding chunk size */
#endif
mmsize_t size; /* Size of this chunk */ mmsize_t size; /* Size of this chunk */
#if CONFIG_MM_BACKTRACE >= 0 #if CONFIG_MM_BACKTRACE >= 0
pid_t pid; /* The pid for caller */ pid_t pid; /* The pid for caller */
@ -182,13 +201,22 @@ struct mm_allocnode_s
FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */ FAR void *backtrace[CONFIG_MM_BACKTRACE]; /* The backtrace buffer for caller */
# endif # endif
#endif #endif
}; }MM_NODE_STRUCT_PENDING;
/* This describes a free chunk */ /* This describes a free chunk */
struct mm_freenode_s struct mm_freenode_s
{ {
#ifdef CONFIG_MM_NODE_PENDING
union
{
mmsize_t preceding; /* Physical preceding chunk size */
uint8_t align[MM_ALIGN];
};
#else
mmsize_t preceding; /* Physical preceding chunk size */ mmsize_t preceding; /* Physical preceding chunk size */
#endif
mmsize_t size; /* Size of this chunk */ mmsize_t size; /* Size of this chunk */
#if CONFIG_MM_BACKTRACE >= 0 #if CONFIG_MM_BACKTRACE >= 0
pid_t pid; /* The pid for caller */ pid_t pid; /* The pid for caller */
@ -199,7 +227,7 @@ struct mm_freenode_s
#endif #endif
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */ FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
FAR struct mm_freenode_s *blink; FAR struct mm_freenode_s *blink;
}; }MM_NODE_STRUCT_PENDING;
static_assert(MM_SIZEOF_ALLOCNODE <= MM_MIN_CHUNK, static_assert(MM_SIZEOF_ALLOCNODE <= MM_MIN_CHUNK,
"Error size for struct mm_allocnode_s\n"); "Error size for struct mm_allocnode_s\n");