Skip to content

Commit

Permalink
kernel/mm: Reduce stack footprint of page-table freeing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
joergroedel committed Aug 20, 2024
1 parent 3280b5f commit 5767d8e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/src/mm/pagetable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ struct RawPageTablePart {
impl RawPageTablePart {
/// Frees a level 1 page table.
fn free_lvl1(page: &PTPage) {
for entry in page.entries {
for entry in page.entries.iter().copied() {
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
Expand All @@ -989,7 +989,7 @@ 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 {
for entry in page.entries.iter().copied() {
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,
Expand Down

0 comments on commit 5767d8e

Please sign in to comment.