kernel/vm.c
// Recursively free page-table pages.
// All leaf mappings must already have been removed.
Recursively free page-table pages.
All leaf mappings must already have been removed.
Recursively free page - table pages . All leaf mappings must already have been removed .
static void
freewalk(pagetable_t pagetable)
{
  for(int i = 0; i < 512; i++){
    pte_t pte = pagetable[i];
    if((pte & PTE_V) && (pte & (PTE_R|PTE_W|PTE_X)) == 0){
      uint64 child = PTE2PA(pte);
      freewalk((pagetable_t)child);
      pagetable[i] = 0;
    } else if(pte & PTE_V){
      panic("freewalk: leaf");
    }
  }
  kfree((void*)pagetable);
}
static void freewalk ( pagetable_t pagetable ) { for ( int i = 0 ; i < 512 ; i ++ ) { pte_t pte = pagetable [ i ] ; if ( ( pte & PTE_V ) && ( pte & ( PTE_R | PTE_W | PTE_X ) ) == 0 ) { uint64 child = PTE2PA ( pte ) ; freewalk ( ( pagetable_t ) child ) ; pagetable [ i ] = 0 ; } else if ( pte & PTE_V ) { panic ( " " ) ; } } kfree ( ( void * ) pagetable ) ; }
Recursively free page-table pages.
Recursively free page - table pages .
// there are 2^9 = 512 PTEs in a page table. // this PTE points to a lower-level page table.