mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 01:38:36 +08:00
Compare commits
3 commits
be6c9015cc
...
5b50ea7d34
Author | SHA1 | Date | |
---|---|---|---|
|
5b50ea7d34 | ||
|
aa0aecbd80 | ||
|
0f70c44b4a |
3 changed files with 44 additions and 7 deletions
|
@ -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
|
||||||
|
|
|
@ -397,16 +397,17 @@ retry:
|
||||||
|
|
||||||
pool->nalloc++;
|
pool->nalloc++;
|
||||||
spin_unlock_irqrestore(&pool->lock, flags);
|
spin_unlock_irqrestore(&pool->lock, flags);
|
||||||
blk = kasan_unpoison(blk, pool->blocksize);
|
|
||||||
#ifdef CONFIG_MM_FILL_ALLOCATIONS
|
|
||||||
memset(blk, MM_ALLOC_MAGIC, pool->blocksize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
mempool_add_backtrace(pool, (FAR struct mempool_backtrace_s *)
|
mempool_add_backtrace(pool, (FAR struct mempool_backtrace_s *)
|
||||||
((FAR char *)blk + pool->blocksize));
|
((FAR char *)blk + pool->blocksize));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
blk = kasan_unpoison(blk, pool->blocksize);
|
||||||
|
#ifdef CONFIG_MM_FILL_ALLOCATIONS
|
||||||
|
memset(blk, MM_ALLOC_MAGIC, pool->blocksize);
|
||||||
|
#endif
|
||||||
|
|
||||||
return blk;
|
return blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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");
|
||||||
|
|
Loading…
Reference in a new issue