为什么WriteFile调用ReadFile以及如何避免它?

时间:2015-08-26 10:35:09

标签: windows winapi ntfs

当在文件的现有部分中顺序覆盖(例如8192字节对齐和大小的块)时(有时/总是?)WriteFile导致从磁盘读取文件,这完全破坏了性能。我不太明白为什么会这样,以及如何避免它。

使用Process Monitor我收到以下信息:

Event.Class: File System
Event.Operator: ReadFile
Event.Offset: 1 875 288 653 824
Event.Length: 4 096
Event.I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O
Event.Priority: Normal 

0   FLTMGR.SYS  FltDecodeParameters + 0x1ab1    0xfffff8016e7f4621  C:\WINDOWS\System32\drivers\FLTMGR.SYS
1   FLTMGR.SYS  FltDecodeParameters + 0x166c    0xfffff8016e7f41dc  C:\WINDOWS\System32\drivers\FLTMGR.SYS
2   FLTMGR.SYS  FltDecodeParameters + 0x1093    0xfffff8016e7f3c03  C:\WINDOWS\System32\drivers\FLTMGR.SYS
3   FLTMGR.SYS  FltDecodeParameters + 0xe8e 0xfffff8016e7f39fe  C:\WINDOWS\System32\drivers\FLTMGR.SYS
4   ntoskrnl.exe    IoPageRead + 0x258  0xfffff8015b8ba598  C:\WINDOWS\system32\ntoskrnl.exe
5   ntoskrnl.exe    IoPageRead + 0x4d4  0xfffff8015b8ba814  C:\WINDOWS\system32\ntoskrnl.exe
6   ntoskrnl.exe    IoGetBaseFileSystemDeviceObject + 0x7c8 0xfffff8015b8b8ae8  C:\WINDOWS\system32\ntoskrnl.exe
7   ntoskrnl.exe    PfFileInfoNotify + 0x6ead   0xfffff8015b8a823d  C:\WINDOWS\system32\ntoskrnl.exe
8   ntoskrnl.exe    setjmpex + 0x224d   0xfffff8015b9dfdbd  C:\WINDOWS\system32\ntoskrnl.exe
9   ntoskrnl.exe    memcpy + 0x250  0xfffff8015b9e2590  C:\WINDOWS\system32\ntoskrnl.exe
10  ntoskrnl.exe    MmMapLockedPagesSpecifyCache + 0x132e   0xfffff8015b89950e  C:\WINDOWS\system32\ntoskrnl.exe
11  ntoskrnl.exe    MmMapLockedPagesSpecifyCache + 0x949    0xfffff8015b898b29  C:\WINDOWS\system32\ntoskrnl.exe
12  ntoskrnl.exe    CcCopyWriteEx + 0x1ca   0xfffff8015b965f9a  C:\WINDOWS\system32\ntoskrnl.exe
13  NTFS.sys    NTFS.sys + 0xb7518  0xfffff8016f907518  C:\WINDOWS\System32\Drivers\NTFS.sys
14  FLTMGR.SYS  FltIsCallbackDataDirty + 0xb15  0xfffff8016e7f58b5  C:\WINDOWS\System32\drivers\FLTMGR.SYS
15  FLTMGR.SYS  FltDecodeParameters + 0x3ad 0xfffff8016e7f2f1d  C:\WINDOWS\System32\drivers\FLTMGR.SYS
16  FLTMGR.SYS  FltParseFileName + 0x159c   0xfffff8016e822eec  C:\WINDOWS\System32\drivers\FLTMGR.SYS
17  ntoskrnl.exe    NtWriteFile + 0x432 0xfffff8015bca8532  C:\WINDOWS\system32\ntoskrnl.exe
18  ntoskrnl.exe    setjmpex + 0x37f3   0xfffff8015b9e1363  C:\WINDOWS\system32\ntoskrnl.exe
19  ntdll.dll   ZwWriteFile + 0xa   0x7ff9eb34357a  C:\WINDOWS\SYSTEM32\ntdll.dll
20  KERNELBASE.dll  WriteFile + 0x88    0x7ff9e84cd458  C:\WINDOWS\system32\KERNELBASE.dll
21  capture.exe capture.exe + 0x6f40b   0x7ff6b971f40b  C:\ingest\server\capture.exe
22  capture.exe capture.exe + 0x5998    0x7ff6b96b5998  C:\ingest\server\capture.exe
23  capture.exe capture.exe + 0x13285   0x7ff6b96c3285  C:\ingest\server\capture.exe
24  nxtcapture.exe  nxtcapture.exe + 0x2b89 0x7ff6b96b2b89  C:\ingest\server\capture.exe
25  capture.exe capture.exe + 0x136be1  0x7ff6b97e6be1  C:\ingest\server\capture.exe
26  KERNEL32.DLL    BaseThreadInitThunk + 0x22  0x7ff9eab02d92  C:\WINDOWS\system32\KERNEL32.DLL
27  ntdll.dll   RtlUserThreadStart + 0x34   0x7ff9eb2b9f64  C:\WINDOWS\SYSTEM32\ntdll.dll

