You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/04/11 04:46:23 UTC

[incubator-nuttx] branch master updated (218cbb470a -> d4978bfba4)

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

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


    from 218cbb470a Fixed source code format errors.
     new 1a4ccd2d70 Revert "mm_heap: heapsize align with MM_MIN_CHUNK."
     new d4978bfba4 mm_initialize: malloc() return aligend pointer.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 mm/mm_heap/mm.h            |  4 ----
 mm/mm_heap/mm_initialize.c | 22 +++++++++++++---------
 mm/mm_heap/mm_mallinfo.c   |  5 +----
 3 files changed, 14 insertions(+), 17 deletions(-)


[incubator-nuttx] 02/02: mm_initialize: malloc() return aligend pointer.

Posted by xi...@apache.org.
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/incubator-nuttx.git

commit d4978bfba4c6ba93ef83fe4f40aa51ed3392f435
Author: wangbowen6 <wa...@xiaomi.com>
AuthorDate: Fri Apr 8 18:12:11 2022 +0800

    mm_initialize: malloc() return aligend pointer.
    
    malloc() should return aligned (with MM_MIN_CHUNK) pointer, but
    pr #5906 destroy that, this pr find a better method to solve
    these questions.
    
    Signed-off-by: YAMAMOTO Takashi <ya...@midokura.com>
    and
    Signed-off-by: wangbowen6 <wa...@xiaomi.com>
---
 mm/mm_heap/mm_initialize.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index e32c63cdac..df28679764 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -93,11 +93,15 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
 
   DEBUGVERIFY(mm_takesemaphore(heap));
 
-  /* Adjust the provided heap start and size so that they are both aligned
-   * with the MM_MIN_CHUNK size.
+  /* Adjust the provided heap start and size.
+   *
+   * Note: (uintptr_t)node + SIZEOF_MM_ALLOCNODE is what's actually
+   * returned to the malloc user, which should have natural alignment.
+   * (that is, in this implementation, MM_MIN_CHUNK-alignment.)
    */
 
-  heapbase = MM_ALIGN_UP((uintptr_t)heapstart);
+  heapbase = MM_ALIGN_UP((uintptr_t)heapstart + 2 * SIZEOF_MM_ALLOCNODE) -
+             2 * SIZEOF_MM_ALLOCNODE;
   heapend  = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize);
   heapsize = heapend - heapbase;
 


[incubator-nuttx] 01/02: Revert "mm_heap: heapsize align with MM_MIN_CHUNK."

Posted by xi...@apache.org.
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/incubator-nuttx.git

commit 1a4ccd2d70ff4aa675e85230d98e109713fdf222
Author: wangbowen6 <wa...@xiaomi.com>
AuthorDate: Fri Apr 8 17:35:36 2022 +0800

    Revert "mm_heap: heapsize align with MM_MIN_CHUNK."
    
    This reverts commit 69e69740b5f578e035befc762538b282d91ed1ba.
---
 mm/mm_heap/mm.h            |  4 ----
 mm/mm_heap/mm_initialize.c | 12 ++++++------
 mm/mm_heap/mm_mallinfo.c   |  5 +----
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h
index 5abe074b20..9ea235ecd3 100644
--- a/mm/mm_heap/mm.h
+++ b/mm/mm_heap/mm.h
@@ -146,10 +146,6 @@
 
 #define SIZEOF_MM_FREENODE sizeof(struct mm_freenode_s)
 
-/* What is the size of the start/end node? */
-
-#define SIZEOF_MM_STARTENDNODE MM_MIN_CHUNK
-
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index 06fd9e652f..e32c63cdac 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -118,15 +118,15 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
   heap->mm_heapstart[IDX]            = (FAR struct mm_allocnode_s *)
                                        heapbase;
   MM_ADD_BACKTRACE(heap, heap->mm_heapstart[IDX]);
-  heap->mm_heapstart[IDX]->size      = SIZEOF_MM_STARTENDNODE;
+  heap->mm_heapstart[IDX]->size      = SIZEOF_MM_ALLOCNODE;
   heap->mm_heapstart[IDX]->preceding = MM_ALLOC_BIT;
   node                               = (FAR struct mm_freenode_s *)
-                                       (heapbase + SIZEOF_MM_STARTENDNODE);
-  node->size                         = heapsize - 2*SIZEOF_MM_STARTENDNODE;
-  node->preceding                    = SIZEOF_MM_STARTENDNODE;
+                                       (heapbase + SIZEOF_MM_ALLOCNODE);
+  node->size                         = heapsize - 2*SIZEOF_MM_ALLOCNODE;
+  node->preceding                    = SIZEOF_MM_ALLOCNODE;
   heap->mm_heapend[IDX]              = (FAR struct mm_allocnode_s *)
-                                       (heapend - SIZEOF_MM_STARTENDNODE);
-  heap->mm_heapend[IDX]->size        = SIZEOF_MM_STARTENDNODE;
+                                       (heapend - SIZEOF_MM_ALLOCNODE);
+  heap->mm_heapend[IDX]->size        = SIZEOF_MM_ALLOCNODE;
   heap->mm_heapend[IDX]->preceding   = node->size | MM_ALLOC_BIT;
   MM_ADD_BACKTRACE(heap, heap->mm_heapend[IDX]);
 
diff --git a/mm/mm_heap/mm_mallinfo.c b/mm/mm_heap/mm_mallinfo.c
index 3144e48a39..7ecdc039e3 100644
--- a/mm/mm_heap/mm_mallinfo.c
+++ b/mm/mm_heap/mm_mallinfo.c
@@ -121,10 +121,7 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
   mm_foreach(heap, mallinfo_handler, info);
 
   info->arena = heap->mm_heapsize;
-
-  /* Account for the tail node */
-
-  info->uordblks += region * SIZEOF_MM_STARTENDNODE;
+  info->uordblks += region * SIZEOF_MM_ALLOCNODE; /* account for the tail node */
 
   DEBUGASSERT(info->uordblks + info->fordblks == heap->mm_heapsize);