diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 5b58028f0d..52ea30fc7c 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -546,6 +546,7 @@ map_backing_store(vm_address_space *addressSpace, vm_cache_ref *cacheRef, } newCacheRef = newCache->ref; + newCache->type = CACHE_TYPE_RAM; newCache->temporary = 1; newCache->scan_skip = cache->scan_skip; @@ -1474,8 +1475,8 @@ _vm_put_area(vm_area *area, bool aspaceLocked) vm_address_space *addressSpace; bool removeit = false; - //TRACE(("_vm_put_area(area = %p, aspaceLocked = %s)\n", - // area, aspaceLocked ? "yes" : "no")); + TRACE(("_vm_put_area(area = %p, aspaceLocked = %s)\n", + area, aspaceLocked ? "yes" : "no")); // we should never get here, but if we do, we can handle it if (area->id == RESERVED_AREA_ID) @@ -3514,6 +3515,7 @@ vm_soft_fault(addr_t originalAddress, bool isWrite, bool isUser) dummyPage.cache = NULL; dummyPage.state = PAGE_STATE_INACTIVE; dummyPage.type = PAGE_TYPE_DUMMY; + dummyPage.wired_count = 0; vm_cache_ref *pageSourceRef; vm_page *page = fault_get_page(map, topCacheRef, cacheOffset, isWrite, diff --git a/src/system/kernel/vm/vm_cache.c b/src/system/kernel/vm/vm_cache.c index f2d4597542..eaf88bb877 100644 --- a/src/system/kernel/vm/vm_cache.c +++ b/src/system/kernel/vm/vm_cache.c @@ -182,6 +182,10 @@ vm_cache_release_ref(vm_cache_ref *cacheRef) #if 0 { // count min references to see if everything is okay + struct stack_frame { + struct stack_frame* previous; + void* return_address; + }; int32 min = 0; vm_area *a; vm_cache *c; @@ -194,8 +198,9 @@ vm_cache_release_ref(vm_cache_ref *cacheRef) min++; for (c = NULL; (c = list_get_next_item(&cacheRef->cache->consumers, c)) != NULL; ) min++; -dprintf("! %ld release cache_ref %p, ref_count is now %ld (min %ld, called from %p)\n", find_thread(NULL), cacheRef, cacheRef->ref_count, - min, ((struct stack_frame *)x86_read_ebp())->return_address); + dprintf("! %ld release cache_ref %p, ref_count is now %ld (min %ld, called from %p)\n", + find_thread(NULL), cacheRef, cacheRef->ref_count, + min, ((struct stack_frame *)x86_read_ebp())->return_address); if (cacheRef->ref_count < min) panic("cache_ref %p has too little ref_count!!!!", cacheRef); if (locked) @@ -223,6 +228,11 @@ dprintf("! %ld release cache_ref %p, ref_count is now %ld (min %ld, called from page = page->cache_next; + if (oldPage->mappings != NULL || oldPage->wired_count != 0) { + panic("remove page %p from cache %p: page still has mappings!\n", + oldPage, cacheRef->cache); + } + // remove it from the hash table state = disable_interrupts(); acquire_spinlock(&sPageCacheTableLock); @@ -526,10 +536,8 @@ vm_cache_remove_consumer(vm_cache_ref *cacheRef, vm_cache *consumer) vm_cache_remove_page(cacheRef, page); vm_cache_insert_page(consumerRef, page, (off_t)page->cache_offset << PAGE_SHIFT); - } - - // TODO: if we'd remove the pages in the cache, we'd also - // need to remove all of their mappings! + } else if (page->mappings != 0 || page->wired_count != 0) + panic("page %p has still mappings!", page); } newSource = cache->source; diff --git a/src/system/kernel/vm/vm_page.c b/src/system/kernel/vm/vm_page.c index cca66ac023..fc47d6cf10 100644 --- a/src/system/kernel/vm/vm_page.c +++ b/src/system/kernel/vm/vm_page.c @@ -185,7 +185,6 @@ dump_page(int argc, char **argv) kprintf("cache: %p\n", page->cache); kprintf("cache_offset: %ld\n", page->cache_offset); kprintf("cache_next,prev: %p, %p\n", page->cache_next, page->cache_prev); - kprintf("mappings: %p\n", page->mappings); kprintf("type: %d\n", page->type); kprintf("state: %d\n", page->state); kprintf("wired_count: %u\n", page->wired_count); @@ -194,7 +193,7 @@ dump_page(int argc, char **argv) mapping = page->mappings; while (mapping != NULL) { - kprintf(" %p\n", mapping->area); + kprintf(" %p (%#lx)\n", mapping->area, mapping->area->id); mapping = mapping->page_link.next; }