Changeset 26250
- Timestamp:
- 07/04/08 12:35:50 (5 months ago)
- Location:
- haiku/branches/developer/bonefish/vm
- Files:
-
- 12 modified
-
headers/private/kernel/vm_types.h (modified) (3 diffs)
-
src/system/kernel/cache/file_cache.cpp (modified) (6 diffs)
-
src/system/kernel/cache/vnode_store.cpp (modified) (1 diff)
-
src/system/kernel/fs/vfs.cpp (modified) (1 diff)
-
src/system/kernel/vm/vm.cpp (modified) (16 diffs)
-
src/system/kernel/vm/vm_cache.cpp (modified) (13 diffs)
-
src/system/kernel/vm/vm_page.cpp (modified) (1 diff)
-
src/system/kernel/vm/vm_store_anonymous_noswap.cpp (modified) (3 diffs)
-
src/system/kernel/vm/vm_store_anonymous_noswap.h (modified) (1 diff)
-
src/system/kernel/vm/vm_store_device.cpp (modified) (1 diff)
-
src/system/kernel/vm/vm_store_null.cpp (modified) (1 diff)
-
src/system/kernel/vm/vm_store_null.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h
r26175 r26250 172 172 virtual ~VMCache(); 173 173 174 status_t Init(); 174 status_t Init(uint32 cacheType); 175 176 virtual void Delete(); 175 177 176 178 // backing store operations … … 184 186 185 187 virtual status_t Fault(struct vm_address_space *aspace, off_t offset); 188 189 virtual void MergeStore(VMCache* source); 186 190 187 191 virtual status_t AcquireUnreferencedStoreRef(); … … 199 203 VMCache *source; 200 204 off_t virtual_base; 201 off_t virtual_size; 202 // the size is absolute, and independent from virtual_base 205 off_t virtual_end; 203 206 off_t committed_size; 204 207 // TODO: Remove! -
haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp
r26175 r26250 374 374 + vecs[vecCount - 1].iov_len - B_PAGE_SIZE; 375 375 376 if (offset + pageOffset + bufferSize == ref->cache->virtual_ size) {376 if (offset + pageOffset + bufferSize == ref->cache->virtual_end) { 377 377 // the space in the page after this write action needs to be cleaned 378 378 memset((void *)(last + lastPageOffset), 0, … … 552 552 file_cache_ref *ref = (file_cache_ref *)_cacheRef; 553 553 vm_cache *cache = ref->cache; 554 off_t fileSize = cache->virtual_ size;554 off_t fileSize = cache->virtual_end; 555 555 bool useBuffer = buffer != 0; 556 556 … … 768 768 file_cache_ref *ref = (struct file_cache_ref *) 769 769 ((vnode_store *)cache->store)->file_cache_ref; 770 off_t fileSize = cache->virtual_ size;770 off_t fileSize = cache->virtual_end; 771 771 772 772 if (size > fileSize) … … 860 860 file_cache_ref *ref = ((VMVnodeCache*)cache)->FileCacheRef(); 861 861 if (ref != NULL) 862 size = cache->virtual_ size;862 size = cache->virtual_end; 863 863 } 864 864 … … 950 950 goto err1; 951 951 952 ref->cache->virtual_ size= size;952 ref->cache->virtual_end = size; 953 953 ((VMVnodeCache*)ref->cache)->SetFileCacheRef(ref); 954 954 return ref; … … 987 987 MutexLocker _(ref->cache->lock); 988 988 989 off_t offset = ref->cache->virtual_ size;989 off_t offset = ref->cache->virtual_end; 990 990 off_t size = newSize; 991 991 if (offset > newSize) { -
haiku/branches/developer/bonefish/vm/src/system/kernel/cache/vnode_store.cpp
r26175 r26250 17 17 VMVnodeCache::Init(struct vnode *vnode) 18 18 { 19 status_t error = VMCache::Init( );19 status_t error = VMCache::Init(CACHE_TYPE_VNODE); 20 20 if (error != B_OK) 21 21 return error; -
haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp
r26160 r26250 2795 2795 2796 2796 kprintf("%p%4ld%10Ld %p %8Ld%8ld\n", vnode, vnode->device, vnode->id, 2797 vnode->cache, (vnode->cache->virtual_ size+ B_PAGE_SIZE - 1)2797 vnode->cache, (vnode->cache->virtual_end + B_PAGE_SIZE - 1) 2798 2798 / B_PAGE_SIZE, vnode->cache->page_count); 2799 2799 } -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp
r26175 r26250 1395 1395 1396 1396 mutex_lock(&newCache->lock); 1397 newCache->type = CACHE_TYPE_RAM;1398 1397 newCache->temporary = 1; 1399 1398 newCache->scan_skip = cache->scan_skip; 1400 1399 newCache->virtual_base = offset; 1401 newCache->virtual_ size= offset + size;1400 newCache->virtual_end = offset + size; 1402 1401 1403 1402 vm_cache_add_consumer_locked(cache, newCache); … … 1406 1405 } 1407 1406 1408 status = vm_cache_set_minimal_commitment_locked(cache, offset +size);1407 status = vm_cache_set_minimal_commitment_locked(cache, size); 1409 1408 if (status != B_OK) 1410 1409 goto err2; … … 1629 1628 1630 1629 cache->temporary = 1; 1631 cache->type = CACHE_TYPE_RAM; 1632 cache->virtual_size = size; 1630 cache->virtual_end = size; 1633 1631 1634 1632 switch (wiring) { … … 1845 1843 // tell the page scanner to skip over this area, it's pages are special 1846 1844 cache->scan_skip = 1; 1847 cache->type = CACHE_TYPE_DEVICE; 1848 cache->virtual_size = size; 1845 cache->virtual_end = size; 1849 1846 1850 1847 mutex_lock(&cache->lock); … … 1919 1916 // tell the page scanner to skip over this area, no pages will be mapped here 1920 1917 cache->scan_skip = 1; 1921 cache->type = CACHE_TYPE_NULL; 1922 cache->virtual_size = size; 1918 cache->virtual_end = size; 1923 1919 1924 1920 mutex_lock(&cache->lock); … … 1944 1940 */ 1945 1941 status_t 1946 vm_create_vnode_cache(struct vnode *vnode, struct VMCache **_cache) 1947 { 1948 // create a vnode cache 1949 vm_cache* cache; 1950 status_t status = VMCacheFactory::CreateVnodeCache(cache, vnode); 1951 if (status != B_OK) 1952 return status; 1953 1954 cache->type = CACHE_TYPE_VNODE; 1955 1956 *_cache = cache; 1957 return B_OK; 1942 vm_create_vnode_cache(struct vnode *vnode, struct VMCache **cache) 1943 { 1944 return VMCacheFactory::CreateVnodeCache(*cache, vnode); 1958 1945 } 1959 1946 … … 2300 2287 mutex_lock(&upperCache->lock); 2301 2288 2302 upperCache->type = CACHE_TYPE_RAM;2303 2289 upperCache->temporary = 1; 2304 2290 upperCache->scan_skip = lowerCache->scan_skip; 2305 2291 upperCache->virtual_base = lowerCache->virtual_base; 2306 upperCache->virtual_ size = lowerCache->virtual_size;2292 upperCache->virtual_end = lowerCache->virtual_end; 2307 2293 2308 2294 // transfer the lower cache areas to the upper cache … … 2475 2461 // into account that really are in this cache. 2476 2462 2477 status = cache->Commit( 2478 cache->virtual_base + cache->page_count * B_PAGE_SIZE); 2463 status = cache->Commit(cache->page_count * B_PAGE_SIZE); 2479 2464 2480 2465 // ToDo: we may be able to join with our source cache, if count == 0 … … 2494 2479 if (cache->source != NULL && cache->temporary) { 2495 2480 // the cache's commitment must contain all possible pages 2496 status = cache->Commit(cache->virtual_size); 2481 status = cache->Commit(cache->virtual_end 2482 - cache->virtual_base); 2497 2483 } 2498 2484 … … 3110 3096 kprintf("%p: type: %s, base: %lld, size: %lld, pages: %lu", cache, 3111 3097 cache_type_to_string(cache->type), cache->virtual_base, 3112 cache->virtual_ size, cache->page_count);3098 cache->virtual_end, cache->page_count); 3113 3099 3114 3100 if (level == 0) … … 3239 3225 kprintf(" type: %s\n", cache_type_to_string(cache->type)); 3240 3226 kprintf(" virtual_base: 0x%Lx\n", cache->virtual_base); 3241 kprintf(" virtual_ size: 0x%Lx\n", cache->virtual_size);3227 kprintf(" virtual_end: 0x%Lx\n", cache->virtual_end); 3242 3228 kprintf(" temporary: %ld\n", cache->temporary); 3243 3229 kprintf(" scan_skip: %ld\n", cache->scan_skip); … … 4833 4819 for (vm_area* current = cache->areas; current != NULL; 4834 4820 current = current->cache_next) { 4835 if (current->address_space_next 4836 && current->address_space_next->base <= (current->base 4837 + newSize)) { 4821 vm_area *next = current->address_space_next; 4822 if (next != NULL && next->base <= (current->base + newSize)) { 4838 4823 // If the area was created inside a reserved area, it can 4839 4824 // also be resized in that area 4840 4825 // ToDo: if there is free space after the reserved area, it could be used as well... 4841 vm_area *next = current->address_space_next;4842 4826 if (next->id == RESERVED_AREA_ID 4843 4827 && next->cache_offset <= current->base … … 4852 4836 // Okay, looks good so far, so let's do it 4853 4837 4838 if (oldSize < newSize) { 4839 // Growing the cache can fail, so we do it first. 4840 status = vm_cache_resize(cache, newSize); 4841 if (status != B_OK) 4842 return status; 4843 } 4844 4854 4845 for (vm_area* current = cache->areas; current != NULL; 4855 4846 current = current->cache_next) { 4856 if (current->address_space_next 4857 && current->address_space_next->base <= (current->base + newSize)) { 4858 vm_area *next = current->address_space_next; 4847 vm_area *next = current->address_space_next; 4848 if (next != NULL && next->base <= (current->base + newSize)) { 4859 4849 if (next->id == RESERVED_AREA_ID 4860 4850 && next->cache_offset <= current->base … … 4870 4860 } 4871 4861 } else { 4862 panic("resize situation for area %p has changed although we " 4863 "should have the address space lock", current); 4872 4864 status = B_ERROR; 4873 4865 break; … … 4884 4876 } 4885 4877 4886 if (status == B_OK) 4878 // shrinking the cache can't fail, so we do it now 4879 if (status == B_OK && newSize < oldSize) 4887 4880 status = vm_cache_resize(cache, newSize); 4888 4881 … … 4893 4886 current->size = oldSize; 4894 4887 } 4888 4889 vm_cache_resize(cache, oldSize); 4895 4890 } 4896 4891 -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp
r26175 r26250 127 127 : 128 128 VMCacheTraceEntry(cache), 129 fOldSize(cache->virtual_ size),129 fOldSize(cache->virtual_end), 130 130 fSize(size) 131 131 { … … 437 437 } 438 438 439 // merge the backing store 440 consumer->MergeStore(cache); 441 439 442 // The remaining consumer has got a new source. 440 443 if (cache->source != NULL) { … … 536 539 // delete this cache 537 540 538 delete cache;541 cache->Delete(); 539 542 } 540 543 … … 685 688 { 686 689 TRACE(("vm_cache_resize(cache %p, newSize %Ld) old size %Ld\n", 687 cache, newSize, cache->virtual_ size));690 cache, newSize, cache->virtual_end)); 688 691 ASSERT_LOCKED_MUTEX(&cache->lock); 689 692 690 693 T(Resize(cache, newSize)); 691 694 692 status_t status = cache->Commit(newSize );695 status_t status = cache->Commit(newSize - cache->virtual_base); 693 696 if (status != B_OK) 694 697 return status; 695 698 696 uint32 oldPageCount = (uint32)((cache->virtual_ size+ B_PAGE_SIZE - 1)699 uint32 oldPageCount = (uint32)((cache->virtual_end + B_PAGE_SIZE - 1) 697 700 >> PAGE_SHIFT); 698 701 uint32 newPageCount = (uint32)((newSize + B_PAGE_SIZE - 1) >> PAGE_SHIFT); … … 732 735 } 733 736 734 cache->virtual_ size= newSize;737 cache->virtual_end = newSize; 735 738 return B_OK; 736 739 } … … 848 851 849 852 VMCache::~VMCache() 853 { 854 mutex_destroy(&lock); 855 } 856 857 858 status_t 859 VMCache::Init(uint32 cacheType) 860 { 861 mutex_init(&lock, "vm_cache"); 862 list_init_etc(&consumers, offsetof(VMCache, consumer_link)); 863 areas = NULL; 864 ref_count = 1; 865 source = NULL; 866 virtual_base = 0; 867 virtual_end = 0; 868 committed_size = 0; 869 temporary = 0; 870 scan_skip = 0; 871 page_count = 0; 872 busy = false; 873 type = cacheType; 874 875 #if DEBUG_CACHE_LIST 876 mutex_lock(&sCacheListLock); 877 878 if (gDebugCacheList) 879 gDebugCacheList->debug_previous = this; 880 debug_previous = NULL; 881 debug_next = gDebugCacheList; 882 gDebugCacheList = this; 883 884 mutex_unlock(&sCacheListLock); 885 #endif 886 887 return B_OK; 888 } 889 890 891 void 892 VMCache::Delete() 850 893 { 851 894 if (areas != NULL) … … 893 936 mutex_unlock(&sCacheListLock); 894 937 895 mutex_destroy(&lock); 896 } 897 898 899 status_t 900 VMCache::Init() 901 { 902 mutex_init(&lock, "vm_cache"); 903 list_init_etc(&consumers, offsetof(VMCache, consumer_link)); 904 areas = NULL; 905 ref_count = 1; 906 source = NULL; 907 virtual_base = 0; 908 virtual_size = 0; 909 committed_size = 0; 910 temporary = 0; 911 scan_skip = 0; 912 page_count = 0; 913 busy = false; 914 915 #if DEBUG_CACHE_LIST 916 mutex_lock(&sCacheListLock); 917 918 if (gDebugCacheList) 919 gDebugCacheList->debug_previous = this; 920 debug_previous = NULL; 921 debug_next = gDebugCacheList; 922 gDebugCacheList = this; 923 924 mutex_unlock(&sCacheListLock); 925 #endif 926 927 return B_OK; 938 delete this; 928 939 } 929 940 … … 940 951 VMCache::HasPage(off_t offset) 941 952 { 942 return offset >= virtual_base && offset <= virtual_ size;953 return offset >= virtual_base && offset <= virtual_end; 943 954 } 944 955 … … 964 975 { 965 976 return B_BAD_ADDRESS; 977 } 978 979 980 void 981 VMCache::MergeStore(VMCache* source) 982 { 966 983 } 967 984 … … 1009 1026 numGuardPages); 1010 1027 if (error != B_OK) { 1011 delete cache;1028 cache->Delete(); 1012 1029 return error; 1013 1030 } … … 1027 1044 status_t error = cache->Init(vnode); 1028 1045 if (error != B_OK) { 1029 delete cache;1046 cache->Delete(); 1030 1047 return error; 1031 1048 } … … 1045 1062 status_t error = cache->Init(baseAddress); 1046 1063 if (error != B_OK) { 1047 delete cache;1064 cache->Delete(); 1048 1065 return error; 1049 1066 } … … 1063 1080 status_t error = cache->Init(); 1064 1081 if (error != B_OK) { 1065 delete cache;1082 cache->Delete(); 1066 1083 return error; 1067 1084 } -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp
r26175 r26250 1398 1398 { 1399 1399 return vm_page_write_modified_page_range(cache, 0, 1400 (cache->virtual_ size+ B_PAGE_SIZE - 1) >> PAGE_SHIFT, fsReenter);1400 (cache->virtual_end + B_PAGE_SIZE - 1) >> PAGE_SHIFT, fsReenter); 1401 1401 } 1402 1402 -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp
r26175 r26250 44 44 "at %p\n", canOvercommit ? "yes" : "no", numGuardPages, store)); 45 45 46 status_t error = VMCache::Init( );46 status_t error = VMCache::Init(CACHE_TYPE_RAM); 47 47 if (error != B_OK) 48 48 return error; … … 60 60 VMAnonymousCache::Commit(off_t size) 61 61 { 62 size -= virtual_base;63 // anonymous stores don't need to span over their whole source64 65 62 // if we can overcommit, we don't commit here, but in anonymous_fault() 66 63 if (fCanOvercommit) { … … 151 148 return B_BAD_HANDLER; 152 149 } 150 151 152 void 153 VMAnonymousCache::MergeStore(VMCache* source) 154 { 155 if (source->type != CACHE_TYPE_RAM) { 156 panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache " 157 "requested", source); 158 return; 159 } 160 161 // take over the source' committed size 162 committed_size += source->committed_size; 163 source->committed_size = 0; 164 165 off_t actualSize = virtual_end - virtual_base; 166 if (committed_size > actualSize) { 167 vm_unreserve_memory(committed_size - actualSize); 168 committed_size = actualSize; 169 } 170 } -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h
r26175 r26250 30 30 virtual status_t Fault(struct vm_address_space *aspace, off_t offset); 31 31 32 virtual void MergeStore(VMCache* source); 33 32 34 private: 33 35 bool fCanOvercommit; -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp
r26175 r26250 14 14 { 15 15 fBaseAddress = baseAddress; 16 return VMCache::Init( );16 return VMCache::Init(CACHE_TYPE_DEVICE); 17 17 } 18 18 -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp
r26175 r26250 6 6 #include "vm_store_null.h" 7 7 8 // TODO: Remove! 8 9 status_t 10 VMNullCache::Init() 11 { 12 return VMCache::Init(CACHE_TYPE_NULL); 13 } -
haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h
r26175 r26250 14 14 15 15<
