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

feat(mm): add slab usage calculation #768

Merged
merged 11 commits into from
Apr 29, 2024

Conversation

laokengwt
Copy link
Contributor

No description provided.

@dragonosbot
Copy link

@laokengwt: no appropriate reviewer found, use r? to override

@dragonosbot dragonosbot added the S-等待审查 Status: 等待assignee以及相关方的审查。 label Apr 25, 2024
@github-actions github-actions bot added the ambiguous The title of PR/issue doesn't match the format label Apr 25, 2024
@fslongjin
Copy link
Member

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Apr 25, 2024
@laokengwt laokengwt changed the title 添加slab可用空间计算并将其添加到sysinfo的freeram feat(mm): 添加slab可用空间计算并将其添加到sysinfo的freeram Apr 25, 2024
@github-actions github-actions bot added enhancement New feature or request and removed ambiguous The title of PR/issue doesn't match the format documentation Improvements or additions to documentation labels Apr 25, 2024
@laokengwt laokengwt changed the title feat(mm): 添加slab可用空间计算并将其添加到sysinfo的freeram feat(mm): add slab usage calculation Apr 25, 2024
let mut count = 0;

// 遍历所有scallocator
while count < 9 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个为啥是9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是slab里面scallocator的数量

Copy link
Member

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.

https://code.dragonos.org.cn/xref/DragonOS/kernel/crates/rust-slabmalloc/src/zone.rs?r=ceeb2e943ca7645609920ec7ad8bfceea2b13de6#65

if let Some(ref mut slab) = SLABALLOCATOR {
slab.zone.usage()
} else {
panic!("slab hasn't been initialized")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该返回零,而不是panic,不然如果我们调试的时候想禁用掉slab,结果就panic掉了,这个显然是不合理的。

@@ -63,6 +63,15 @@ impl SlabAllocator {
}
}

/// 获取slab中的空闲空间
pub unsafe fn slab_usage() -> u64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看这个名字,让人理解为slab里面已经使用的空间哦。

而且分配器的trait里面不已经有一个usage方法了吗?为啥要自己实现一个usage?

@fslongjin
Copy link
Member

@dragonosbot author

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 26, 2024
@@ -126,6 +123,38 @@ impl<'a> ZoneAllocator<'a> {
}
}
}

/// 获取scallocator中的还未被分配的空间
pub fn usage(&mut self) -> u64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我的意思是,定义一个结构体类似这样的:

https://code.dragonos.org.cn/xref/DragonOS/kernel/src/mm/allocator/page_frame.rs?r=471d65cf158c9bf741c21f5d0ab92efe7bf1c3d4#281

因为usage这个函数名字,然后你只返回空闲空间的数字的话,其实总让人觉得是“已经使用了的空间”的意思


/// slab空闲空间
pub struct SlabFreeSpace {
pub free: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

啊这,为什么你不在slab那个库里面定义一个slabusage的结构体,然后有free和use的两个字段,而要在内核里面定义这个。

这个从职责分配上来说就是一个很不好的设计。

@laokengwt
Copy link
Contributor Author

@dragonosbot review

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Apr 28, 2024
Copy link
Member

@fslongjin fslongjin left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不要直接写4096,而是应该用OBJECT_PAGE_SIZEE。

@fslongjin
Copy link
Member

@dragonosbot author

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 28, 2024
@laokengwt
Copy link
Contributor Author

@dragonosbot review

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Apr 28, 2024
@laokengwt
Copy link
Contributor Author

@dragonosbot review

// 剩余可分配object数乘上page中规定的每个object的大小,即空闲空间
free += obj_count * scallocator.size();
}
count -= 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个测试过吗?count -= 1;怎么能跑的。

@fslongjin
Copy link
Member

@dragonosbot author

@dragonosbot dragonosbot added S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 and removed S-等待审查 Status: 等待assignee以及相关方的审查。 labels Apr 28, 2024
@laokengwt
Copy link
Contributor Author

@dragonosbot review

@dragonosbot dragonosbot added S-等待审查 Status: 等待assignee以及相关方的审查。 and removed S-等待作者修改 Status: 这正在等待作者的一些操作(例如代码更改或更多信息)。 labels Apr 29, 2024
@fslongjin fslongjin merged commit 7401bec into DragonOS-Community:master Apr 29, 2024
7 checks passed
@laokengwt laokengwt deleted the slab branch May 7, 2024 08:39
BrahmaMantra pushed a commit to BrahmaMantra/DragonOS that referenced this pull request Dec 9, 2024
* Add slab free space calculation and add it to freeram of sysinfo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request S-等待审查 Status: 等待assignee以及相关方的审查。
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants