Any tools to FRAGMENT the drive

glugglug

Diamond Member
Jun 9, 2002
5,340
1
81
I'm looking for a utility to fragment the drive, especially the free space, to test whether certain performance issues we are seeing are due to delays accessing new memory allocations because the disk cache takes longer to flush with free space fragmentation.

Are there any for NTFS?
 

gorcorps

aka Brandon
Jul 18, 2004
30,741
456
126
Oh yeah there's this sweet program called "Daily Use" that does just what you're looking for. However if that's not fast enough then you can install/uninstall a bunch of programs to get the drive nice and messed up.
 

QuixoticOne

Golden Member
Nov 4, 2005
1,855
0
0
Eh there are some tools but the exact way you want it done is usually somewhat dependent on yourt local situation. Usually I just use a quick hack like the following.

It'll take a while to run and has to use up most of your free space (tune the parameters accordingly) on the drive it runs on while it works and has to keep about half of that space in use afterward to preserve the allocated space fragments that force the free space to be fragmented.

Code:
@echo off

REM FRAGMENT THE DISK BY MAKING APPROXIMATELY 1 Million directories each containing
REM some amount of data (say around 1MByte), then go back and delete half of those.
REM One will typically end up with half of one's previously free disk space in use by files,
REM and the other half of one's previously available disk space free but fragmented into free size pieces
REM approximately less than the amount of data copied into each subdirectory.

MD FRAG
CD FRAG

REM GENERATE THE FULL MILLION DIRECTORIES
SET LISTA=0 1 2 3 4 5 6 7 8 9
SET LISTB=0 1 2 3 4 5 6 7 8 9
SET LISTC=0 1 2 3 4 5 6 7 8 9
SET LISTD=0 1 2 3 4 5 6 7 8 9
SET LISTE=0 1 2 3 4 5 6 7 8 9
SET LISTF=0 1 2 3 4 5 6 7 8 9

SET HALFA=0 2 4 6 8
SET HALFB=0 2 4 6 8
SET HALFC=0 2 4 6 8
SET HALFD=0 2 4 6 8
SET HALFE=0 2 4 6 8
SET HALFF=0 2 4 6 8

REM SKIP MOST OF THE SEQUENCE FOR QUICK TESTING
REM SET LISTA=0 3 6 9
REM SET LISTB=0 3 6 9
REM SET LISTC=0 3 6 9
REM SET LISTD=0 3 6 9
REM SET LISTE=0 3 6 9
REM SET LISTF=0 3 6 9

REM SET HALFA=0 6
REM SET HALFB=0 6
REM SET HALFC=0 6
REM SET HALFD=0 6
REM SET HALFE=0 6
REM SET HALFF=0 6

echo F > A.DAT

REM 40 bytes
COPY A.DAT+A.DAT+A.DAT+A.DAT+A.DAT+A.DAT+A.DAT+A.DAT+A.DAT+A.DAT B.DAT

REM 400 bytes
COPY B.DAT+B.DAT+B.DAT+B.DAT+B.DAT+B.DAT+B.DAT+B.DAT+B.DAT+B.DAT C.DAT

REM 4K bytes
COPY C.DAT+C.DAT+C.DAT+C.DAT+C.DAT+C.DAT+C.DAT+C.DAT+C.DAT+C.DAT D.DAT

REM 40KB
COPY D.DAT+D.DAT+D.DAT+D.DAT+D.DAT+D.DAT+D.DAT+D.DAT+D.DAT+D.DAT E.DAT

REM 400KB
COPY E.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT F.DAT

REM 1MB
COPY F.DAT+F.DAT+E.DAT+E.DAT+E.DAT+E.DAT+E.DAT M.DAT

REM 4MB
REM COPY F.DAT+F.DAT+F.DAT+F.DAT+F.DAT+F.DAT+F.DAT+F.DAT+F.DAT+F.DAT G.DAT

REM 40MB
REM COPY G.DAT+G.DAT+G.DAT+G.DAT+G.DAT+G.DAT+G.DAT+G.DAT+G.DAT+G.DAT H.DAT

REM 400MB
REM COPY H.DAT+H.DAT+H.DAT+H.DAT+H.DAT+H.DAT+H.DAT+H.DAT+H.DAT+H.DAT I.DAT

REM 4GB
REM COPY I.DAT+I.DAT+I.DAT+I.DAT+I.DAT+I.DAT+I.DAT+I.DAT+I.DAT+I.DAT J.DAT

REM 40GB
REM COPY J.DAT+J.DAT+J.DAT+J.DAT+J.DAT+J.DAT+J.DAT+J.DAT+J.DAT+J.DAT K.DAT

REM SELECT HOW MUCH DATA TO SPEW INTO EACH SUB-DIRECTORY
REM MAKE THIS a bit under 1/1000000th the amount of free disk space you have.
FOR %%F IN (A B C D E M) DO COPY %%F.DAT %%F.SPEW > NUL:

REM MAKE A MASTER FRAGMENT SPEW DIRECTORY
MD SPEW

REM MAKE A TOP LEVEL 1000 DIRECTORIES UNDER THAT
FOR %%A IN (%LISTA%) DO FOR %%B IN (%LISTB%) DO FOR %%C IN (%LISTC%) DO MD SPEW\%%A%%B%%C

REM MAKE A SECOND LEVEL 1000 DIRECTORIES PER TOP LEVEL DIRECTORY
FOR %%A IN (%LISTA%) DO FOR %%B IN (%LISTB%) DO FOR %%C IN (%LISTC%) DO FOR %%D IN (%LISTD%) DO FOR %%E IN (%LISTE%) DO FOR %%F IN (%LISTF%) DO MD SPEW\%%A%%B%%C\%%D%%E%%F

REM SPEW THE SELECTED AMOUNT OF DATA FILES INTO EACH OF THE DIRECTORIES
FOR %%A IN (%LISTA%) DO FOR %%B IN (%LISTB%) DO FOR %%C IN (%LISTC%) DO FOR %%D IN (%LISTD%) DO FOR %%E IN (%LISTE%) DO FOR %%F IN (%LISTF%) DO COPY *.SPEW SPEW\%%A%%B%%C\%%D%%E%%F > NUL:

REM DELETE HALF (EVERY OTHER) OF THE DIRECTORIES/DATA WE JUST CREATED TO GET BACK SOME VERY FRAGMENTED DISK SPACE
FOR %%A IN (%HALFA%) DO FOR %%B IN (%HALFB%) DO FOR %%C IN (%HALFC%) DO FOR %%D IN (%HALFD%) DO FOR %%E IN (%HALFE%) DO FOR %%F IN (%HALFF%) DO RD /S /Q SPEW\%%A%%B%%C\%%D%%E%%F