Is there a tool that would show me for a specific file on disk, how fragmented it is? (How many seeks does physical disk need to make if I were to read that file in a linear fashion)
You can use DeviceIoControl
with FSCTL_GET_VOLUME_BITMAP
, FSCTL_GET_RETRIEVAL_POINTERS
and FSCTL_MOVE_FILE
, see Defragmenting Files.
You can also find different code examples if you search for FSCTL_MOVE_FILE
.
Here is one in C and another in .NET.
The Sysinternals tool contig with parameter -a
can do this for a file or all files in a folder and its subfolders.
You can use DeviceIoControl
with FSCTL_GET_VOLUME_BITMAP
, FSCTL_GET_RETRIEVAL_POINTERS
and FSCTL_MOVE_FILE
, see Defragmenting Files.
You can also find different code examples if you search for FSCTL_MOVE_FILE
.
Here is one in C and another in .NET.
filefrag is the tool you're looking for, if you're using Linux. Use -v parameter with filename to get detailed list of fragmentation. http://linux.die.net/man/8/filefrag
fsutil file queryallocranges offset=<o> length=<l> <file>
will show you the file's extents you will need admin rights.
And, of course, "fragmentation" is suspect:
- The file may be in pieces in the same cylinder. No seek overhead, just rotational latency. Or not as the pieces may be an optimal order (chances are near zero for this one).
- The file may be "contiguous" but across several cylinders. Even reading sequentially will result in seeks.
- The file may be on a stripe set and you have no idea where the boundaries are. You may skip to another controller, another spindle, or another partition on the same drive.
Be careful about what conclusions you draw.
© 2022 - 2024 — McMap. All rights reserved.