I want to measure/optimize the "cold boot" startup performance of an application, and it's difficult to do this without an actual reboot, which is obviously not an ideal solution.
我想要测量/优化应用程序的“冷启动”启动性能,如果没有实际的重新启动,就很难做到这一点,这显然不是理想的解决方案。
Is there a way I could invalidate entire system's file cache, so that mapped page accesses actually cause a disk access, so that I can measure the time my program takes to start up?
是否有一种方法可以使整个系统的文件缓存失效,因此映射的页面访问实际上会导致磁盘访问,这样我就可以度量我的程序启动的时间了?
Info:
I pretty much need FSCTL_DISMOUNT_VOLUME
's functionality, but for the system volume.
我非常需要FSCTL_DISMOUNT_VOLUME的功能,但是对于系统卷。
4 个解决方案
#1
30
At least on Windows 7, it seems that attempting to open a volume handle without FILE_SHARE_WRITE
sharing permissions causes the file system cache to be invalidated, even if the creation fails.
至少在Windows 7上,尝试打开一个没有FILE_SHARE_WRITE共享权限的卷句柄会导致文件系统缓存失效,即使创建失败。
Thus I made a program that simply calls CreateFile
to this end.
因此,我编写了一个程序,简单地调用CreateFile到此结束。
Base64 encoding of the program*:
本程序的Base64编码*:
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAAABdRXZRRR7ikUUe4pFFHuKTGz/ikQUe4pMbOqKRBR7ilJpY2hFFHuKAAAAAAAAAABQRQAATAECAMEgRlkAAAAAAAAAAOAAIwELAQkAAAgAAAACAAAAAAAAoBIAAAAQAAAAIAAAAABAAAAQAAAAAgAABQAAAAAAAAAFAAAAAAAAAAAwAAAAAgAAlr4AAAMAAIQAABAAAAAQAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAMABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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A8c2VjdXJpdHk+DQogICAgICA8cmVxdWVzdGVkUHJpdmlsZWdlcz4NCiAgICAgICAgPHJlcXVlc3RlZEV4ZWN1dGlvbkxldmVsIGxldmVsPSJyZXF1aXJlQWRtaW5pc3RyYXRvciIgdWlBY2Nlc3M9ImZhbHNlIj48L3JlcXVlc3RlZEV4ZWN1dGlvbkxldmVsPg0KICAgICAgPC9yZXF1ZXN0ZWRQcml2aWxlZ2VzPg0KICAgIDwvc2VjdXJpdHk+DQogIDwvdHJ1c3RJbmZvPg0KPC9hc3NlbWJseT5QQURQQURESU5HWFhQQURESU5HUEFERElOR1hYUEFERElOR1BBRERJTkdYWFBBRERJTkdQQURESU5HWFhQQURESU5H
Source:
// Usage: ClearCache C: D:
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
int _tmain(int argc, LPTSTR argv[]) {
LPCTSTR DOS_PREFIX = _T("\\\\.\\");
for (int i = 1; i < argc; i++) {
LPTSTR arg = argv[i];
LPTSTR path = (LPTSTR)calloc(
_tcslen(arg) + _tcslen(DOS_PREFIX) + 1, sizeof(*arg));
__try {
if (_istalpha(arg[0]) && arg[1] == _T(':') &&
(arg[2] == _T('\0') ||
arg[2] == _T('\\') && arg[3] == _T('\0')))
{ _tcscat(path, DOS_PREFIX); }
_tcscat(path, arg);
HANDLE hFile = CreateFile(path,
FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); }
else {
DWORD le = GetLastError();
if (le != ERROR_SHARING_VIOLATION && le != ERROR_ACCESS_DENIED)
{
_ftprintf(stderr, _T("Error %d clearing %s\n"), le, argv[i]);
return le;
}
}
} __finally { free(path); }
}
return 0;
}
*Just for fun, see if you can figure out what the executable does by disassembling it. It's not your typical executable. :)
*只是为了好玩,看看你能不能通过拆卸它来找出可执行文件的功能。这不是典型的可执行文件。:)
#2
5
I've written a simple command-line utility to do that: FlushFileCache
我已经编写了一个简单的命令行实用程序来完成它:FlushFileCache。
It relies on the undocumented NtSetSystemInformation functions, and can flush the various other memory pools as well.
它依赖于无记录的NtSetSystemInformation函数,还可以刷新各种其他内存池。
#3
1
What David said. Create a large file, however many GB you need, and each time you want to reset your file cache, make a copy of the file. Then make sure you delete the old file.
大卫说。创建一个大文件,不管你需要多少GB,每次你想要重置你的文件缓存,复制一个文件。然后确保删除旧文件。
So, create BIGFILE1.DAT, copy it to BIGFILE2.DAT, and then delete BIGFILE1.DAT (which removes it from the disk and the cache). Next time, just reverse the process.
因此,创建BIGFILE1。DAT,复制到BIGFILE2。DAT,然后删除BIGFILE1。DAT(从磁盘和缓存中删除它)。下次,只要反转这个过程。
Addenda:
附录:
Well, the other option is to take the files that are mapped, and copy them to new files, delete the old ones, and rename the new files back to the old ones. The cache is backed by a file. If the file "goes away" so does the cache.
另一种选择是将映射的文件复制到新文件中,删除旧文件,并将新文件重命名为旧文件。缓存由一个文件支持。如果文件“消失”,缓存也会消失。
If you can identify these files, and they're not shared by the system/other running programs, this should be simple to script and, ideally, run faster than copy 6G of files around.
如果您能够识别这些文件,并且它们不是由系统/其他运行程序共享的,那么这应该是简单的脚本,并且,理想情况下,运行速度比复制6G文件快。
#4
0
You can use a VM and take a shapshot right after the VM boots. Resuming from a snapshot will be faster than a reboot.
您可以使用VM并在VM引导之后进行shapshot。从快照中恢复将比重新启动更快。
#1
30
At least on Windows 7, it seems that attempting to open a volume handle without FILE_SHARE_WRITE
sharing permissions causes the file system cache to be invalidated, even if the creation fails.
至少在Windows 7上,尝试打开一个没有FILE_SHARE_WRITE共享权限的卷句柄会导致文件系统缓存失效,即使创建失败。
Thus I made a program that simply calls CreateFile
to this end.
因此,我编写了一个程序,简单地调用CreateFile到此结束。
Base64 encoding of the program*:
本程序的Base64编码*:
TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAsAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAQAYAAAAGAAAgAAAAAAAAAAABAAAAAAAAQABAAAAMAAAgAAAAAAAAAAABAAAAAAAAQAJBAAASAAAAFggAABlAQAA5AQAAAAAAAA8YXNzZW1ibHkgeG1sbnM9InVybjpzY2hlbWFzLW1pY3Jvc29mdC1jb206YXNtLnYxIiBtYW5pZmVzdFZlcnNpb249IjEuMCI+DQogIDx0cnVzdEluZm8geG1sbnM9InVybjpzY2hlbWFzLW1pY3Jvc29mdC1jb206YXNtLnYzIj4NCiAgICA8c2VjdXJpdHk+DQogICAgICA8cmVxdWVzdGVkUHJpdmlsZWdlcz4NCiAgICAgICAgPHJlcXVlc3RlZEV4ZWN1dGlvbkxldmVsIGxldmVsPSJyZXF1aXJlQWRtaW5pc3RyYXRvciIgdWlBY2Nlc3M9ImZhbHNlIj48L3JlcXVlc3RlZEV4ZWN1dGlvbkxldmVsPg0KICAgICAgPC9yZXF1ZXN0ZWRQcml2aWxlZ2VzPg0KICAgIDwvc2VjdXJpdHk+DQogIDwvdHJ1c3RJbmZvPg0KPC9hc3NlbWJseT5QQURQQURESU5HWFhQQURESU5HUEFERElOR1hYUEFERElOR1BBRERJTkdYWFBBRERJTkdQQURESU5HWFhQQURESU5H
Source:
// Usage: ClearCache C: D:
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
int _tmain(int argc, LPTSTR argv[]) {
LPCTSTR DOS_PREFIX = _T("\\\\.\\");
for (int i = 1; i < argc; i++) {
LPTSTR arg = argv[i];
LPTSTR path = (LPTSTR)calloc(
_tcslen(arg) + _tcslen(DOS_PREFIX) + 1, sizeof(*arg));
__try {
if (_istalpha(arg[0]) && arg[1] == _T(':') &&
(arg[2] == _T('\0') ||
arg[2] == _T('\\') && arg[3] == _T('\0')))
{ _tcscat(path, DOS_PREFIX); }
_tcscat(path, arg);
HANDLE hFile = CreateFile(path,
FILE_READ_DATA, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) { CloseHandle(hFile); }
else {
DWORD le = GetLastError();
if (le != ERROR_SHARING_VIOLATION && le != ERROR_ACCESS_DENIED)
{
_ftprintf(stderr, _T("Error %d clearing %s\n"), le, argv[i]);
return le;
}
}
} __finally { free(path); }
}
return 0;
}
*Just for fun, see if you can figure out what the executable does by disassembling it. It's not your typical executable. :)
*只是为了好玩,看看你能不能通过拆卸它来找出可执行文件的功能。这不是典型的可执行文件。:)
#2
5
I've written a simple command-line utility to do that: FlushFileCache
我已经编写了一个简单的命令行实用程序来完成它:FlushFileCache。
It relies on the undocumented NtSetSystemInformation functions, and can flush the various other memory pools as well.
它依赖于无记录的NtSetSystemInformation函数,还可以刷新各种其他内存池。
#3
1
What David said. Create a large file, however many GB you need, and each time you want to reset your file cache, make a copy of the file. Then make sure you delete the old file.
大卫说。创建一个大文件,不管你需要多少GB,每次你想要重置你的文件缓存,复制一个文件。然后确保删除旧文件。
So, create BIGFILE1.DAT, copy it to BIGFILE2.DAT, and then delete BIGFILE1.DAT (which removes it from the disk and the cache). Next time, just reverse the process.
因此,创建BIGFILE1。DAT,复制到BIGFILE2。DAT,然后删除BIGFILE1。DAT(从磁盘和缓存中删除它)。下次,只要反转这个过程。
Addenda:
附录:
Well, the other option is to take the files that are mapped, and copy them to new files, delete the old ones, and rename the new files back to the old ones. The cache is backed by a file. If the file "goes away" so does the cache.
另一种选择是将映射的文件复制到新文件中,删除旧文件,并将新文件重命名为旧文件。缓存由一个文件支持。如果文件“消失”,缓存也会消失。
If you can identify these files, and they're not shared by the system/other running programs, this should be simple to script and, ideally, run faster than copy 6G of files around.
如果您能够识别这些文件,并且它们不是由系统/其他运行程序共享的,那么这应该是简单的脚本,并且,理想情况下,运行速度比复制6G文件快。
#4
0
You can use a VM and take a shapshot right after the VM boots. Resuming from a snapshot will be faster than a reboot.
您可以使用VM并在VM引导之后进行shapshot。从快照中恢复将比重新启动更快。