mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 01:13:23 +00:00
Inject a scalable buddy system allocator to OSTD
Co-authored-by: Zhe Tang <tangzh@stu.pku.edu.cn>
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
92bc8cbbf7
commit
5f05963ee5
@ -19,6 +19,7 @@ aster-virtio = { path = "comps/virtio" }
|
||||
aster-rights = { path = "libs/aster-rights" }
|
||||
component = { path = "libs/comp-sys/component" }
|
||||
controlled = { path = "libs/comp-sys/controlled" }
|
||||
osdk-frame-allocator = { path = "../osdk/deps/frame-allocator" }
|
||||
ostd = { path = "../ostd" }
|
||||
typeflags = { path = "libs/typeflags" }
|
||||
typeflags-util = { path = "libs/typeflags-util" }
|
||||
|
@ -8,8 +8,6 @@
|
||||
|
||||
use alloc::format;
|
||||
|
||||
use ostd::mm::stat;
|
||||
|
||||
use crate::{
|
||||
fs::{
|
||||
procfs::template::{FileOps, ProcFileBuilder},
|
||||
@ -27,21 +25,17 @@ impl MemInfoFileOps {
|
||||
}
|
||||
}
|
||||
|
||||
/// Total memory in the entire system in bytes.
|
||||
fn mem_total() -> usize {
|
||||
stat::mem_total()
|
||||
}
|
||||
|
||||
/// An estimation of how much memory is available for starting new
|
||||
/// applications, without disk operations.
|
||||
fn mem_available() -> usize {
|
||||
stat::mem_available()
|
||||
}
|
||||
|
||||
impl FileOps for MemInfoFileOps {
|
||||
fn data(&self) -> Result<Vec<u8>> {
|
||||
let total = mem_total() / 1024;
|
||||
let available = mem_available() / 1024;
|
||||
// The total amount of physical memory available to the system.
|
||||
let total = crate::vm::mem_total();
|
||||
// An estimation of how much memory is available for starting new
|
||||
// applications, without disk operations.
|
||||
let available = osdk_frame_allocator::load_total_free_size();
|
||||
|
||||
// Convert the values to KiB.
|
||||
let total = total / 1024;
|
||||
let available = available / 1024;
|
||||
let free = total - available;
|
||||
let output = format!(
|
||||
"MemTotal:\t{} kB\nMemFree:\t{} kB\nMemAvailable:\t{} kB\n",
|
||||
|
@ -1,7 +1,6 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use aster_time::read_monotonic_time;
|
||||
use ostd::mm::stat::{mem_available, mem_total};
|
||||
|
||||
use super::SyscallReturn;
|
||||
use crate::prelude::*;
|
||||
@ -26,8 +25,8 @@ pub struct sysinfo {
|
||||
pub fn sys_sysinfo(sysinfo_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let info = sysinfo {
|
||||
uptime: read_monotonic_time().as_secs() as i64,
|
||||
totalram: mem_total() as u64,
|
||||
freeram: mem_available() as u64,
|
||||
totalram: crate::vm::mem_total() as u64,
|
||||
freeram: osdk_frame_allocator::load_total_free_size() as u64,
|
||||
..Default::default() // TODO: add other system information
|
||||
};
|
||||
ctx.user_space().write_val(sysinfo_addr, &info)?;
|
||||
|
@ -16,8 +16,27 @@
|
||||
//! In Asterinas, VMARs and VMOs, as well as other capabilities, are implemented
|
||||
//! as zero-cost capabilities.
|
||||
|
||||
use osdk_frame_allocator::FrameAllocator;
|
||||
|
||||
pub mod page_fault_handler;
|
||||
pub mod perms;
|
||||
pub mod util;
|
||||
pub mod vmar;
|
||||
pub mod vmo;
|
||||
|
||||
#[ostd::global_frame_allocator]
|
||||
static FRAME_ALLOCATOR: FrameAllocator = FrameAllocator;
|
||||
|
||||
/// Total physical memory in the entire system in bytes.
|
||||
pub fn mem_total() -> usize {
|
||||
use ostd::boot::{boot_info, memory_region::MemoryRegionType};
|
||||
|
||||
let regions = &boot_info().memory_regions;
|
||||
let total = regions
|
||||
.iter()
|
||||
.filter(|region| region.typ() == MemoryRegionType::Usable)
|
||||
.map(|region| region.len())
|
||||
.sum::<usize>();
|
||||
|
||||
total
|
||||
}
|
||||
|
Reference in New Issue
Block a user