From 4eaa43ac48bb4936de09b85827893c9beb90b51c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 11 Oct 2008 07:30:44 +0000 Subject: [PATCH] * Added "flags" parameter to VMCache::Read(). * Use the new VMCache::Read() flags parameter to directly read into the physical page in the page fault handler instead of mapping it first. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27966 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/vm_types.h | 2 +- src/system/kernel/cache/vnode_store.cpp | 40 ++++++++++++++++--- src/system/kernel/cache/vnode_store.h | 2 +- src/system/kernel/vm/VMAnonymousCache.cpp | 4 +- src/system/kernel/vm/VMAnonymousCache.h | 2 +- .../kernel/vm/VMAnonymousNoSwapCache.cpp | 2 +- src/system/kernel/vm/VMAnonymousNoSwapCache.h | 2 +- src/system/kernel/vm/VMDeviceCache.cpp | 2 +- src/system/kernel/vm/VMDeviceCache.h | 2 +- src/system/kernel/vm/vm.cpp | 10 ++--- src/system/kernel/vm/vm_cache.cpp | 3 +- 11 files changed, 50 insertions(+), 21 deletions(-) diff --git a/headers/private/kernel/vm_types.h b/headers/private/kernel/vm_types.h index 8e6f963da8..4ab232e39f 100644 --- a/headers/private/kernel/vm_types.h +++ b/headers/private/kernel/vm_types.h @@ -213,7 +213,7 @@ public: virtual bool HasPage(off_t offset); virtual status_t Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes); + uint32 flags, size_t *_numBytes); virtual status_t Write(off_t offset, const iovec *vecs, size_t count, uint32 flags, size_t *_numBytes); virtual status_t WriteAsync(off_t offset, const iovec* vecs, diff --git a/src/system/kernel/cache/vnode_store.cpp b/src/system/kernel/cache/vnode_store.cpp index 43cd0bb926..1c3dfa880d 100644 --- a/src/system/kernel/cache/vnode_store.cpp +++ b/src/system/kernel/cache/vnode_store.cpp @@ -11,6 +11,33 @@ #include #include +#include + +#include "io_requests.h" + + +static inline status_t +memset_physical(addr_t address, int value, size_t length) +{ + while (length > 0) { + addr_t pageOffset = address % B_PAGE_SIZE; + addr_t virtualAddress; + status_t error = vm_get_physical_page(address - pageOffset, + &virtualAddress, 0); + if (error != B_OK) + return error; + + size_t toSet = min_c(length, B_PAGE_SIZE - pageOffset); + memset((void*)(virtualAddress + pageOffset), value, toSet); + + vm_put_physical_page(virtualAddress); + + length -= toSet; + address += toSet; + } + + return B_OK; +} status_t @@ -41,12 +68,12 @@ VMVnodeCache::HasPage(off_t offset) status_t VMVnodeCache::Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes) + uint32 flags, size_t *_numBytes) { size_t bytesUntouched = *_numBytes; status_t status = vfs_read_pages(fVnode, NULL, offset, vecs, count, - 0, _numBytes); + flags, _numBytes); bytesUntouched -= *_numBytes; @@ -61,9 +88,12 @@ VMVnodeCache::Read(off_t offset, const iovec *vecs, size_t count, for (int32 i = count; i-- > 0 && bytesUntouched != 0;) { size_t length = min_c(bytesUntouched, vecs[i].iov_len); - // ToDo: will have to map the pages in later (when we switch to physical pages) - memset((void *)((addr_t)vecs[i].iov_base + vecs[i].iov_len - length), - 0, length); + addr_t address = (addr_t)vecs[i].iov_base + vecs[i].iov_len - length; + if ((flags & B_PHYSICAL_IO_REQUEST) != 0) + memset_physical(address, 0, length); + else + memset((void*)address, 0, length); + bytesUntouched -= length; } diff --git a/src/system/kernel/cache/vnode_store.h b/src/system/kernel/cache/vnode_store.h index 4f1072c00f..3132d66212 100644 --- a/src/system/kernel/cache/vnode_store.h +++ b/src/system/kernel/cache/vnode_store.h @@ -20,7 +20,7 @@ public: virtual bool HasPage(off_t offset); virtual status_t Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes); + uint32 flags, size_t *_numBytes); virtual status_t Write(off_t offset, const iovec *vecs, size_t count, uint32 flags, size_t *_numBytes); virtual status_t WriteAsync(off_t offset, const iovec* vecs, diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp index 52df343d63..ba13dc35e0 100644 --- a/src/system/kernel/vm/VMAnonymousCache.cpp +++ b/src/system/kernel/vm/VMAnonymousCache.cpp @@ -496,7 +496,7 @@ VMAnonymousCache::HasPage(off_t offset) status_t VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes) + uint32 flags, size_t *_numBytes) { off_t pageIndex = offset >> PAGE_SHIFT; @@ -517,7 +517,7 @@ VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, * B_PAGE_SIZE; status_t status = vfs_read_pages(swapFile->vnode, swapFile->cookie, pos, - vecs + i, j - i, 0, _numBytes); + vecs + i, j - i, flags, _numBytes); if (status != B_OK) return status; } diff --git a/src/system/kernel/vm/VMAnonymousCache.h b/src/system/kernel/vm/VMAnonymousCache.h index 8d5c1ab002..2a1b58162a 100644 --- a/src/system/kernel/vm/VMAnonymousCache.h +++ b/src/system/kernel/vm/VMAnonymousCache.h @@ -39,7 +39,7 @@ public: virtual bool HasPage(off_t offset); virtual status_t Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes); + uint32 flags, size_t *_numBytes); virtual status_t Write(off_t offset, const iovec *vecs, size_t count, uint32 flags, size_t *_numBytes); virtual status_t WriteAsync(off_t offset, const iovec* vecs, diff --git a/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp b/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp index 6c22bafcec..b1f77b4bbb 100644 --- a/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp +++ b/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp @@ -96,7 +96,7 @@ VMAnonymousNoSwapCache::HasPage(off_t offset) status_t VMAnonymousNoSwapCache::Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes) + uint32 flags, size_t *_numBytes) { panic("anonymous_store: read called. Invalid!\n"); return B_ERROR; diff --git a/src/system/kernel/vm/VMAnonymousNoSwapCache.h b/src/system/kernel/vm/VMAnonymousNoSwapCache.h index e5faa32274..c6f59369f9 100644 --- a/src/system/kernel/vm/VMAnonymousNoSwapCache.h +++ b/src/system/kernel/vm/VMAnonymousNoSwapCache.h @@ -23,7 +23,7 @@ public: virtual bool HasPage(off_t offset); virtual status_t Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes); + uint32 flags, size_t *_numBytes); virtual status_t Write(off_t offset, const iovec *vecs, size_t count, uint32 flags, size_t *_numBytes); diff --git a/src/system/kernel/vm/VMDeviceCache.cpp b/src/system/kernel/vm/VMDeviceCache.cpp index ce753ddcbb..34b4116010 100644 --- a/src/system/kernel/vm/VMDeviceCache.cpp +++ b/src/system/kernel/vm/VMDeviceCache.cpp @@ -27,7 +27,7 @@ VMDeviceCache::HasPage(off_t offset) status_t VMDeviceCache::Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes) + uint32 flags, size_t *_numBytes) { panic("device_store: read called. Invalid!\n"); return B_ERROR; diff --git a/src/system/kernel/vm/VMDeviceCache.h b/src/system/kernel/vm/VMDeviceCache.h index 0947e7007b..636e2b1040 100644 --- a/src/system/kernel/vm/VMDeviceCache.h +++ b/src/system/kernel/vm/VMDeviceCache.h @@ -19,7 +19,7 @@ public: virtual bool HasPage(off_t offset); virtual status_t Read(off_t offset, const iovec *vecs, size_t count, - size_t *_numBytes); + uint32 flags, size_t *_numBytes); virtual status_t Write(off_t offset, const iovec *vecs, size_t count, uint32 flags, size_t *_numBytes); diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 6c11df27df..eb2b2aa47c 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -45,6 +45,7 @@ #include #include "VMAnonymousCache.h" +#include "io_requests.h" //#define TRACE_VM @@ -4438,15 +4439,12 @@ fault_find_page(vm_translation_map *map, vm_cache *topCache, // get a virtual address for the page iovec vec; - map->ops->get_physical_page( - page->physical_page_number * B_PAGE_SIZE, - (addr_t *)&vec.iov_base, PHYSICAL_PAGE_CAN_WAIT); + vec.iov_base = (void*)(page->physical_page_number * B_PAGE_SIZE); size_t bytesRead = vec.iov_len = B_PAGE_SIZE; // read it in - status_t status = cache->Read(cacheOffset, &vec, 1, &bytesRead); - - map->ops->put_physical_page((addr_t)vec.iov_base); + status_t status = cache->Read(cacheOffset, &vec, 1, + B_PHYSICAL_IO_REQUEST, &bytesRead); cache->Lock(); diff --git a/src/system/kernel/vm/vm_cache.cpp b/src/system/kernel/vm/vm_cache.cpp index a7195843b3..1b77566ce9 100644 --- a/src/system/kernel/vm/vm_cache.cpp +++ b/src/system/kernel/vm/vm_cache.cpp @@ -861,7 +861,8 @@ VMCache::HasPage(off_t offset) status_t -VMCache::Read(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes) +VMCache::Read(off_t offset, const iovec *vecs, size_t count, uint32 flags, + size_t *_numBytes) { return B_ERROR; }