From e696ba4440f656bd4adb57d63b67b20702d43782 Mon Sep 17 00:00:00 2001 From: LoGin Date: Sun, 8 Jun 2025 10:56:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=88=9B=E5=BB=BAbudd?= =?UTF-8?q?y=E7=9A=84=E5=87=BD=E6=95=B0=E6=A0=88=E5=B8=A7=E8=BF=87?= =?UTF-8?q?=E5=A4=A7=E7=9A=84=E9=97=AE=E9=A2=98=20(#1189)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 解决创建buddy的函数栈帧过大的问题 Signed-off-by: longjin * chore(kernel): 移除smoltcp的log依赖项 Signed-off-by: longjin --------- Signed-off-by: longjin --- kernel/Cargo.lock | 1 - kernel/Cargo.toml | 1 - kernel/src/arch/x86_64/smp/mod.rs | 7 ++++++- kernel/src/mm/allocator/buddy.rs | 11 ++++++----- kernel/src/mm/no_init.rs | 8 +++++++- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index f9ef3930..6213178f 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -1543,7 +1543,6 @@ dependencies = [ "cfg-if", "defmt", "heapless", - "log", "managed", ] diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 7fe70acc..0b8fe0bf 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -49,7 +49,6 @@ num = { version = "=0.4.0", default-features = false } num-derive = "=0.3" num-traits = { git = "https://git.mirrors.dragonos.org.cn/DragonOS-Community/num-traits.git", rev = "1597c1c", default-features = false } smoltcp = { version = "=0.11.0", default-features = false, features = [ - "log", "alloc", "socket-raw", "socket-udp", diff --git a/kernel/src/arch/x86_64/smp/mod.rs b/kernel/src/arch/x86_64/smp/mod.rs index eec877b8..1963df1c 100644 --- a/kernel/src/arch/x86_64/smp/mod.rs +++ b/kernel/src/arch/x86_64/smp/mod.rs @@ -151,11 +151,16 @@ pub struct X86_64SmpManager { } impl X86_64SmpManager { - pub const fn new() -> Self { + /// 创建一个新的X86_64SmpManager实例 + /// + /// 注:由于该函数只在编译时被调用,因此 `#[allow(clippy::large_stack_frames)]` 是安全的。 + #[allow(clippy::large_stack_frames)] + const fn new() -> Self { return Self { ia64_cpu_to_sapicid: RwLock::new([None; PerCpu::MAX_CPU_NUM as usize]), }; } + /// initialize the logical cpu number to APIC ID mapping pub fn build_cpu_map(&self) -> Result<(), SystemError> { // 参考:https://code.dragonos.org.cn/xref/linux-6.1.9/arch/ia64/kernel/smpboot.c?fi=smp_build_cpu_map#496 diff --git a/kernel/src/mm/allocator/buddy.rs b/kernel/src/mm/allocator/buddy.rs index 50ee1a3b..721ee5b3 100644 --- a/kernel/src/mm/allocator/buddy.rs +++ b/kernel/src/mm/allocator/buddy.rs @@ -77,11 +77,12 @@ impl BuddyAllocator { // 定义一个变量记录buddy表的大小 (A::PAGE_SIZE - mem::size_of::>()) / mem::size_of::(); + #[inline(never)] pub unsafe fn new(mut bump_allocator: BumpAllocator) -> Option { let initial_free_pages = bump_allocator.usage().free(); let total_memory = bump_allocator.usage().total(); debug!("Free pages before init buddy: {:?}", initial_free_pages); - debug!("Buddy entries: {}", Self::BUDDY_ENTRIES); + // debug!("Buddy entries: {}", Self::BUDDY_ENTRIES); let mut free_area: [PhysAddr; MAX_ORDER - MIN_ORDER] = [PhysAddr::new(0); MAX_ORDER - MIN_ORDER]; @@ -105,12 +106,12 @@ impl BuddyAllocator { }; let mut total_pages_to_buddy = PageFrameCount::new(0); - let mut res_areas = [PhysMemoryArea::default(); 128]; + static mut RES_AREAS: [PhysMemoryArea; 128] = [PhysMemoryArea::DEFAULT; 128]; let mut offset_in_remain_area = bump_allocator - .remain_areas(&mut res_areas) + .remain_areas(&mut RES_AREAS) .expect("BuddyAllocator: failed to get remain areas from bump allocator"); - let remain_areas = &res_areas[0..]; + let remain_areas = &RES_AREAS[0..]; for area in remain_areas { let mut paddr = (area.area_base_aligned() + offset_in_remain_area).data(); @@ -120,7 +121,7 @@ impl BuddyAllocator { if remain_pages.data() == 0 { continue; } - debug!("area: {area:?}, paddr: {paddr:#x}, remain_pages: {remain_pages:?}"); + // debug!("area: {area:?}, paddr: {paddr:#x}, remain_pages: {remain_pages:?}"); total_pages_to_buddy += remain_pages; diff --git a/kernel/src/mm/no_init.rs b/kernel/src/mm/no_init.rs index fdb8d4d6..9c699326 100644 --- a/kernel/src/mm/no_init.rs +++ b/kernel/src/mm/no_init.rs @@ -51,7 +51,13 @@ pub struct EarlyIoRemapPages { impl EarlyIoRemapPages { /// 预留的用于在内存管理初始化之前,映射内存所使用的页表数量 pub const EARLY_REMAP_PAGES_NUM: usize = 256; - pub const fn new() -> Self { + + /// 创建一个新的EarlyIoRemapPages实例 + /// + /// # Safety + /// 由于该函数只在编译时被调用,因此 `#[allow(clippy::large_stack_frames)]` 是安全的。 + #[allow(clippy::large_stack_frames)] + const fn new() -> Self { Self { pages: [EarlyRemapPage { data: [0; MMArch::PAGE_SIZE],