kernel/vm: Preparations for VMCache::committed_size removal.

Includes some cleanup to the organization of VMCache.h.
This commit is contained in:
Augustin Cavalier
2026-03-26 17:25:05 -04:00
parent 76af6f4c98
commit 0a5cd96093
5 changed files with 27 additions and 21 deletions
+13 -14
View File
@@ -99,6 +99,13 @@ public:
inline void ReleaseRef(); inline void ReleaseRef();
inline void ReleaseRefAndUnlock( inline void ReleaseRefAndUnlock(
bool consumerLocked = false); 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; } inline VMCacheRef* CacheRef() const { return fCacheRef; }
@@ -129,9 +136,6 @@ public:
void TakeAreasFrom(VMCache* fromCache); void TakeAreasFrom(VMCache* fromCache);
uint32 CountWritableAreas(VMArea* ignoreArea) const; 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 Resize(off_t newSize, int priority);
virtual status_t Rebase(off_t newBase, int priority); virtual status_t Rebase(off_t newBase, int priority);
virtual status_t Adopt(VMCache* source, off_t offset, off_t size, virtual status_t Adopt(VMCache* source, off_t offset, off_t size,
@@ -141,20 +145,14 @@ public:
status_t FlushAndRemoveAllPages(); status_t FlushAndRemoveAllPages();
void* UserData() { return fUserData; } status_t SetMinimalCommitment(off_t commitment,
void SetUserData(void* data) { fUserData = data; } int priority);
// Settable by the lock owner and valid as off_t Commitment() const;
// long as the lock is owned.
// for debugging only
int32 RefCount() const
{ return fRefCount; }
// backing store operations
virtual bool CanOvercommit(); virtual bool CanOvercommit();
virtual status_t Commit(off_t size, int priority); 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, virtual status_t Read(off_t offset, const generic_io_vec *vecs,
size_t count, uint32 flags, size_t count, uint32 flags,
generic_size_t *_numBytes); generic_size_t *_numBytes);
@@ -166,6 +164,7 @@ public:
generic_size_t numBytes, uint32 flags, generic_size_t numBytes, uint32 flags,
AsyncIOCallback* callback); AsyncIOCallback* callback);
virtual bool CanWritePage(off_t offset); virtual bool CanWritePage(off_t offset);
status_t WriteModified();
virtual int32 MaxPagesPerWrite() const virtual int32 MaxPagesPerWrite() const
{ return -1; } // no restriction { return -1; } // no restriction
@@ -256,7 +256,7 @@ off_t
DataContainer::GetCommittedSize() const DataContainer::GetCommittedSize() const
{ {
if (_IsCacheMode()) if (_IsCacheMode())
return sizeof(VMForVnodeCache) + fCache->committed_size; return sizeof(VMForVnodeCache) + fCache->Commitment();
else else
return fSmallBufferSize; return fSmallBufferSize;
} }
+9 -2
View File
@@ -148,7 +148,7 @@ class SetMinimalCommitment : public VMCacheTraceEntry {
SetMinimalCommitment(VMCache* cache, off_t commitment) SetMinimalCommitment(VMCache* cache, off_t commitment)
: :
VMCacheTraceEntry(cache), VMCacheTraceEntry(cache),
fOldCommitment(cache->committed_size), fOldCommitment(cache->Commitment()),
fCommitment(commitment) fCommitment(commitment)
{ {
Initialized(); 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 // If we don't have enough committed space to cover through to the new end
// of the area... // of the area...
if (committed_size < commitment) { if (Commitment() < commitment) {
#if KDEBUG #if KDEBUG
const off_t size = PAGE_ALIGN(virtual_end - virtual_base); const off_t size = PAGE_ALIGN(virtual_end - virtual_base);
ASSERT_PRINT(commitment <= size, "cache %p, commitment %" B_PRIdOFF ", size %" B_PRIdOFF, 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 bool
VMCache::CanOvercommit() VMCache::CanOvercommit()
{ {
+2 -2
View File
@@ -1175,7 +1175,7 @@ discard_area_range(VMArea* area, addr_t address, addr_t size)
cache->Discard(area->cache_offset + offset, size); cache->Discard(area->cache_offset + offset, size);
if (commitmentChange != 0) if (commitmentChange != 0)
cache->Commit(cache->committed_size + commitmentChange, VM_PRIORITY_USER); cache->Commit(cache->Commitment() + commitmentChange, VM_PRIORITY_USER);
cache->ReleaseRefAndUnlock(); cache->ReleaseRefAndUnlock();
return B_OK; return B_OK;
@@ -6567,7 +6567,7 @@ _user_set_memory_protection(void* _address, size_t size, uint32 protection)
} }
if (commitmentChange != 0) { 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; const ssize_t topCacheSize = topCache->virtual_end - topCache->virtual_base;
if (newCommitment > topCacheSize) { if (newCommitment > topCacheSize) {
// This should only happen in the case where this process fork()ed, // This should only happen in the case where this process fork()ed,
+2 -2
View File
@@ -278,7 +278,7 @@ update_cache_info_recursively(VMCache* cache, cache_info& info)
{ {
info.page_count += cache->page_count; info.page_count += cache->page_count;
if (cache->type == CACHE_TYPE_RAM) if (cache->type == CACHE_TYPE_RAM)
info.committed += cache->committed_size; info.committed += cache->Commitment();
// recurse // recurse
for (VMCache::ConsumerList::Iterator it = cache->consumers.GetIterator(); 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); kprintf("/%lu", info.page_count);
if (cache->type == CACHE_TYPE_RAM || (level == 0 && info.committed > 0)) { 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) if (level == 0)
kprintf("/%lu", info.committed); kprintf("/%lu", info.committed);