CcCopyWriteEx中的以下信息可能相关:

  

如果Wait为TRUE,则保证CcCopyWriteEx完成复制   请求并返回TRUE。如果缓存文件的必需页面是   已经驻留在内存中,数据将立即复制,不会   会发生阻塞。 如果任何需要的页面不是常驻页面,则调用者   将被置于等待状态,直到完成所有必需的页面   居民和数据可以复制。

如果我理解正确,这与内存映射类似,其中首先需要覆盖的页面需要从磁盘读取,即使整个页面要被覆盖。有什么办法可以避免这个吗可能有些Cache Manager Routine

FILE_FLAG_WRITE_THROUGH有所作为。它仍然调用ReadFile但不经常调用,从磁盘读取的数量似乎要低得多。虽然我没有完全理解发生了什么,但磁盘活动和队列长度仍然高得多,而不是写入目标文件中的非初始化页面。

0   FLTMGR.SYS  FltDecodeParameters + 0x1ab1    0xfffff8018a9f4621  C:\WINDOWS\System32\drivers\FLTMGR.SYS
1   FLTMGR.SYS  FltDecodeParameters + 0x166c    0xfffff8018a9f41dc  C:\WINDOWS\System32\drivers\FLTMGR.SYS
2   FLTMGR.SYS  FltDecodeParameters + 0x1093    0xfffff8018a9f3c03  C:\WINDOWS\System32\drivers\FLTMGR.SYS
3   FLTMGR.SYS  FltDecodeParameters + 0xe8e 0xfffff8018a9f39fe  C:\WINDOWS\System32\drivers\FLTMGR.SYS
4   ntoskrnl.exe    IoPageRead + 0x258  0xfffff803f5e4d598  C:\WINDOWS\system32\ntoskrnl.exe
5   ntoskrnl.exe    IoPageRead + 0x4d4  0xfffff803f5e4d814  C:\WINDOWS\system32\ntoskrnl.exe
6   ntoskrnl.exe    IoGetBaseFileSystemDeviceObject + 0x7c8 0xfffff803f5e4bae8  C:\WINDOWS\system32\ntoskrnl.exe
7   ntoskrnl.exe    PfFileInfoNotify + 0x6ead   0xfffff803f5e3b23d  C:\WINDOWS\system32\ntoskrnl.exe
8   ntoskrnl.exe    setjmpex + 0x224d   0xfffff803f5f72dbd  C:\WINDOWS\system32\ntoskrnl.exe
9   ntoskrnl.exe    memcpy + 0x250  0xfffff803f5f75590  C:\WINDOWS\system32\ntoskrnl.exe
10  ntoskrnl.exe    MmMapLockedPagesSpecifyCache + 0x132e   0xfffff803f5e2c50e  C:\WINDOWS\system32\ntoskrnl.exe
11  ntoskrnl.exe    MmMapLockedPagesSpecifyCache + 0x949    0xfffff803f5e2bb29  C:\WINDOWS\system32\ntoskrnl.exe
12  ntoskrnl.exe    CcCopyWriteEx + 0x1ca   0xfffff803f5ef8f9a  C:\WINDOWS\system32\ntoskrnl.exe
13  NTFS.sys    NTFS.sys + 0x8ce8   0xfffff8018c068ce8  C:\WINDOWS\System32\Drivers\NTFS.sys
14  NTFS.sys    NTFS.sys + 0x7dc7   0xfffff8018c067dc7  C:\WINDOWS\System32\Drivers\NTFS.sys
15  FLTMGR.SYS  FltIsCallbackDataDirty + 0x424  0xfffff8018a9f51c4  C:\WINDOWS\System32\drivers\FLTMGR.SYS
16  FLTMGR.SYS  FltDecodeParameters + 0xea6 0xfffff8018a9f3a16  C:\WINDOWS\System32\drivers\FLTMGR.SYS
17  ntoskrnl.exe    NtReadFile + 0xa1b  0xfffff803f623c72b  C:\WINDOWS\system32\ntoskrnl.exe
18  ntoskrnl.exe    NtWriteFile + 0x680 0xfffff803f623b780  C:\WINDOWS\system32\ntoskrnl.exe
19  ntoskrnl.exe    setjmpex + 0x37f3   0xfffff803f5f74363  C:\WINDOWS\system32\ntoskrnl.exe
20  ntdll.dll   ZwWriteFile + 0xa   0x7ff9a313357a  C:\WINDOWS\SYSTEM32\ntdll.dll
21  KERNELBASE.dll  WriteFile + 0x88    0x7ff9a059d458  C:\WINDOWS\system32\KERNELBASE.dll
22  capture.exe capture.exe + 0x6f40b   0x7ff7eef0f40b  C:\ingest\server\capture.exe
23  capture.exe capture.exe + 0x5998    0x7ff7eeea5998  C:\ingest\server\capture.exe
24  capture.exe capture.exe + 0x13285   0x7ff7eeeb3285  C:\ingest\server\capture.exe
25  capture.exe capture.exe + 0x2b89    0x7ff7eeea2b89  C:\ingest\server\capture.exe
26  capture.exe capture.exe + 0x136c71  0x7ff7eefd6c71  C:\ingest\server\capture.exe
27  KERNEL32.DLL    BaseThreadInitThunk + 0x22  0x7ff9a0a92d92  C:\WINDOWS\system32\KERNEL32.DLL
28  ntdll.dll   RtlUserThreadStart + 0x34   0x7ff9a30a9f64  C:\WINDOWS\SYSTEM32\ntdll.dll

