/* * Free a block. */ static void sfs_bfree(struct sfs_fs *sfs, uint32_t diskblock) { bitmap_unmark(sfs->sfs_freemap, diskblock); sfs->sfs_freemapdirty = true; }
void bitmap_ts_unmark(struct bitmap_ts* b, unsigned index) { assert(b != NULL); lock_acquire(b->lk); bitmap_unmark(b->bm, index); lock_release(b->lk); }
/* destroy all pages in physical memory and all swapped pages */ void as_destroy(struct addrspace *as) { int spl = splhigh(); int i = 0; //free all coremap entries for (; i < num_frames; i++) { if(coremap[i].state != FREE && coremap[i].addrspace == as){ coremap[i].addrspace = NULL; coremap[i].mapped_vaddr = 0; coremap[i].state = FREE; coremap[i].num_pages_allocated = 0; } } // free all pages in the swap file for(; i < array_getnum(as->as_regions); i++) { struct as_region* cur = (struct as_region*)array_getguy(as->as_regions, i); assert(cur->vbase % PAGE_SIZE == 0); // destroy all pages belonging to this region int j = 0; for (; j < cur->npages; j++) { vaddr_t page = cur->vbase + j * PAGE_SIZE; assert((page & PAGE_FRAME) == page); u_int32_t *pte = get_PTE_from_addrspace(as, page); if (((*pte & PTE_PRESENT) == 0) && ((*pte | PTE_SWAPPED) != 0)) { // if this page is in swap file... off_t file_slot = (*pte & SWAPFILE_OFFSET) >> 12; // the occupied bit must be set assert(bitmap_isset(swapfile_map, file_slot) != 0); bitmap_unmark(swapfile_map, file_slot); } } }
/*remove the page table entry mapped with paddr, */ int remove_ppage (u_int32_t paddr) { int result = 0; int spl=splhigh(); paddr = paddr & PAGE_FRAME; //get the index of the page in the page table int page_index = (paddr - coremap_base) / PAGE_SIZE; //make sure that the paddr address is valid assert((coremap[ page_index ].paddr & PAGE_FRAME) == (paddr & PAGE_FRAME)); /* * Clear the _PTE fields for this entry */ coremap[ page_index ].vaddr = 0; coremap[ page_index ].paddr = paddr & PAGE_FRAME; coremap[ page_index ].last_access_time_sec = 0; coremap[ page_index ].last_access_time_nsec = 0; coremap[ page_index ].pid = 0; coremap[ page_index ].status = PAGE_FREE; /* * umnark the bit of the core memory map to indicate that the page is free */ bitmap_unmark(core_memmap, page_index); splx(spl); return result; }
/*remove the swapped in page from the swap area mapping*/ int remove_spage (u_int32_t chunk) { int result = 0; //get the index of the chunk in the swap area int chunk_index = (chunk & PAGE_FRAME) / PAGE_SIZE; //make sure that the chunk address is valid assert( (swaparea[ chunk_index ].paddr & PAGE_FRAME) == chunk ); /* * Clear the swapmap for this chunk */ int spl=splhigh(); swaparea[ chunk_index ].vaddr = 0; swaparea[ chunk_index ].paddr = chunk; swaparea[ chunk_index ].last_access_time_sec = 0; swaparea[ chunk_index ].last_access_time_nsec = 0; swaparea[ chunk_index ].pid = 0; /* * unmark the memmap for the chunk to indicate that the chunk is free. */ bitmap_unmark(swap_memmap, chunk_index); splx(spl); return result; }
/* release allocated block */ static void testfs_put_block_freemap(struct super_block *sb, int block_nr) { assert(sb->block_freemap); bitmap_unmark(sb->block_freemap, block_nr); testfs_write_block_freemap(sb, block_nr); }
static int ToMem(u_int32_t flatloc, vaddr_t vaddr) { assert(lock_do_i_hold(&vmlock)); assert((vaddr & 0xfffff000) == vaddr); assert((flatloc & 0xfffff000) == flatloc); struct uio ku; int result; u_int32_t bitmaploc, diskloc, diskindex; bitmaploc = flatloc/PAGE_SIZE; assert (bitmap_isset(diskmap, bitmaploc)); diskindex = flatloc / DISKSPACE; diskloc = flatloc - diskindex * DISKSPACE; mk_kuio(&ku, (void*)vaddr , PAGE_SIZE, diskloc, UIO_READ); result = VOP_READ(disk[diskindex], &ku); if (result) { panic(strerror(result)); } bitmap_unmark(diskmap, bitmaploc); return result; }
/* * Free a block. */ static void sfs_bfree(struct sfs_fs *sfs, u_int32_t diskblock) { /* Don't think we need to synchronize this */ bitmap_unmark(sfs->sfs_freemap, diskblock); sfs->sfs_freemapdirty = 1; }
void file_free_page(struct file *f, page_t page) { assert(f != NULL); assert(f->f_page_bitmap != NULL); assert(bitmap_isset(f->f_page_bitmap, page)); bitmap_unmark(f->f_page_bitmap, page); //assert(file_sync_bitmap(f) == 0); }
void testfs_put_inode_freemap(struct super_block *sb, int inode_nr) { assert(sb->inode_freemap); bitmap_unmark(sb->inode_freemap, inode_nr); testfs_write_inode_freemap(sb, inode_nr); assert(sb->sb.used_inode_count > 0); sb->sb.used_inode_count--; testfs_write_super_block(sb); }
static int DiskClear(u_int32_t flatloc) { assert(lock_do_i_hold(&vmlock)); assert((flatloc & 0xfffff000) == flatloc); u_int32_t bitmaploc; bitmaploc = flatloc/PAGE_SIZE; assert (bitmap_isset(diskmap, bitmaploc)); bitmap_unmark(diskmap, bitmaploc); return 0; }
void swap_dealloc( off_t offset ) { int ix; //the index is simply the offset divided by page size. ix = offset / PAGE_SIZE; //lock the swap. LOCK_SWAP(); //mark this index as unused. bitmap_unmark( bm_sw, ix ); //update stats. ++ss_sw.ss_free; //unlock the swap. UNLOCK_SWAP(); }
/* * swap_free: marks a page in the swapfile as unused. * * Synchronization: uses swaplock. */ void swap_free(off_t swapaddr) { uint32_t index; KASSERT(swapaddr != INVALID_SWAPADDR); KASSERT(swapaddr % PAGE_SIZE == 0); index = swapaddr / PAGE_SIZE; lock_acquire(swaplock); KASSERT(swap_free_pages < swap_total_pages); KASSERT(swap_reserved_pages <= swap_free_pages); KASSERT(bitmap_isset(swapmap, index)); bitmap_unmark(swapmap, index); swap_free_pages++; lock_release(swaplock); }
/* * Allocate a block. */ int sfs_balloc(struct sfs_fs *sfs, daddr_t *diskblock) { int result; result = bitmap_alloc(sfs->sfs_freemap, diskblock); if (result) { return result; } sfs->sfs_freemapdirty = true; if (*diskblock >= sfs->sfs_sb.sb_nblocks) { panic("sfs: balloc: invalid block %u\n", *diskblock); } /* Clear block before returning it */ result = sfs_clearblock(sfs, *diskblock); if (result) { bitmap_unmark(sfs->sfs_freemap, *diskblock); } return result; }
/* * Free a block. */ void sfs_bfree(struct sfs_fs *sfs, daddr_t diskblock) { bitmap_unmark(sfs->sfs_freemap, diskblock); sfs->sfs_freemapdirty = true; }
/* release allocated inode */ void testfs_put_inode_freemap(struct super_block *sb, int inode_nr) { assert(sb->inode_freemap); bitmap_unmark(sb->inode_freemap, inode_nr); testfs_write_inode_freemap(sb, inode_nr); }