nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

mm: replace mutex with spinlock in the implementation of memory allocation

Open hujun260 opened this issue 1 year ago • 2 comments

Summary

  1. Since memory allocation operations are all non-blocking, we can replace mutex with spinlock.
  2. Spinlock is significantly faster than mutex, improving the real-time capability and performance of the system.
  3. We can allocate memory in irq.
  4. In many cases, memory allocation operates within critical sections, and mutex may cause context switches, leading to confusion
  5. Impacting the use of memory allocation within spinlock scope

Impact

none

Testing

ostest

hujun260 avatar Sep 06 '24 09:09 hujun260

mm_lock could yeild the CPU to other tasks, but replace spinlock will increase the CPU load, you should optimize the allocation algorithm instead of making the CPU busier.

anchao avatar Sep 06 '24 11:09 anchao

could we implement a nested memory pool for each task? which can improve memory allocation performance and avoid the additional overhead caused by context switching as much as possible.

anchao avatar Sep 06 '24 11:09 anchao