vm.c
// Deallocate user pages to bring the process size from oldsz to
// newsz.  oldsz and newsz need not be page-aligned, nor does newsz
// need to be less than oldsz.  oldsz can be larger than the actual
// process size.  Returns the new process size.
Deallocate user pages to bring the process size from oldsz to
newsz.  oldsz and newsz need not be page-aligned, nor does newsz
need to be less than oldsz.  oldsz can be larger than the actual
process size.  Returns the new process size.
Deallocate user pages to bring the process size from oldsz to newsz . oldsz and newsz need not be page - aligned nor does newsz need to be less than oldsz . oldsz can be larger than the actual process size . Returns the new process size .
int
deallocuvm(pde_t *pgdir, uint oldsz, uint newsz)
{
  pte_t *pte;
  uint a, pa = 0, blockno;
  if(newsz >= oldsz)
    return oldsz;
  a = PGROUNDUP(newsz);
  for(; a  < oldsz; a += PGSIZE){
    pte = walkpgdir(pgdir, (char*)a, 0);
    if(!pte)
      a = PGADDR(PDX(a) + 1, 0, 0) - PGSIZE;
    else if((*pte & PTE_P) != 0){
      pa = PTE_ADDR(*pte);
      if(pa == 0)
        panic("kfree");
      char *v = P2V(pa);
      kfree(v);
      *pte = 0;
    }
    else if((*pte & PTE_SWAPPED)) {
        blockno = (*pte)>>12;
        bfree_page(blockno);
        char *v = P2V(pa);
        kfree(v);
        *pte = 0;
    }
  }
  return newsz;
}
int deallocuvm ( pde_t * pgdir , uint oldsz , uint newsz ) { pte_t * pte ; uint a , pa = 0 , blockno ; if ( newsz >= oldsz ) return oldsz ; a = PGROUNDUP ( newsz ) ; for ( ; a < oldsz ; a += PGSIZE ) { pte = walkpgdir ( pgdir , ( char * ) a , 0 ) ; if ( ! pte ) a = PGADDR ( PDX ( a ) + 1 , 0 , 0 ) - PGSIZE ; else if ( ( * pte & PTE_P ) != 0 ) { pa = PTE_ADDR ( * pte ) ; if ( pa == 0 ) panic ( " " ) ; char * v = P2V ( pa ) ; kfree ( v ) ; * pte = 0 ; } else if ( ( * pte & PTE_SWAPPED ) ) { blockno = ( * pte ) >> 12 ; bfree_page ( blockno ) ; char * v = P2V ( pa ) ; kfree ( v ) ; * pte = 0 ; } } return newsz ; }
Deallocate user pages to bring the process size from oldsz to
newsz.
Deallocate user pages to bring the process size from oldsz to newsz .