From a93ebbfb5b580b63509a081c67c0027ee4db28f6 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sat, 23 May 2026 17:40:40 +0200 Subject: [PATCH] Populate pool tracking table with common allocation tags --- xtoskrnl/includes/mm/alloc.hh | 1 + xtoskrnl/mm/alloc.cc | 61 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/xtoskrnl/includes/mm/alloc.hh b/xtoskrnl/includes/mm/alloc.hh index 6ce5c52..600ced7 100644 --- a/xtoskrnl/includes/mm/alloc.hh +++ b/xtoskrnl/includes/mm/alloc.hh @@ -64,6 +64,7 @@ namespace MM OUT PPFN_NUMBER PagesFreed); STATIC XTAPI XTSTATUS FreePagedPoolPages(IN PVOID VirtualAddress, OUT PPFN_NUMBER PagesFreed); + STATIC XTAPI VOID PopulateAllocationTags(VOID); STATIC XTAPI VOID RegisterAllocationTag(IN ULONG Tag, IN SIZE_T Bytes, IN MMPOOL_TYPE PoolType); diff --git a/xtoskrnl/mm/alloc.cc b/xtoskrnl/mm/alloc.cc index fb8ce6c..b6c6c6a 100644 --- a/xtoskrnl/mm/alloc.cc +++ b/xtoskrnl/mm/alloc.cc @@ -1382,6 +1382,9 @@ MM::Allocator::InitializeAllocationsTracking(VOID) /* Calculate and store the hash mask */ AllocationsTrackingTableMask = AllocationsTrackingTableSize - 2; + /* Populate the pool tracking table with the most frequently used allocation tags */ + PopulateAllocationTags(); + /* Initialize the spinlock used to synchronize concurrent modifications to the tracking table */ KE::SpinLock::InitializeSpinLock(&AllocationsTrackingTableLock); } @@ -1502,6 +1505,64 @@ MM::Allocator::InitializeBigAllocationsTracking(VOID) NonPagedPool); } +/** + * Populates the pool tracking table with the most frequently used allocation tags. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Allocator::PopulateAllocationTags(VOID) +{ + ULONG Hash, HashIndex, Index; + + CULONG HotTags[] = + { + SIGNATURE32('B', 'i', 'g', 'A'), /* Big Allocations */ + SIGNATURE32('M', 'M', 'g', 'r'), /* Memory Manager Internal */ + SIGNATURE32('N', 'o', 'n', 'e'), /* Untagged allocations */ + SIGNATURE32('O', 'v', 'f', 'l'), /* Global table expansion overflow fallback */ + }; + + /* Seed all tags */ + for(Index = 0; Index < ARRAY_SIZE(HotTags); Index++) + { + /* Compute the initial hash index */ + Hash = ComputeHash(HotTags[Index], AllocationsTrackingTableMask); + HashIndex = Hash; + + /* Probe the tracking table until an empty slot is found */ + while(TRUE) + { + /* Check if the tag is already present in the table */ + if(AllocationsTrackingTable[Hash].Tag == HotTags[Index]) + { + /* The tag has already been registered, skip it */ + break; + } + + /* Check if the slot is empty */ + if((AllocationsTrackingTable[Hash].Tag == 0) && (Hash != (AllocationsTrackingTableSize - 1))) + { + /* Claim the slot and break the loop */ + AllocationsTrackingTable[Hash].Tag = HotTags[Index]; + break; + } + + /* Advance to the next index on collision */ + Hash = (Hash + 1) & AllocationsTrackingTableMask; + + /* Check if the hash index has wrapped around */ + if(Hash == HashIndex) + { + break; + } + } + } +} + /** * Registers a pool memory allocation in the tracking table. *