How to see fragmentation of a specific file?
Asked Answered
B

5

10

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)

Bedel answered 13/5, 2010 at 23:10 Comment(0)
M
10

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.

Maite answered 13/5, 2010 at 23:32 Comment(0)
C
17

The Sysinternals tool contig with parameter -a can do this for a file or all files in a folder and its subfolders.

Clippard answered 25/8, 2010 at 18:48 Comment(2)
@SmitJohnth, wow, was this still useful? I thought that with the SSD:s of today fragmentation was hardly an issue anymore.Clippard
SSD are still too expensive to store all crap on it even after prices for HDD have hardly fallen in the last years. I produced a big text file, tried to search in it and then noticed that it was too slow. I measured reading speen and then started to suspect something... Now it's fixed.Supposal
M
10

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.

Maite answered 13/5, 2010 at 23:32 Comment(0)
S
7

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

Srini answered 14/2, 2012 at 17:7 Comment(0)
W
3

fsutil file queryallocranges offset=<o> length=<l> <file> will show you the file's extents you will need admin rights.

Worked answered 25/8, 2010 at 18:25 Comment(1)
This only checks ranges for sparse files. If a file is solid but fragmented, it will show one piece.Ehrlich
P
3

And, of course, "fragmentation" is suspect:

  1. 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).
  2. The file may be "contiguous" but across several cylinders. Even reading sequentially will result in seeks.
  3. 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.

Purify answered 17/9, 2010 at 21:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.