kernel/vm: when resizing down a VMCache, fill a partial page with zeros
* factored out file_cache * fix two gVisor tests: MMapFileTest.ReadSharedTruncatePartialPage and MMapFileTest.WriteSharedTruncatePartialPage * fix #19438 Change-Id: Ia7f119478d306ab6d867632e4a5270733f0b29df Reviewed-on: https://review.haiku-os.org/c/haiku/+/9060 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
30c9648a4f
commit
91880bad83
-14
@@ -1276,23 +1276,9 @@ file_cache_set_size(void* _cacheRef, off_t newSize)
|
|||||||
VMCache* cache = ref->cache;
|
VMCache* cache = ref->cache;
|
||||||
AutoLocker<VMCache> _(cache);
|
AutoLocker<VMCache> _(cache);
|
||||||
|
|
||||||
off_t oldSize = cache->virtual_end;
|
|
||||||
status_t status = cache->Resize(newSize, VM_PRIORITY_USER);
|
status_t status = cache->Resize(newSize, VM_PRIORITY_USER);
|
||||||
// Note, the priority doesn't really matter, since this cache doesn't
|
// Note, the priority doesn't really matter, since this cache doesn't
|
||||||
// reserve any memory.
|
// reserve any memory.
|
||||||
if (status == B_OK && newSize < oldSize) {
|
|
||||||
// We may have a new partial page at the end of the cache that must be
|
|
||||||
// cleared.
|
|
||||||
uint32 partialBytes = newSize % B_PAGE_SIZE;
|
|
||||||
if (partialBytes != 0) {
|
|
||||||
vm_page* page = cache->LookupPage(newSize - partialBytes);
|
|
||||||
if (page != NULL) {
|
|
||||||
vm_memset_physical(page->physical_page_number * B_PAGE_SIZE
|
|
||||||
+ partialBytes, 0, B_PAGE_SIZE - partialBytes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1172,6 +1172,17 @@ VMCache::Resize(off_t newSize, int priority)
|
|||||||
while (_FreePageRange(pages.GetIterator(newPageCount, true, true)))
|
while (_FreePageRange(pages.GetIterator(newPageCount, true, true)))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
if (newSize < virtual_end && newPageCount > 0) {
|
||||||
|
// We may have a partial page at the end of the cache that must be cleared.
|
||||||
|
uint32 partialBytes = newSize % B_PAGE_SIZE;
|
||||||
|
if (partialBytes != 0) {
|
||||||
|
vm_page* page = LookupPage(newSize - partialBytes);
|
||||||
|
if (page != NULL) {
|
||||||
|
vm_memset_physical(page->physical_page_number * B_PAGE_SIZE
|
||||||
|
+ partialBytes, 0, B_PAGE_SIZE - partialBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (priority >= 0) {
|
if (priority >= 0) {
|
||||||
status_t status = Commit(PAGE_ALIGN(newSize - virtual_base), priority);
|
status_t status = Commit(PAGE_ALIGN(newSize - virtual_base), priority);
|
||||||
|
|||||||
Reference in New Issue
Block a user