pussuw commented on PR #2159:
URL: https://github.com/apache/nuttx-apps/pull/2159#issuecomment-1782552870
One part of the problem is related to address environment handling in SMP
mode, more specifically the lazy TLB part is faulty in SMP mode.
With the sched_lock(), both nsh and hello run on CPU0, which means it works
just like in the non-SMP mode. Remove the sched_lock() and nsh runs on CPU0 and
hello runs on CPU1. Why ? I don't know.
The leak happens when CPU1 tries to hold on to hello's address environment
even after hello has exited (the lazy TLB feature works like this). This
explains why the page pool memory is not freed:
```
// Bad, addrenv is NOT freed
[ 0.030000] [CPU0] addrenv_switch: Addrenv:0->0x8020d7b0, tcb:0x802048b0,
name:CPU0 IDLE
[ 0.090000] [CPU1] addrenv_switch: Addrenv:0->0x8020d7b0, tcb:0x8020d830,
name:/system/bin/init
NuttShell (NSH) NuttX-10.4.0
nsh> free
total used free largest nused nfree
Kmem: 2053120 17632 2035488 2034656 56 3
Page: 4194304 602112 3592192 3592192
nsh> hello
[ 19.860000] [CPU0] addrenv_switch: Addrenv:0x8020d7b0->0x8020dc90,
tcb:0x8020d830, name:/system/bin/init
[ 19.860000] [CPU0] addrenv_switch: Addrenv:0x8020dc90->0x8020d7b0,
tcb:0x8020d830, name:/system/bin/init
[ 19.870000] [CPU0] addrenv_switch: Addrenv:0x8020d7b0->0x8020dc90,
tcb:0x8020d830, name:/system/bin/init
[ 19.900000] [CPU0] addrenv_switch: Addrenv:0x8020dc90->0x8020d7b0,
tcb:0x8020d830, name:/system/bin/init
[ 19.900000] [CPU0] addrenv_switch: Addrenv:0x8020d7b0->0x8020dc90,
tcb:0x8020d830, name:/system/bin/init
[ 19.900000] [CPU0] addrenv_switch: Addrenv:0x8020dc90->0x8020d7b0,
tcb:0x8020d830, name:/system/bin/init
[ 19.910000] [CPU1] addrenv_switch: Addrenv:0x8020d7b0->0x8020dc90,
tcb:0x8020dd10, name:hello
nsh> free
total used free largest nused nfree
Kmem: 2053120 21216 2031904 2031568 59 4
Page: 4194304 1175552 3018752 3018752
nsh>
```
Why Kmem is leaked, I don't know yet..
--
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]