From a8877df135c0395285945b11a75d57e10b7aecdf Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 14 Aug 2024 18:34:02 -0400 Subject: [PATCH] kernel/vm: Add "unmergeable" flag to VMCache. ramfs needs to create caches that are both temporary and unmergeable, so add another flag to make this state possible. Otherwise, mmap'ed files from ramfs might wind up in VMCache trying to merge the caches when the last one is closed, which we don't want. --- headers/private/kernel/vm/VMCache.h | 1 + src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp | 1 + src/system/kernel/vm/VMCache.cpp | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/headers/private/kernel/vm/VMCache.h b/headers/private/kernel/vm/VMCache.h index 8807079d0d..504f4f655f 100644 --- a/headers/private/kernel/vm/VMCache.h +++ b/headers/private/kernel/vm/VMCache.h @@ -198,6 +198,7 @@ public: // TODO: Remove! uint32 page_count; uint32 temporary : 1; + uint32 unmergeable : 1; uint32 type : 6; #if DEBUG_CACHE_LIST diff --git a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp index 491dd9dbfa..054deced6e 100644 --- a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp @@ -255,6 +255,7 @@ DataContainer::_SwitchToCacheMode() return error; fCache->temporary = 1; + fCache->unmergeable = 1; fCache->virtual_end = fSize; error = fCache->Commit(fSize, VM_PRIORITY_USER); diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp index 1e8a27b9d9..f04a2b90e2 100644 --- a/src/system/kernel/vm/VMCache.cpp +++ b/src/system/kernel/vm/VMCache.cpp @@ -627,8 +627,8 @@ VMCacheRef::VMCacheRef(VMCache* cache) bool VMCache::_IsMergeable() const { - return areas == NULL && temporary && !consumers.IsEmpty() - && consumers.Head() == consumers.Tail(); + return areas == NULL && temporary && !unmergeable + && !consumers.IsEmpty() && consumers.Head() == consumers.Tail(); } @@ -657,6 +657,7 @@ VMCache::Init(uint32 cacheType, uint32 allocationFlags) virtual_end = 0; committed_size = 0; temporary = 0; + unmergeable = 0; page_count = 0; fWiredPagesCount = 0; type = cacheType;