This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 84333881d70691ad82fc829b61d612225b25b167
Author: yinshengkai <yinsheng...@xiaomi.com>
AuthorDate: Sun Jun 30 16:10:22 2024 +0800

    mm: add mm_largest api to get the current largest available memory block
    
    Signed-off-by: yinshengkai <yinsheng...@xiaomi.com>
---
 arch/sim/src/sim/sim_heap.c | 14 ++++++++++++++
 include/nuttx/mm/mm.h       |  1 +
 mm/mm_heap/mm_mallinfo.c    | 24 ++++++++++++++++++++++++
 mm/tlsf/mm_tlsf.c           | 13 +++++++++++++
 4 files changed, 52 insertions(+)

diff --git a/arch/sim/src/sim/sim_heap.c b/arch/sim/src/sim/sim_heap.c
index 8257af7a6d..aa4b945d6e 100644
--- a/arch/sim/src/sim/sim_heap.c
+++ b/arch/sim/src/sim/sim_heap.c
@@ -623,6 +623,20 @@ size_t mm_heapfree(struct mm_heap_s *heap)
 {
   return SIZE_MAX;
 }
+
+/****************************************************************************
+ * Name: mm_heapfree_largest
+ *
+ * Description:
+ *   Return the largest chunk of contiguous memory in the heap
+ *
+ ****************************************************************************/
+
+size_t mm_heapfree_largest(FAR struct mm_heap_s *heap)
+{
+  return SIZE_MAX;
+}
+
 #else /* CONFIG_MM_CUSTOMIZE_MANAGER */
 
 void up_allocate_heap(void **heap_start, size_t *heap_size)
diff --git a/include/nuttx/mm/mm.h b/include/nuttx/mm/mm.h
index e5d27d63d0..6a0bfbae78 100644
--- a/include/nuttx/mm/mm.h
+++ b/include/nuttx/mm/mm.h
@@ -390,6 +390,7 @@ struct mallinfo_task mm_mallinfo_task(FAR struct mm_heap_s 
*heap,
                                       FAR const struct malltask *task);
 
 size_t mm_heapfree(FAR struct mm_heap_s *heap);
+size_t mm_heapfree_largest(FAR struct mm_heap_s *heap);
 
 /* Functions contained in kmm_mallinfo.c ************************************/
 
diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c
index 90d643ace8..407b6fe6e8 100644
--- a/mm/mm_heap/mm_mallinfo.c
+++ b/mm/mm_heap/mm_mallinfo.c
@@ -200,3 +200,27 @@ size_t mm_heapfree(FAR struct mm_heap_s *heap)
 {
   return heap->mm_heapsize - heap->mm_curused;
 }
+
+/****************************************************************************
+ * Name: mm_heapfree_largest
+ *
+ * Description:
+ *   Return the largest chunk of contiguous memory in the heap
+ *
+ ****************************************************************************/
+
+size_t mm_heapfree_largest(FAR struct mm_heap_s *heap)
+{
+  FAR struct mm_freenode_s *node;
+  for (node = heap->mm_nodelist[MM_NNODES - 1].blink; node;
+       node = node->blink)
+    {
+      size_t nodesize = MM_SIZEOF_NODE(node);
+      if (nodesize != 0)
+        {
+          return nodesize;
+        }
+    }
+
+  return 0;
+}
diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c
index cbb212b688..543b2c0d6d 100644
--- a/mm/tlsf/mm_tlsf.c
+++ b/mm/tlsf/mm_tlsf.c
@@ -1476,3 +1476,16 @@ size_t mm_heapfree(FAR struct mm_heap_s *heap)
 {
   return heap->mm_heapsize - heap->mm_curused;
 }
+
+/****************************************************************************
+ * Name: mm_heapfree_largest
+ *
+ * Description:
+ *   Return the largest chunk of contiguous memory in the heap
+ *
+ ****************************************************************************/
+
+size_t mm_heapfree_largest(FAR struct mm_heap_s *heap)
+{
+  return SIZE_MAX;
+}

Reply via email to