From 09199074d825a3b2da5a3065cd35ca3919a27550 Mon Sep 17 00:00:00 2001 From: Joerg Roedel Date: Tue, 20 Aug 2024 17:42:17 +0200 Subject: [PATCH] kernel/mm: Reduce stack footprint of page-table freeing Turns out that the way the iterators are implemented in RawPageTablePart::free_lvl*() the compiler makes copies of entire pages on the stack, which overflows the 32 KiB stack pretty quickly. Iterate over references only and significantly reduce stack usage of the page-table freeing code. Signed-off-by: Joerg Roedel --- kernel/src/mm/pagetable.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/src/mm/pagetable.rs b/kernel/src/mm/pagetable.rs index 8b743b692..deb32676c 100644 --- a/kernel/src/mm/pagetable.rs +++ b/kernel/src/mm/pagetable.rs @@ -977,8 +977,8 @@ struct RawPageTablePart { impl RawPageTablePart { /// Frees a level 1 page table. fn free_lvl1(page: &PTPage) { - for entry in page.entries { - if let Some(page) = PTPage::from_entry(entry) { + for entry in page.entries.iter() { + if let Some(page) = PTPage::from_entry(*entry) { // SAFETY: the page comes from an entry in the page table, // which we allocated using `PTPage::alloc()`, so this is // safe. @@ -989,8 +989,8 @@ impl RawPageTablePart { /// Frees a level 2 page table, including all level 1 tables beneath it. fn free_lvl2(page: &PTPage) { - for entry in page.entries { - if let Some(l1_page) = PTPage::from_entry(entry) { + for entry in page.entries.iter() { + if let Some(l1_page) = PTPage::from_entry(*entry) { Self::free_lvl1(l1_page); // SAFETY: the page comes from an entry in the page table, // which we allocated using `PTPage::alloc()`, so this is