kernel/vm: Track fault and copy counts in VMCache.

This solves a TODO for reporting CoW counts in area_info, and paves
the way for adaptive handling of pre-faulting based on how many
faults a cache has handled.

Change-Id: I4ecd7cf46b794c51acac87184fef49ea5ce76743
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8873
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2025-01-28 14:32:06 -05:00 committed by waddlesplash
parent b2b3e71456
commit 17c3890ce1
3 changed files with 24 additions and 5 deletions

View File

@ -174,6 +174,16 @@ public:
virtual status_t Fault(struct VMAddressSpace *aspace,
off_t offset);
inline uint64 FaultCount() const
{ return fFaultCount; }
inline void IncrementFaultCount()
{ fFaultCount++; }
inline uint64 CopiedPagesCount() const
{ return fCopiedPagesCount; }
inline void IncrementCopiedPagesCount()
{ fCopiedPagesCount++; }
virtual void Merge(VMCache* source);
virtual status_t AcquireUnreferencedStoreRef();
@ -228,7 +238,10 @@ private:
PageEventWaiter* fPageEventWaiters;
void* fUserData;
VMCacheRef* fCacheRef;
page_num_t fWiredPagesCount;
uint64 fFaultCount;
uint64 fCopiedPagesCount;
};

View File

@ -642,6 +642,8 @@ VMCache::Init(uint32 cacheType, uint32 allocationFlags)
temporary = 0;
page_count = 0;
fWiredPagesCount = 0;
fFaultCount = 0;
fCopiedPagesCount = 0;
type = cacheType;
fPageEventWaiters = NULL;

View File

@ -4405,6 +4405,7 @@ fault_get_page(PageFaultContext& context)
context.cacheChainLocker.RelockCaches(true);
sourcePage->Cache()->MarkPageUnbusy(sourcePage);
sourcePage->Cache()->IncrementCopiedPagesCount();
// insert the new page into our cache
context.topCache->InsertPage(page, context.cacheOffset);
@ -4666,8 +4667,9 @@ vm_soft_fault(VMAddressSpace* addressSpace, addr_t originalAddress,
*wirePage = context.page;
}
DEBUG_PAGE_ACCESS_END(context.page);
context.page->Cache()->IncrementFaultCount();
DEBUG_PAGE_ACCESS_END(context.page);
break;
}
@ -4920,16 +4922,18 @@ fill_area_info(struct VMArea* area, area_info* info, size_t size)
info->protection = area->protection;
info->lock = area->wiring;
info->team = area->address_space->ID();
info->copy_count = 0;
info->in_count = 0;
info->out_count = 0;
// TODO: retrieve real values here!
VMCache* cache = vm_area_get_locked_cache(area);
// Note, this is a simplification; the cache could be larger than this area
info->ram_size = cache->page_count * B_PAGE_SIZE;
info->copy_count = cache->CopiedPagesCount();
info->in_count = 0;
info->out_count = 0;
// TODO: retrieve real values here!
vm_area_put_locked_cache(cache);
}