直写也很有趣的是它似乎正在读取单个扇区(注意ReadFile调用中的长度:4096)。

13:09:00,8579774    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 519 567 872, Length: 3 112 960, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:00,9399289    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 522 680 832, Length: 2 957 312, I/O Flags: Write Through, Priority: Normal
13:09:00,9418288    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 522 680 832, Length: 2 957 312, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,0466551    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 525 638 144, Length: 3 145 728, I/O Flags: Write Through, Priority: Normal
13:09:01,0486614    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 525 638 144, Length: 3 145 728, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,1476023    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 528 783 872, Length: 2 490 368, I/O Flags: Write Through, Priority: Normal
13:09:01,1492754    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 528 783 872, Length: 2 490 368, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,2594166    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 531 274 240, Length: 2 981 888, I/O Flags: Write Through, Priority: Normal
13:09:01,2613028    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 531 274 240, Length: 2 981 888, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,3693932    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 534 256 128, Length: 2 678 784, I/O Flags: Write Through, Priority: Normal
13:09:01,3705444    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 534 256 128, Length: 90 112, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,3708446    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 534 346 240, Length: 2 588 672, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,4846832    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 536 934 912, Length: 3 096 576, I/O Flags: Write Through, Priority: Normal
13:09:01,4862724    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 536 934 912, Length: 3 096 576, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,5905083    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 540 031 488, Length: 3 211 264, I/O Flags: Write Through, Priority: Normal
13:09:01,5923326    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 540 031 488, Length: 3 211 264, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,6951367    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 543 242 752, Length: 2 670 592, I/O Flags: Write Through, Priority: Normal
13:09:01,6967169    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 543 242 752, Length: 2 670 592, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,8028430    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 545 913 344, Length: 2 342 912, I/O Flags: Write Through, Priority: Normal
13:09:01,8045821    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 545 913 344, Length: 2 342 912, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:01,9234657    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 548 256 256, Length: 3 055 616, I/O Flags: Write Through, Priority: Normal
13:09:01,9254169    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 548 256 256, Length: 3 055 616, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,0273731    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 551 311 872, Length: 3 424 256, I/O Flags: Write Through, Priority: Normal
13:09:02,0288307    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 551 311 872, Length: 3 424 256, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,1316979    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 554 736 128, Length: 2 678 784, I/O Flags: Write Through, Priority: Normal
13:09:02,1327686    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 554 736 128, Length: 2 678 784, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,2327822    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 557 414 912, Length: 2 605 056, I/O Flags: Write Through, Priority: Normal
13:09:02,2341425    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 557 414 912, Length: 2 605 056, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,3390269    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 560 019 968, Length: 2 711 552, I/O Flags: Write Through, Priority: Normal
13:09:02,3402005    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 560 019 968, Length: 2 711 552, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,4392960    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 562 731 520, Length: 3 334 144, I/O Flags: Write Through, Priority: Normal
13:09:02,4411620    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 562 731 520, Length: 3 334 144, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,5463951    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 566 065 664, Length: 2 277 376, I/O Flags: Write Through, Priority: Normal
13:09:02,5474362    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 566 065 664, Length: 1 835 008, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,5484791    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 567 900 672, Length: 442 368, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,6509821    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 568 343 040, Length: 3 342 336, I/O Flags: Write Through, Priority: Normal
13:09:02,6524223    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 568 343 040, Length: 3 342 336, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,7516238    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 571 685 376, Length: 2 555 904, I/O Flags: Write Through, Priority: Normal
13:09:02,7529352    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 571 685 376, Length: 2 555 904, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,8526049    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 574 241 280, Length: 2 138 112, I/O Flags: Write Through, Priority: Normal
13:09:02,8541937    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 574 241 280, Length: 2 138 112, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:02,9589201    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 576 379 392, Length: 3 039 232, I/O Flags: Write Through, Priority: Normal
13:09:02,9602760    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 576 379 392, Length: 3 039 232, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,0738157    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 579 418 624, Length: 2 785 280, I/O Flags: Write Through, Priority: Normal
13:09:03,0752279    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 579 418 624, Length: 2 785 280, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,1890830    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 582 203 904, Length: 3 383 296, I/O Flags: Write Through, Priority: Normal
13:09:03,1908153    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 582 203 904, Length: 3 383 296, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,3075209    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 585 587 200, Length: 3 055 616, I/O Flags: Write Through, Priority: Normal
13:09:03,3091505    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 585 587 200, Length: 3 055 616, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,4250265    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 588 642 816, Length: 3 006 464, I/O Flags: Write Through, Priority: Normal
13:09:03,4266098    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 588 642 816, Length: 3 006 464, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,5379099    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 591 649 280, Length: 3 293 184, I/O Flags: Write Through, Priority: Normal
13:09:03,5392216    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 591 649 280, Length: 3 293 184, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,6386064    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 594 942 464, Length: 2 596 864, I/O Flags: Write Through, Priority: Normal
13:09:03,6403585    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 594 942 464, Length: 2 596 864, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,7476785    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 597 539 328, Length: 2 498 560, I/O Flags: Write Through, Priority: Normal
13:09:03,7495491    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 597 539 328, Length: 2 498 560, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,8598891    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 600 037 888, Length: 3 522 560, I/O Flags: Write Through, Priority: Normal
13:09:03,8613834    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 600 037 888, Length: 1 417 216, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,8622310    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 601 455 104, Length: 2 105 344, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:03,9748379    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 603 560 448, Length: 3 006 464, I/O Flags: Write Through, Priority: Normal
13:09:03,9761048    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 603 560 448, Length: 3 006 464, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,0970842    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 606 566 912, Length: 3 104 768, I/O Flags: Write Through, Priority: Normal
13:09:04,0986363    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 606 566 912, Length: 3 104 768, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,2026181    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 609 671 680, Length: 2 342 912, I/O Flags: Write Through, Priority: Normal
13:09:04,2047880    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 839 040, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2059156    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 908 672, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2062328    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 912 768, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2124125    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 916 864, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2125033    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 920 960, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2125692    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 925 056, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2127042    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 929 152, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2130060    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 933 248, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2132903    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 610 937 344, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2134340    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 092 992, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2136517    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 097 088, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2139954    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 101 184, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2140859    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 105 280, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2142153    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 109 376, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2143550    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 113 472, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2144234    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 117 568, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2144772    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 611 121 664, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:04,2151351    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 609 671 680, Length: 2 342 912, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,3066104    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 612 014 592, Length: 2 940 928, I/O Flags: Write Through, Priority: Normal
13:09:04,3085623    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 612 014 592, Length: 2 940 928, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,4154163    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 614 955 520, Length: 3 186 688, I/O Flags: Write Through, Priority: Normal
13:09:04,4177492    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 614 955 520, Length: 3 186 688, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,5174478    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 618 142 208, Length: 2 547 712, I/O Flags: Write Through, Priority: Normal
13:09:04,5192064    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 618 142 208, Length: 2 547 712, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,6315595    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 620 689 920, Length: 2 891 776, I/O Flags: Write Through, Priority: Normal
13:09:04,6328619    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 620 689 920, Length: 2 891 776, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,7344473    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 623 581 696, Length: 3 055 616, I/O Flags: Write Through, Priority: Normal
13:09:04,7358909    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 623 581 696, Length: 3 055 616, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,8373090    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 626 637 312, Length: 2 621 440, I/O Flags: Write Through, Priority: Normal
13:09:04,8385106    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 626 637 312, Length: 2 621 440, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:04,9471593    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 629 258 752, Length: 3 047 424, I/O Flags: Write Through, Priority: Normal
13:09:04,9485457    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 629 258 752, Length: 3 047 424, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,0705718    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 632 306 176, Length: 3 022 848, I/O Flags: Write Through, Priority: Normal
13:09:05,0730288    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 632 306 176, Length: 2 703 360, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,0748379    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 635 009 536, Length: 319 488, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,1867648    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 635 329 024, Length: 3 383 296, I/O Flags: Write Through, Priority: Normal
13:09:05,1885589    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 635 329 024, Length: 3 383 296, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,3091527    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 638 712 320, Length: 2 637 824, I/O Flags: Write Through, Priority: Normal
13:09:05,3108466    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 638 712 320, Length: 2 637 824, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,4259338    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 641 350 144, Length: 3 506 176, I/O Flags: Write Through, Priority: Normal
13:09:05,4277572    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 641 350 144, Length: 3 506 176, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Write Through, Priority: Normal
13:09:05,5460495    capture.exe 3336    WriteFile   L:\data.loop    SUCCESS Offset: 1 927 644 856 320, Length: 3 309 568, I/O Flags: Write Through, Priority: Normal
13:09:05,5479142    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 596 544, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5641906    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 633 408, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5679702    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 637 504, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5680940    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 641 600, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5684703    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 645 696, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5687985    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 649 792, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5688542    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 653 888, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5688983    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 657 984, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal
13:09:05,5692249    capture.exe 3336    ReadFile    L:\data.loop    SUCCESS Offset: 1 927 647 662 080, Length: 4 096, I/O Flags: Non-cached, Paging I/O, Synchronous Paging I/O, Priority: Normal

1 个答案:

答案 0 :(得分:2)

您看到的读取很可能是操作系统缓存预读。 FILE_FLAG_WRITE_THROUGH标志是指示磁盘驱动程序直接写入数据以驱动绕过硬件磁盘系统缓存(尽管it is notoriously ignored by many less-than-enterprise-grade SATA drives)。该标志不会阻止OS或磁盘系统缓存缓存数据,也不会禁用预读OS缓存。

我假设您的意图是以几乎连续的高数据速率写入文件,很少读取它,就像在视频或仪器捕获系统中一样。它是,那么你正在寻找的是另一个标志FILE_FLAG_NO_BUFFERING,它禁止在读取或写入时对文件数据进行操作系统缓存。显然,预读也被禁用以满足读取不来自系统缓存的承诺。

不要将FILE_FLAG_WRITE_THROUGHFILE_FLAG_NO_BUFFERING一起指定,除非您希望保证在您WriteFile的调用返回时数据实际上已变为磁位。这适用于事务处理(如数据库服务器),通常可以降低应用程序的磁盘I / O性能,在某些情况下会降低很多因素。