CV-Bowen commented on code in PR #5991:
URL: https://github.com/apache/incubator-nuttx/pull/5991#discussion_r844948235
##########
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:
@xiaoxiang781216 @yamt A tricky solution is to make heapstart->size =
**SIZEOF_MM_STARTENDNODE** = **MM_MIN_CHUNK**, heapend->size =
**SIZEOF_MM_ALLOCNODE**, so the reset memory size (remove start and end node
size) = (heapend - heapbase - MM_MIN_CHUNK - SIZEOF_MM_ALLOCNODE) is aligned
with MM_MIN_CHUNK, and the goal of #5906 is also satisfied.
##########
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:
@xiaoxiang781216 I'm afraid not, (heapend - heapbase) % MM_MIN_CHUNK =
SIZEOF_MM_ALLOCNODE, so the memory size is not aligned with MM_MIN_CHUNK.
--
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]