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;
|
||||
AutoLocker<VMCache> _(cache);
|
||||
|
||||
off_t oldSize = cache->virtual_end;
|
||||
status_t status = cache->Resize(newSize, VM_PRIORITY_USER);
|
||||
// Note, the priority doesn't really matter, since this cache doesn't
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user