Hi all, I have been investigating an issue pointed out by Masayuki Ishikawa (in https://github.com/apache/nuttx-apps/pull/2159) where memory usage rises after executing loadable processes in SMP mode. This happens after removing sched_lock() from nsh_fileapps, as discussed in a previous thread.
I did some investigation and came to the conclusion that while the PR in question causes the aforementioned regression, the fundamental problem is much deeper and far more serious. In SMP mode there is a mm_delaylist for each CPU, I presume to make exclusive access to the list easier to implement. When calling mm_free() the memory is put into the delaylist if the mm_lock cannot be acquired, while the delaylist elements are freed when mm_malloc() is called. However, there is a problem with the per-CPU delaylist approach when using this opportunistic approach: - If only CPU 0 allocates memory, and only CPU 1 frees memory, this can cause a systematic error where CPU 1:s mm_delaylist is filled up with items to be freed, but since CPU 1 never calls mm_malloc() the items are never freed. The case is theoretical but entirely possible (as proven by the simple test case in PR 2159) resulting in a situation where memory runs out because all of the free memory is in CPU X:s mm_delaylist, waiting to be freed. My question is, is there no deterministic alternative to this opportunistic approach ? E.g. handling the delaylist from the idle process ? I am asking for advice on how to solve this issue, any and all is greatly appreciated. Br, Ville Juven
