[NTOS:Mm] Replace YieldProcessor() with KeDelayExecutionThread()

These are used in the paging path, when the page is currently in the process of being read from or written to the disk. While YieldProcessor() provides the chance to switch context to the other paging thread, it only does so, once the current thread's quantum has expired. On a single CPU system this effectively leads to busy waiting for the rest of the quantum. On SMP systems this could succeed earlier, thus reducing latency, but it would still contribute to high CPU usage, while waiting for the IO operation to complete, which is not what we want.
Using KeDelayExecutionThread() will instantly allow another thread to run, providing enough time to complete the IO operation.
This commit is contained in:
Timo Kreuzer 2023-04-01 19:18:45 +03:00
parent d70e798977
commit 477792856e

View file

@ -1477,7 +1477,7 @@ MmAlterViewAttributes(PMMSUPPORT AddressSpace,
break;
MmUnlockSectionSegment(Segment);
MmUnlockAddressSpace(AddressSpace);
YieldProcessor();
KeDelayExecutionThread(KernelMode, FALSE, &TinyTime);
MmLockAddressSpace(AddressSpace);
MmLockSectionSegment(Segment);
}
@ -1608,7 +1608,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
if (SwapEntry == MM_WAIT_ENTRY)
{
MmUnlockAddressSpace(AddressSpace);
YieldProcessor();
KeDelayExecutionThread(KernelMode, FALSE, &TinyTime);
MmLockAddressSpace(AddressSpace);
return STATUS_MM_RESTART_OPERATION;
}
@ -1789,7 +1789,7 @@ MmNotPresentFaultSectionView(PMMSUPPORT AddressSpace,
{
MmUnlockSectionSegment(Segment);
MmUnlockAddressSpace(AddressSpace);
YieldProcessor();
KeDelayExecutionThread(KernelMode, FALSE, &TinyTime);
MmLockAddressSpace(AddressSpace);
return STATUS_MM_RESTART_OPERATION;
}
@ -3442,7 +3442,7 @@ MmFreeSectionPage(PVOID Context, MEMORY_AREA* MemoryArea, PVOID Address,
MmUnlockSectionSegment(Segment);
MmUnlockAddressSpace(AddressSpace);
YieldProcessor();
KeDelayExecutionThread(KernelMode, FALSE, &TinyTime);
MmLockAddressSpace(AddressSpace);
MmLockSectionSegment(Segment);
@ -5202,7 +5202,7 @@ MmMakePagesDirty(
{
MmUnlockSectionSegment(Segment);
MmUnlockAddressSpace(AddressSpace);
YieldProcessor();
KeDelayExecutionThread(KernelMode, FALSE, &TinyTime);
MmLockAddressSpace(AddressSpace);
MmLockSectionSegment(Segment);
Entry = MmGetPageEntrySectionSegment(Segment, &SegmentOffset);