From 0a5cd960930e908dd151efbe65581b686b567c8b Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Thu, 26 Mar 2026 16:52:44 -0400 Subject: [PATCH] kernel/vm: Preparations for VMCache::committed_size removal. Includes some cleanup to the organization of VMCache.h. --- headers/private/kernel/vm/VMCache.h | 27 +++++++++---------- .../file_systems/ramfs/DataContainer.cpp | 2 +- src/system/kernel/vm/VMCache.cpp | 11 ++++++-- src/system/kernel/vm/vm.cpp | 4 +-- src/system/kernel/vm/vm_debug.cpp | 4 +-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/headers/private/kernel/vm/VMCache.h b/headers/private/kernel/vm/VMCache.h index d3aa2a9e12..bc49972f56 100644 --- a/headers/private/kernel/vm/VMCache.h +++ b/headers/private/kernel/vm/VMCache.h @@ -99,6 +99,13 @@ public: inline void ReleaseRef(); inline void ReleaseRefAndUnlock( bool consumerLocked = false); + int32 RefCount() const + { return fRefCount; } + + void* UserData() { return fUserData; } + void SetUserData(void* data) { fUserData = data; } + // Settable by the lock owner and valid as + // long as the lock is owned. inline VMCacheRef* CacheRef() const { return fCacheRef; } @@ -129,9 +136,6 @@ public: void TakeAreasFrom(VMCache* fromCache); uint32 CountWritableAreas(VMArea* ignoreArea) const; - status_t WriteModified(); - status_t SetMinimalCommitment(off_t commitment, - int priority); virtual status_t Resize(off_t newSize, int priority); virtual status_t Rebase(off_t newBase, int priority); virtual status_t Adopt(VMCache* source, off_t offset, off_t size, @@ -141,20 +145,14 @@ public: status_t FlushAndRemoveAllPages(); - void* UserData() { return fUserData; } - void SetUserData(void* data) { fUserData = data; } - // Settable by the lock owner and valid as - // long as the lock is owned. - - // for debugging only - int32 RefCount() const - { return fRefCount; } - - // backing store operations + status_t SetMinimalCommitment(off_t commitment, + int priority); + off_t Commitment() const; virtual bool CanOvercommit(); virtual status_t Commit(off_t size, int priority); - virtual bool StoreHasPage(off_t offset); + // backing store operations + virtual bool StoreHasPage(off_t offset); virtual status_t Read(off_t offset, const generic_io_vec *vecs, size_t count, uint32 flags, generic_size_t *_numBytes); @@ -166,6 +164,7 @@ public: generic_size_t numBytes, uint32 flags, AsyncIOCallback* callback); virtual bool CanWritePage(off_t offset); + status_t WriteModified(); virtual int32 MaxPagesPerWrite() const { return -1; } // no restriction diff --git a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp index 583302e386..79753a9929 100644 --- a/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp +++ b/src/add-ons/kernel/file_systems/ramfs/DataContainer.cpp @@ -256,7 +256,7 @@ off_t DataContainer::GetCommittedSize() const { if (_IsCacheMode()) - return sizeof(VMForVnodeCache) + fCache->committed_size; + return sizeof(VMForVnodeCache) + fCache->Commitment(); else return fSmallBufferSize; } diff --git a/src/system/kernel/vm/VMCache.cpp b/src/system/kernel/vm/VMCache.cpp index 459b771186..34efb75acc 100644 --- a/src/system/kernel/vm/VMCache.cpp +++ b/src/system/kernel/vm/VMCache.cpp @@ -148,7 +148,7 @@ class SetMinimalCommitment : public VMCacheTraceEntry { SetMinimalCommitment(VMCache* cache, off_t commitment) : VMCacheTraceEntry(cache), - fOldCommitment(cache->committed_size), + fOldCommitment(cache->Commitment()), fCommitment(commitment) { Initialized(); @@ -1080,7 +1080,7 @@ VMCache::SetMinimalCommitment(off_t commitment, int priority) // If we don't have enough committed space to cover through to the new end // of the area... - if (committed_size < commitment) { + if (Commitment() < commitment) { #if KDEBUG const off_t size = PAGE_ALIGN(virtual_end - virtual_base); ASSERT_PRINT(commitment <= size, "cache %p, commitment %" B_PRIdOFF ", size %" B_PRIdOFF, @@ -1307,6 +1307,13 @@ VMCache::FlushAndRemoveAllPages() } +off_t +VMCache::Commitment() const +{ + return committed_size; +} + + bool VMCache::CanOvercommit() { diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 52d0c2418c..cda017e688 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -1175,7 +1175,7 @@ discard_area_range(VMArea* area, addr_t address, addr_t size) cache->Discard(area->cache_offset + offset, size); if (commitmentChange != 0) - cache->Commit(cache->committed_size + commitmentChange, VM_PRIORITY_USER); + cache->Commit(cache->Commitment() + commitmentChange, VM_PRIORITY_USER); cache->ReleaseRefAndUnlock(); return B_OK; @@ -6567,7 +6567,7 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection) } if (commitmentChange != 0) { - off_t newCommitment = topCache->committed_size + commitmentChange; + off_t newCommitment = topCache->Commitment() + commitmentChange; const ssize_t topCacheSize = topCache->virtual_end - topCache->virtual_base; if (newCommitment > topCacheSize) { // This should only happen in the case where this process fork()ed, diff --git a/src/system/kernel/vm/vm_debug.cpp b/src/system/kernel/vm/vm_debug.cpp index a038bec6b8..114f37b2fc 100644 --- a/src/system/kernel/vm/vm_debug.cpp +++ b/src/system/kernel/vm/vm_debug.cpp @@ -278,7 +278,7 @@ update_cache_info_recursively(VMCache* cache, cache_info& info) { info.page_count += cache->page_count; if (cache->type == CACHE_TYPE_RAM) - info.committed += cache->committed_size; + info.committed += cache->Commitment(); // recurse for (VMCache::ConsumerList::Iterator it = cache->consumers.GetIterator(); @@ -324,7 +324,7 @@ dump_caches_recursively(VMCache* cache, cache_info& info, int level) kprintf("/%lu", info.page_count); if (cache->type == CACHE_TYPE_RAM || (level == 0 && info.committed > 0)) { - kprintf(", committed: %" B_PRIdOFF, cache->committed_size); + kprintf(", committed: %" B_PRIdOFF, cache->Commitment()); if (level == 0) kprintf("/%lu", info.committed);