nuttx
nuttx copied to clipboard
mm: replace mutex with spinlock in the implementation of memory allocation
Summary
- Since memory allocation operations are all non-blocking, we can replace mutex with spinlock.
- Spinlock is significantly faster than mutex, improving the real-time capability and performance of the system.
- We can allocate memory in irq.
- In many cases, memory allocation operates within critical sections, and mutex may cause context switches, leading to confusion
- Impacting the use of memory allocation within spinlock scope
Impact
none
Testing
ostest
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.
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.