minifilter IRP_MJ_READ has unstable performance

In my driver,IRP_MJ_READ is like:

if(FLT_IS_IRP_OPERATION(Data))
{
FsRtlEnterFileSystem();
if(BooleanFlagOn(IrpFlags, IRP_PAGING_IO))
{
ExAcquireResourceSharedLite(&Fcb->PagingIoResource,TRUE);
fltStatus = FltCheckOplock( &Fcb->Oplock, Data, NULL, NULL, NULL);
BytesToRead = ALIGNED(ULONG, Length, Fcb->SectorSize); //SectorSize = 512
FltReadFile(BytesToRead,FLTFL_IO_OPERATION_NON_CACHED);
KeSaveExtendedProcessorState()
AVX_Decrypt(BytesToRead);
KeRestoreExtendedProcessorState
ExReleaseResourceLite(&Fcb->PagingIoResource);
}
FsRtlExitFileSystem();
}
else if(FLT_IS_FASTIO_OPERATION(Data))
{
FsRtlEnterFileSystem();
Buffer = MapUserBuffer(Data);
Status = FsRtlCopyRead();
FsRtlExitFileSystem();
}

In user mode test code,like:

DWORD start = timeGetTime();
HANDLE target = CreateFileA(“1G.txt”);
file_size = GetFileSize(target,NULL);
do {
ReadFile(out_buffer, ONE_M,);//ONE_M = 1M
} while (read_len < file_size);
CloseHandle(target);
DWORD end = timeGetTime();
float speed = (file_size / ONE_M) / ((end - start) / 1000.00);

Every record is first test after computer just started.
You can see unstable performance for reading,but write has stable performance.
Why write is stable and read is so unstable?

read 1024MB need 14.05s 72.91MB/S
read 1024MB need 8.37s 122.28MB/S
read 1024MB need 7.01s 145.97MB/S
read 1024MB need 25.92s 39.51MB/S very slowly
read 1024MB need 7.28s 140.66MB/S
read 1024MB need 6.31s 162.23MB/S
read 1024MB need 23.95s 42.75MB/S very slowly
read 1024MB need 37.81s 27.08MB/S very slowly
read 1024MB need 30.85s 33.19MB/S very slowly
read 1024MB need 9.72s 105.37MB/S

write 1024MB need 10.37s 98.71MB/S
write 1024MB need 10.19s 100.53MB/S
write 1024MB need 10.50s 97.53MB/S
write 1024MB need 11.48s 89.18MB/S
write 1024MB need 11.40s 89.79MB/S
write 1024MB need 10.09s 101.46MB/S
write 1024MB need 10.09s 101.46MB/S
write 1024MB need 9.78s 104.70MB/S
write 1024MB need 11.50s 89.05MB/S

Sorry,it should be unstable performance.

Interesting.

I don’t know. Caching, perhaps?

Try it with different caring options on the open and see what happens.

P

Is this on an SSD drive? VM?

@Dejan_Maksimovic said:
Is this on an SSD drive? VM?
Not VM,desktop computer:
Intel i5-4460 3.20GHz
16.0 RAM
TOSHIBA DT01ACA100 1TB 7200 RPM 32MB Cache

This is a mini filter, not a filesystem?

If so what is with the Oplocks and taking other people’s locks? You check someone else’s oplock and then plough on?

I don’t understand your code and a random wait doesn’t seem an unlikely outcome.