forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fscache: teach fscache to use NtQueryDirectoryFile
Using FindFirstFileExW() requires the OS to allocate a 64K buffer for each directory and then free it when we call FindClose(). Update fscache to call the underlying kernel API NtQueryDirectoryFile so that we can do the buffer management ourselves. That allows us to allocate a single buffer for the lifetime of the cache and reuse it for each directory. This change improves performance of 'git status' by 18% in a repo with ~200K files and 30k folders. Documentation for NtQueryDirectoryFile can be found at: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntifs/nf-ntifs-ntquerydirectoryfile https://docs.microsoft.com/en-us/windows/desktop/FileIO/file-attribute-constants https://docs.microsoft.com/en-us/windows/desktop/fileio/reparse-point-tags To determine if the specified directory is a symbolic link, inspect the FileAttributes member to see if the FILE_ATTRIBUTE_REPARSE_POINT flag is set. If so, EaSize will contain the reparse tag (this is a so far undocumented feature, but confirmed by the NTFS developers). To determine if the reparse point is a symbolic link (and not some other form of reparse point), test whether the tag value equals the value IO_REPARSE_TAG_SYMLINK. The NtQueryDirectoryFile() call works best (and on Windows 8.1 and earlier, it works *only*) with buffer sizes up to 64kB. Which is 32k wide characters, so let's use that as our buffer size. Signed-off-by: Ben Peart <benpeart@microsoft.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
- Loading branch information
Showing
2 changed files
with
224 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#ifndef _NTIFS_ | ||
#define _NTIFS_ | ||
|
||
/* | ||
* Copy necessary structures and definitions out of the Windows DDK | ||
* to enable calling NtQueryDirectoryFile() | ||
*/ | ||
|
||
typedef _Return_type_success_(return >= 0) LONG NTSTATUS; | ||
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) | ||
|
||
#if !defined(_NTSECAPI_) && !defined(_WINTERNL_) && \ | ||
!defined(__UNICODE_STRING_DEFINED) | ||
#define __UNICODE_STRING_DEFINED | ||
typedef struct _UNICODE_STRING { | ||
USHORT Length; | ||
USHORT MaximumLength; | ||
PWSTR Buffer; | ||
} UNICODE_STRING; | ||
typedef UNICODE_STRING *PUNICODE_STRING; | ||
typedef const UNICODE_STRING *PCUNICODE_STRING; | ||
#endif /* !_NTSECAPI_ && !_WINTERNL_ && !__UNICODE_STRING_DEFINED */ | ||
|
||
typedef enum _FILE_INFORMATION_CLASS { | ||
FileDirectoryInformation = 1, | ||
FileFullDirectoryInformation, | ||
FileBothDirectoryInformation, | ||
FileBasicInformation, | ||
FileStandardInformation, | ||
FileInternalInformation, | ||
FileEaInformation, | ||
FileAccessInformation, | ||
FileNameInformation, | ||
FileRenameInformation, | ||
FileLinkInformation, | ||
FileNamesInformation, | ||
FileDispositionInformation, | ||
FilePositionInformation, | ||
FileFullEaInformation, | ||
FileModeInformation, | ||
FileAlignmentInformation, | ||
FileAllInformation, | ||
FileAllocationInformation, | ||
FileEndOfFileInformation, | ||
FileAlternateNameInformation, | ||
FileStreamInformation, | ||
FilePipeInformation, | ||
FilePipeLocalInformation, | ||
FilePipeRemoteInformation, | ||
FileMailslotQueryInformation, | ||
FileMailslotSetInformation, | ||
FileCompressionInformation, | ||
FileObjectIdInformation, | ||
FileCompletionInformation, | ||
FileMoveClusterInformation, | ||
FileQuotaInformation, | ||
FileReparsePointInformation, | ||
FileNetworkOpenInformation, | ||
FileAttributeTagInformation, | ||
FileTrackingInformation, | ||
FileIdBothDirectoryInformation, | ||
FileIdFullDirectoryInformation, | ||
FileValidDataLengthInformation, | ||
FileShortNameInformation, | ||
FileIoCompletionNotificationInformation, | ||
FileIoStatusBlockRangeInformation, | ||
FileIoPriorityHintInformation, | ||
FileSfioReserveInformation, | ||
FileSfioVolumeInformation, | ||
FileHardLinkInformation, | ||
FileProcessIdsUsingFileInformation, | ||
FileNormalizedNameInformation, | ||
FileNetworkPhysicalNameInformation, | ||
FileIdGlobalTxDirectoryInformation, | ||
FileIsRemoteDeviceInformation, | ||
FileAttributeCacheInformation, | ||
FileNumaNodeInformation, | ||
FileStandardLinkInformation, | ||
FileRemoteProtocolInformation, | ||
FileMaximumInformation | ||
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS; | ||
|
||
typedef struct _FILE_FULL_DIR_INFORMATION { | ||
ULONG NextEntryOffset; | ||
ULONG FileIndex; | ||
LARGE_INTEGER CreationTime; | ||
LARGE_INTEGER LastAccessTime; | ||
LARGE_INTEGER LastWriteTime; | ||
LARGE_INTEGER ChangeTime; | ||
LARGE_INTEGER EndOfFile; | ||
LARGE_INTEGER AllocationSize; | ||
ULONG FileAttributes; | ||
ULONG FileNameLength; | ||
ULONG EaSize; | ||
WCHAR FileName[1]; | ||
} FILE_FULL_DIR_INFORMATION, *PFILE_FULL_DIR_INFORMATION; | ||
|
||
typedef struct _IO_STATUS_BLOCK { | ||
union { | ||
NTSTATUS Status; | ||
PVOID Pointer; | ||
} u; | ||
ULONG_PTR Information; | ||
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; | ||
|
||
typedef VOID | ||
(NTAPI *PIO_APC_ROUTINE)( | ||
IN PVOID ApcContext, | ||
IN PIO_STATUS_BLOCK IoStatusBlock, | ||
IN ULONG Reserved); | ||
|
||
NTSYSCALLAPI | ||
NTSTATUS | ||
NTAPI | ||
NtQueryDirectoryFile( | ||
_In_ HANDLE FileHandle, | ||
_In_opt_ HANDLE Event, | ||
_In_opt_ PIO_APC_ROUTINE ApcRoutine, | ||
_In_opt_ PVOID ApcContext, | ||
_Out_ PIO_STATUS_BLOCK IoStatusBlock, | ||
_Out_writes_bytes_(Length) PVOID FileInformation, | ||
_In_ ULONG Length, | ||
_In_ FILE_INFORMATION_CLASS FileInformationClass, | ||
_In_ BOOLEAN ReturnSingleEntry, | ||
_In_opt_ PUNICODE_STRING FileName, | ||
_In_ BOOLEAN RestartScan | ||
); | ||
|
||
#define STATUS_NO_MORE_FILES ((NTSTATUS)0x80000006L) | ||
|
||
#endif |