xiaoxiang781216 commented on code in PR #5991:
URL: https://github.com/apache/incubator-nuttx/pull/5991#discussion_r844869056
##########
mm/mm_heap/mm_initialize.c:
##########
@@ -93,12 +93,17 @@ 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);
- heapend = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize);
+ heapbase = MM_ALIGN_UP((uintptr_t)heapstart + SIZEOF_MM_ALLOCNODE)
+ - SIZEOF_MM_ALLOCNODE;
+ heapend = MM_ALIGN_DOWN((uintptr_t)heapstart + (uintptr_t)heapsize)
Review Comment:
The original code:
1. Align heapbase and heapend to MM_MIN_CHUNK
2. #5906 ensure two preallocate nodes with MM_MIN_CHUNK
So, the rest of free slot should multiple of MM_MIN_CHUNK. It's strange that
we need an additional alignment here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]