[NTOSKRNL::CC] Implement CcOkToAddWriteBehindThread

This commit is contained in:
Dibyamartanda Samanta 2024-08-17 20:13:20 +02:00 committed by CodingWorkshop Signing Team
parent e75a2adeec
commit 3ae19eaf01
Signed by: CodingWorkshop Signing Team
GPG Key ID: 6DC88369C82795D2

View File

@ -13,6 +13,95 @@
extern "C"
/* Move Typedef Later to cctypes.hpp */
typedef struct _WRITE_BEHIND_THROUGHPUT
{
ULONG PagesYetToWrite;
ULONG Throughput;
} WRITE_BEHIND_THROUGHPUT, *PWRITE_BEHIND_THROUGHPUT;
BOOLEAN
CcOkToAddWriteBehindThread(VOID)
{
ULONG ActiveExtraWriteBehindThreads = {0};
PWRITE_BEHIND_THROUGHPUT ThroughputStats = nullptr;
ULONG PagesYetToWrite = {0};
ULONG Throughput = {0};
ULONG PreviousThroughput = {0};
LONG ThroughputTrend = {0};
BOOLEAN Result = false;
ActiveExtraWriteBehindThreads = CcActiveExtraWriteBehindThreads;
ThroughputStats = CcThroughputStats;
PagesYetToWrite = CcPagesYetToWrite;
Throughput = ThroughputStats[ActiveExtraWriteBehindThreads].PagesYetToWrite;
PreviousThroughput = 0;
if (Throughput >= PagesYetToWrite)
{
Throughput -= PagesYetToWrite;
}
else
{
Throughput = 0;
}
ThroughputStats[ActiveExtraWriteBehindThreads].PagesYetToWrite = PagesYetToWrite;
Result = true;
if (ActiveExtraWriteBehindThreads > 0)
{
PreviousThroughput = ThroughputStats[ActiveExtraWriteBehindThreads - 1].Throughput;
}
ThroughputStats[ActiveExtraWriteBehindThreads].Throughput = Throughput;
if (Throughput > 0)
{
ThroughputTrend = CcThroughputTrend;
if (Throughput < PreviousThroughput)
{
if (ThroughputTrend > 0)
ThroughputTrend = 0;
ThroughputTrend--;
}
else
{
if (ThroughputTrend < 0)
ThroughputTrend = 0;
ThroughputTrend++;
}
CcThroughputTrend = ThroughputTrend;
if (ThroughputTrend == 3)
{
CcThroughputTrend = 0;
Result = true;
if (ActiveExtraWriteBehindThreads < CcMaxExtraWriteBehindThreads)
{
ThroughputStats[ActiveExtraWriteBehindThreads + 1].Throughput = 0;
ThroughputStats[ActiveExtraWriteBehindThreads + 1].PagesYetToWrite = PagesYetToWrite;
}
}
else if (ThroughputTrend == -3)
{
CcThroughputTrend = 0;
Result = true;
if (ActiveExtraWriteBehindThreads > 0)
{
ThroughputStats[ActiveExtraWriteBehindThreads - 1].Throughput = 0;
ThroughputStats[ActiveExtraWriteBehindThreads - 1].PagesYetToWrite = PagesYetToWrite;
}
}
}
return Result;
}
VOID
NTAPI