-
-
Notifications
You must be signed in to change notification settings - Fork 161
rust重构mmio_buddy和mmio #178
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fslongjin
requested changes
Mar 1, 2023
fslongjin
reviewed
Mar 4, 2023
|
||
  `free_regions`的下标(index)与内存块的大小有关。由于每个内存块大小都为$2^{n}$ bit,那么可以令$exp = n$。index与exp的换算公式如下:$index = exp - 12$。e.g. 一个大小为$2^{12}$ bit的内存块,其$exp = 12$,使用上述公式计算得$index = 12 -12 = 0$,所以该内存块会被存入`free_regions[0].list`中。通过上述换算公式,每次取出或释放$2^n$大小的内存块,只需要操作`free_regions[n -12]`即可。DragonOS中,buddy内存池最大的内存块大小为$1G = 2^{30}bit$,最小的内存块大小为 $4K = 2^{12} bit$,所以$index\in[0,18]$。 | ||
|
||
  作为内存分配机制,buddy服务于所有进程,为了解决在各个进程之间实现free_regions中的链表数据同步的问题,`free_regions`中的链表类型采用加了[自旋锁 — DragonOS dev 文档](https://docs.dragonos.org/zh_CN/latest/kernel/locking/spinlock.html#spinlock)(SpinLock)的空闲内存块链表(MmioFreeRegionList),`MmioFreeRegionList`中封装有真正的存储了空闲内存块信息的结构体的链表(list)和对应链表长度(num_free)。有了自选锁后,同一时刻只允许一个进程修改某个链表,如取出链表元素(申请内存)或者向链表中插入元素(释放内存)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.