pussuw commented on PR #2159:
URL: https://github.com/apache/nuttx-apps/pull/2159#issuecomment-1784818486

   Got back to this, the reason the memory is never freed in this simple test 
case, is that there is a mm_delaylist for every CPU:
   
   ```
     /* Free delay list, for some situations where we can't do free
      * immdiately.
      */
   
     FAR struct mm_delaynode_s *mm_delaylist[CONFIG_SMP_NCPUS];
   ```
   
   What happens, CPU1 puts the tcb, kernel stack and others to CPU1 delaylist:
   ```
   
   [   13.190000] [CPU1] nxtask_exit: Release 0x8020dd10, cpu:1
   [   13.190000] [CPU1] nxsched_release_tcb: Release 0x8020dd10
   [   13.190000] [CPU1] mm_free: Freeing 0xc0202000
   [   13.190000] [CPU1] mm_free: Delaylist! 0xc0202000
   [   13.190000] [CPU1] up_addrenv_kstackfree: Free kernel stack 0x80213310
   [   13.190000] [CPU1] mm_free: Freeing 0x80213310
   [   13.190000] [CPU1] mm_free: Delaylist! 0x80213310
   [   13.190000] [CPU1] nxsched_release_tcb: Release kstack 0x8020dd10
   [   13.190000] [CPU1] nxsched_release_tcb: Release addrenv 0x8020dd10
   [   13.190000] [CPU1] nxsched_release_tcb: Release group 0x8020dd10
   [   13.190000] [CPU1] nxsched_release_tcb: Release tcb 0x8020dd10
   [   13.190000] [CPU1] mm_free: Freeing 0x8020dd10
   [   13.190000] [CPU1] mm_free: Delaylist! 0x8020dd10
   ```
   
   The next time when mm_malloc() is called, it is done by CPU0 only so it does 
not see the pending elements in CPU1 queue:
   
   ```
   nsh> free
   [   28.380000] [CPU0] free_delaylist: Delaylist free: 0
   [   28.380000] [CPU0] free_delaylist: Delaylist free: 0
   [   28.390000] [CPU0] free_delaylist: Delaylist free: 0
   [   28.390000] [CPU0] mm_free: Freeing 0x8020d9a0
   [   28.390000] [CPU0] mm_free: Freeing 0x8020dc50
   [   28.390000] [CPU0] mm_free: Freeing 0x8020dbe0
   [   28.390000] [CPU0] free_delaylist: Delaylist free: 0
                      total       used       free    largest  nused  nfree
           Kmem:    2053120      53440    1999680    1999344     59      4
           Page:    4194304    1175552    3018752    3018752
   [   28.390000] [CPU0] mm_free: Freeing 0x8020de80
   
   ```
   
   Eventually when / if CPU1 calls mm_malloc() it will free the memory. The way 
the delay list is handled is quite opportunistic. Is there no deterministic way 
to handle it ? 
   


-- 
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]

Reply via email to