Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hujun260
Copy link
Contributor

@hujun260 hujun260 commented Sep 6, 2024

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 hujun260 force-pushed the apache_2 branch 2 times, most recently from a8def70 to 35c46e1 Compare September 6, 2024 11:28
@anchao
Copy link
Contributor

anchao commented Sep 6, 2024

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
Copy link
Contributor

anchao commented Sep 6, 2024

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.

@hujun260 hujun260 marked this pull request as draft September 11, 2024 13:26
…ation.

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

Signed-off-by: hujun5 <hujun5@xiaomi.com>
@hujun260 hujun260 marked this pull request as ready for review September 14, 2024 10:25
@hujun260 hujun260 marked this pull request as draft September 14, 2024 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants