You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/03/31 18:24:36 UTC

[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on a change in pull request #1112: testing/mm: add memory boundary realloc test.

xiaoxiang781216 commented on a change in pull request #1112:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1112#discussion_r839899047



##########
File path: testing/mm/mm_main.c
##########
@@ -37,18 +39,51 @@
 
 #define STOP_ON_ERRORS exit(1)
 
-/* All other definitions derive from these two */
-
-#define MM_MIN_SHIFT      4  /* 16 bytes */
-#define MM_MIN_CHUNK     (1 << MM_MIN_SHIFT)
-#define MM_GRAN_MASK     (MM_MIN_CHUNK - 1)
-#define MM_ALIGN_UP(a)   (((a) + MM_GRAN_MASK) & ~MM_GRAN_MASK)
-#define MM_ALIGN_DOWN(a) ((a) & ~MM_GRAN_MASK)
+/* All other definitions derive from these two

Review comment:
       could we add nuttx/mm/mm_heap to search path?

##########
File path: testing/mm/mm_main.c
##########
@@ -279,6 +316,174 @@ static void do_frees(FAR void **mem, FAR const int *size,
     }
 }
 
+static void realloc_boundary_free(void)
+{
+  dq_entry_t *tail;
+
+  /* Free all the memory in the relloc queue */
+
+  printf("Free all the memory in the relloc queue\n");
+
+  while (!dq_empty(&g_realloc_queue))
+    {
+      tail = dq_remlast(&g_realloc_queue);
+      if (tail != NULL)
+        {
+          free(tail);
+        }
+      else
+        {
+          DEBUGASSERT(false);
+        }
+    }
+}
+
+static void *realloc_boundary_malloc(int *nodesize)
+{
+  int size;
+  int clz;
+  void *ptr = NULL;
+
+  DEBUGASSERT(nodesize);
+
+  *nodesize = 0;
+  g_alloc_info = mallinfo();
+  if (g_alloc_info.mxordblk < MM_MIN_CHUNK)
+    {
+      size = MM_MIN_CHUNK;
+    }
+  else
+    {
+      /* Get a a suitable size to make sure function
+       * realloc_boundary_malloc() can run twice.
+       */
+
+      clz  = __builtin_clz(g_alloc_info.mxordblk);

Review comment:
       call fls instead




-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org