From a0e707d35f49f34cef18316b795ff95e95e97dfb Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Sat, 4 Jul 2026 14:08:05 +0200 Subject: [PATCH] Implement buffer return logic for general lookaside lists --- xtoskrnl/ex/laslist.cc | 70 ++++++++++++++++++++++++++++++++- xtoskrnl/includes/ex/laslist.hh | 4 ++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/xtoskrnl/ex/laslist.cc b/xtoskrnl/ex/laslist.cc index 22ab895..fe793eb 100644 --- a/xtoskrnl/ex/laslist.cc +++ b/xtoskrnl/ex/laslist.cc @@ -79,7 +79,6 @@ EX::LookasideList::AllocateFromLookasideList(IN PPAGED_LOOKASIDE_LIST LookasideL return Buffer; } - /** * Allocates a memory block from the specified per-processor lookaside list. * @@ -138,6 +137,75 @@ EX::LookasideList::AllocateFromPerProcessorList(IN NONPAGED_LOOKASIDE_NUMBER Num return Entry; } +/** + * Returns a previously allocated memory block to the specified non-paged lookaside list. + * + * @param LookasideList + * Supplies a pointer to the non-paged lookaside list. + * + * @param Entry + * Supplies a pointer to the memory block being freed. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +EX::LookasideList::FreeToLookasideList(IN PNONPAGED_LOOKASIDE_LIST LookasideList, + IN PVOID Entry) +{ + /* Increment the tracking metric */ + LookasideList->Global.TotalFrees++; + + /* Verify if the lookaside list has reached its maximum capacity threshold */ + if(RTL::SinglyList::QueryListDepth(&LookasideList->Global.ListHead) >= LookasideList->Global.Depth) + { + /* The list is full, record a capacity miss */ + LookasideList->Global.FreeMisses++; + (LookasideList->Global.Free)(Entry); + } + else + { + /* Push the block onto the lookaside list */ + RTL::Atomic::PushEntrySingleList(&LookasideList->Global.ListHead, (PSINGLE_LIST_ENTRY)Entry); + } +} + +/** + * Returns a previously allocated memory block to the specified paged lookaside list. + * + * @param LookasideList + * Supplies a pointer to the paged lookaside list. + * + * @param Entry + * Supplies a pointer to the memory block being freed. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +EX::LookasideList::FreeToLookasideList(IN PPAGED_LOOKASIDE_LIST LookasideList, + IN PVOID Entry) +{ + /* Increment the tracking metric */ + LookasideList->Global.TotalFrees++; + + /* Verify if the lookaside list has reached its maximum capacity threshold */ + if(RTL::SinglyList::QueryListDepth(&LookasideList->Global.ListHead) >= LookasideList->Global.Depth) + { + /* The list is full, record a capacity miss */ + LookasideList->Global.FreeMisses++; + (LookasideList->Global.Free)(Entry); + } + else + { + /* Push the block onto the lookaside list */ + RTL::Atomic::PushEntrySingleList(&LookasideList->Global.ListHead, (PSINGLE_LIST_ENTRY)Entry); + } +} /** * Frees a memory block back to the specified per-processor lookaside list. diff --git a/xtoskrnl/includes/ex/laslist.hh b/xtoskrnl/includes/ex/laslist.hh index 6f424c6..98688e3 100644 --- a/xtoskrnl/includes/ex/laslist.hh +++ b/xtoskrnl/includes/ex/laslist.hh @@ -31,6 +31,10 @@ namespace EX STATIC XTAPI PVOID AllocateFromLookasideList(IN PNONPAGED_LOOKASIDE_LIST LookasideList); STATIC XTAPI PVOID AllocateFromLookasideList(IN PPAGED_LOOKASIDE_LIST LookasideList); STATIC XTAPI PVOID AllocateFromPerProcessorList(IN NONPAGED_LOOKASIDE_NUMBER Number); + STATIC XTAPI VOID FreeToLookasideList(IN PNONPAGED_LOOKASIDE_LIST LookasideList, + IN PVOID Entry); + STATIC XTAPI VOID FreeToLookasideList(IN PPAGED_LOOKASIDE_LIST LookasideList, + IN PVOID Entry); STATIC XTAPI VOID FreeToPerProcessorList(IN NONPAGED_LOOKASIDE_NUMBER Number, IN PVOID Entry); STATIC XTAPI VOID InitializeLookasideList(IN OUT PGENERAL_LOOKASIDE LookasideList,