https://git.reactos.org/?p=reactos.git;a=commitdiff;h=13cbc7fbf9197dd787259d32c679049f243c13c8

commit 13cbc7fbf9197dd787259d32c679049f243c13c8
Author:     George Bișoc <[email protected]>
AuthorDate: Thu Dec 30 20:57:14 2021 +0100
Commit:     George Bișoc <[email protected]>
CommitDate: Tue Jan 11 10:11:08 2022 +0100

    [NTOS:MM] Add the pool quota prototypes and some definitions
    
    Declare the MmRaisePoolQuota and MmReturnPoolQuota prototypes in the header 
and add some definitions related to pool quotas, namely 
MmTotalNonPagedPoolQuota and MmTotalPagedPoolQuota. These variables are used 
internally by the kernel as sort of "containers" (for the lack of a better term)
    which uphold the amount of quotas that the Process Manager is requesting 
the Memory Manager to raise or return the pool quota limit. In addition to 
that, add some definitions needed for both of these functions.
    
    The definitions, MI_CHARGE_PAGED_POOL_QUOTA and 
MI_CHARGE_NON_PAGED_POOL_QUOTA respectively, bear some interesting aspect. 
Seemingly the 0x80000 and 0x10000 values (that would denote to 524288 and 65536 
specifically) are used as quota "limits" or in other words, thresholds that the 
kernel
    uses. So for example if one would want to raise the quota limit charge, 
MmRaisePoolQuota will raise it so based on this formula -- NewMaxQuota = 
CurrentQuota + LIMIT_VALUE. LIMIT_VALUE can be either 
MI_CHARGE_PAGED_POOL_QUOTA or MI_CHARGE_NON_PAGED_POOL_QUOTA, depending a per 
quota pool basis.
    
    What's more interesting is that these values are pervasive in Process 
Manager even. This is when quotas are to be returned back and trim the limit of 
the quota block if needed, the kernel would either take the amount provided by 
the caller of quotas to return or the threshold (paged or not paged)
    if the amount to return exceeds the said threshold in question.
---
 ntoskrnl/include/internal/mm.h | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/ntoskrnl/include/internal/mm.h b/ntoskrnl/include/internal/mm.h
index 654f23c6ee0..5c28d27806b 100644
--- a/ntoskrnl/include/internal/mm.h
+++ b/ntoskrnl/include/internal/mm.h
@@ -28,6 +28,9 @@ extern KMUTANT MmSystemLoadLock;
 
 extern ULONG MmNumberOfPagingFiles;
 
+extern SIZE_T MmTotalNonPagedPoolQuota;
+extern SIZE_T MmTotalPagedPoolQuota;
+
 extern PVOID MmUnloadedDrivers;
 extern PVOID MmLastUnloadedDrivers;
 extern PVOID MmTriageActionTaken;
@@ -53,6 +56,14 @@ struct _EPROCESS;
 struct _MM_RMAP_ENTRY;
 typedef ULONG_PTR SWAPENTRY;
 
+//
+// Pool Quota values
+//
+#define MI_QUOTA_NON_PAGED_NEEDED_PAGES             64
+#define MI_NON_PAGED_QUOTA_MIN_RESIDENT_PAGES       200
+#define MI_CHARGE_PAGED_POOL_QUOTA                  0x80000
+#define MI_CHARGE_NON_PAGED_POOL_QUOTA              0x10000
+
 //
 // Special IRQL value (found in assertions)
 //
@@ -646,12 +657,21 @@ MiFreePoolPages(
 
 /* pool.c *******************************************************************/
 
+_Requires_lock_held_(PspQuotaLock)
 BOOLEAN
 NTAPI
-MiRaisePoolQuota(
-    IN POOL_TYPE PoolType,
-    IN ULONG CurrentMaxQuota,
-    OUT PULONG NewMaxQuota
+MmRaisePoolQuota(
+    _In_ POOL_TYPE PoolType,
+    _In_ SIZE_T CurrentMaxQuota,
+    _Out_ PSIZE_T NewMaxQuota
+);
+
+_Requires_lock_held_(PspQuotaLock)
+VOID
+NTAPI
+MmReturnPoolQuota(
+    _In_ POOL_TYPE PoolType,
+    _In_ SIZE_T QuotaToReturn
 );
 
 /* mdl.c *********************************************************************/

Reply via email to