-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
feat(mm): add slab usage calculation #768
Conversation
@laokengwt: no appropriate reviewer found, use |
let mut count = 0; | ||
|
||
// 遍历所有scallocator | ||
while count < 9 { |
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.
这个为啥是9
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.
这个是slab里面scallocator的数量
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.
这个是slab里面scallocator的数量
那应该使用slab allocator的常量,而不是在这里写死一个9.
kernel/src/mm/allocator/slab.rs
Outdated
if let Some(ref mut slab) = SLABALLOCATOR { | ||
slab.zone.usage() | ||
} else { | ||
panic!("slab hasn't been initialized") |
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.
应该返回零,而不是panic,不然如果我们调试的时候想禁用掉slab,结果就panic掉了,这个显然是不合理的。
kernel/src/mm/allocator/slab.rs
Outdated
@@ -63,6 +63,15 @@ impl SlabAllocator { | |||
} | |||
} | |||
|
|||
/// 获取slab中的空闲空间 | |||
pub unsafe fn slab_usage() -> u64 { |
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.
看这个名字,让人理解为slab里面已经使用的空间哦。
而且分配器的trait里面不已经有一个usage方法了吗?为啥要自己实现一个usage?
@dragonosbot author |
@@ -126,6 +123,38 @@ impl<'a> ZoneAllocator<'a> { | |||
} | |||
} | |||
} | |||
|
|||
/// 获取scallocator中的还未被分配的空间 | |||
pub fn usage(&mut self) -> u64 { |
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.
我的意思是,定义一个结构体类似这样的:
因为usage这个函数名字,然后你只返回空闲空间的数字的话,其实总让人觉得是“已经使用了的空间”的意思
kernel/src/mm/allocator/slab.rs
Outdated
|
||
/// slab空闲空间 | ||
pub struct SlabFreeSpace { | ||
pub free: u64, |
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.
啊这,为什么你不在slab那个库里面定义一个slabusage的结构体,然后有free和use的两个字段,而要在内核里面定义这个。
这个从职责分配上来说就是一个很不好的设计。
@dragonosbot review |
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.
在释放页面的时候需要减少计数,在那个try_reclaim_pages()
里面
@@ -162,9 +198,38 @@ unsafe impl<'a> crate::Allocator<'a> for ZoneAllocator<'a> { | |||
match ZoneAllocator::get_slab(layout.size()) { | |||
Slab::Base(idx) => { | |||
self.small_slabs[idx].refill(new_page); | |||
// 每refill一个page就为slab的总空间统计加上4KB | |||
self.total += 4096; |
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.
这个不要直接写4096,而是应该用OBJECT_PAGE_SIZEE。
@dragonosbot author |
@dragonosbot review |
@dragonosbot review |
// 剩余可分配object数乘上page中规定的每个object的大小,即空闲空间 | ||
free += obj_count * scallocator.size(); | ||
} | ||
count -= 1; |
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.
这个测试过吗?count -= 1;
怎么能跑的。
@dragonosbot author |
@dragonosbot review |
* Add slab free space calculation and add it to freeram of sysinfo
No description provided.