mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
feat(mm): add slab usage calculation (#768)
* Add slab free space calculation and add it to freeram of sysinfo
This commit is contained in:
@ -1,6 +1,3 @@
|
||||
//! 当前slab分配器暂时不使用,等待后续完善后合并主线
|
||||
#![allow(dead_code)]
|
||||
|
||||
use core::{alloc::Layout, ptr::NonNull, sync::atomic::AtomicBool};
|
||||
|
||||
use alloc::boxed::Box;
|
||||
@ -74,3 +71,11 @@ pub unsafe fn slab_init() {
|
||||
pub fn slab_init_state() -> bool {
|
||||
unsafe { *SLABINITSTATE.get_mut() }
|
||||
}
|
||||
|
||||
pub unsafe fn slab_usage() -> SlabUsage {
|
||||
if let Some(ref mut slab) = SLABALLOCATOR {
|
||||
slab.zone.usage()
|
||||
} else {
|
||||
SlabUsage::new(0, 0)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
arch::{mm::LockedFrameAllocator, rand::rand},
|
||||
libs::rand::GRandFlags,
|
||||
mm::allocator::page_frame::FrameAllocator,
|
||||
mm::allocator::{page_frame::FrameAllocator, slab::slab_usage},
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use core::cmp;
|
||||
@ -38,10 +38,11 @@ impl Syscall {
|
||||
let mut sysinfo = SysInfo::default();
|
||||
|
||||
let mem = unsafe { LockedFrameAllocator.usage() };
|
||||
let slab_usage = unsafe { slab_usage() };
|
||||
sysinfo.uptime = 0;
|
||||
sysinfo.loads = [0; 3];
|
||||
sysinfo.totalram = mem.total().bytes() as u64;
|
||||
sysinfo.freeram = mem.free().bytes() as u64;
|
||||
sysinfo.freeram = mem.free().bytes() as u64 + slab_usage.free();
|
||||
sysinfo.sharedram = 0;
|
||||
sysinfo.bufferram = 0;
|
||||
sysinfo.totalswap = 0;
|
||||
|
Reference in New Issue
Block a user