This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new ea3e518f3e2 mm/mempool: include initial blocks in diagnostic traversal
ea3e518f3e2 is described below
commit ea3e518f3e206daa80569af04ce9502bbccf9d3c
Author: jingfei <[email protected]>
AuthorDate: Sun Nov 29 08:31:33 2026 +0800
mm/mempool: include initial blocks in diagnostic traversal
Static initial storage is not part of the expansion queue, so task
accounting and block dumps must visit it explicitly. A dynamically
allocated initial chunk is the first queue entry and can have a different
size from later expansion chunks. Use its actual size for that entry.
Keep allocation behavior and diagnostic APIs unchanged. Document the
storage regions covered by the existing diagnostic interfaces.
Signed-off-by: jingfei <[email protected]>
---
Documentation/os/memory/index.rst | 11 +++++++++++
mm/mempool/mempool.c | 28 +++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/Documentation/os/memory/index.rst
b/Documentation/os/memory/index.rst
index 716a2551c95..31cc037a8cd 100644
--- a/Documentation/os/memory/index.rst
+++ b/Documentation/os/memory/index.rst
@@ -128,6 +128,17 @@ Please follow these steps to hook all memory related
routines:
- Include ``xxx_malloc.h`` in your source code to hook one file
- Add ``-include xxx_malloc.h`` to ``CFLAGS`` to hook all source code
+Memory Pool Diagnostics
+-----------------------
+
+With ``CONFIG_MM_BACKTRACE >= 0``, ``mempool_info_task()`` can report
+per-task allocations and ``mempool_memdump()`` can list individual blocks.
+These diagnostics cover static initial storage, dynamically allocated
+initial storage, expansion chunks and interrupt-reserved storage. The
+initial and expansion chunks may have different sizes. Stack traces
+additionally require ``CONFIG_MM_BACKTRACE > 0`` and recording enabled
+for the pool.
+
Granule Allocator
-----------------
diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c
index fd0b643a61f..dc10bcb91e0 100644
--- a/mm/mempool/mempool.c
+++ b/mm/mempool/mempool.c
@@ -154,6 +154,7 @@ static void mempool_foreach(FAR struct mempool_s *pool,
FAR const void *input, FAR void *output)
{
size_t blocksize = MEMPOOL_REALBLOCKSIZE(pool->blocksize);
+ size_t chunksize = pool->expandsize;
FAR struct mempool_backtrace_s *buf;
FAR sq_entry_t *entry;
FAR char *base ;
@@ -171,9 +172,32 @@ static void mempool_foreach(FAR struct mempool_s *pool,
}
}
+ if (pool->initialsize >= blocksize + MEMPOOL_HEADER_SIZE)
+ {
+ if (pool->initialbase != NULL)
+ {
+ /* Static storage is not linked into the expansion queue. */
+
+ nblks = (pool->initialsize - MEMPOOL_HEADER_SIZE) / blocksize;
+ base = pool->initialbase;
+ while (nblks--)
+ {
+ buf = (FAR struct mempool_backtrace_s *)
+ (base + nblks * blocksize + pool->blocksize);
+ callback(pool, buf, input, output);
+ }
+ }
+ else
+ {
+ /* The first queued chunk can differ from subsequent expansions. */
+
+ chunksize = pool->initialsize;
+ }
+ }
+
sq_for_every(&pool->equeue, entry)
{
- nblks = (pool->expandsize - MEMPOOL_HEADER_SIZE) / blocksize;
+ nblks = (chunksize - MEMPOOL_HEADER_SIZE) / blocksize;
base = (FAR char *)entry - (nblks * blocksize);
while (nblks--)
@@ -182,6 +206,8 @@ static void mempool_foreach(FAR struct mempool_s *pool,
(base + nblks * blocksize + pool->blocksize);
callback(pool, buf, input, output);
}
+
+ chunksize = pool->expandsize;
}
}