GetFileInformationByHandle followed by read with FILE_FLAG_NO_BUFFERING is extremely slow

Nazar Mokrynskyi 0 Reputation points
2024-03-05T07:28:31.0066667+00:00

I have an app that does pre-allocation of the file on disk using GetFileInformationByHandle to check if file already has correct size (here is the exact code in Rust) and then reads many tiny chunks of the file at random using FILE_FLAG_NO_BUFFERING.

The issue is that reads are ~10x faster before GetFileInformationByHandle is called than after even if the call didn't result in file size change. This makes zero sense to me. Reopening file withing the same process after calling GetFileInformationByHandle doesn't help either, only process restart.

Interestingly, GetFileInformationByHandleEx doesn't cause such issues.

I resorted to FILE_FLAG_NO_BUFFERING after discovering memory usage issues due to buggy caching in Windows.

Am I doing anything wrong or the whole file system layer in Windows is hopelessly broken?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,471 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nazar Mokrynskyi 0 Reputation points
    2024-03-15T16:48:28.4133333+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.