This is the mail archive of the
cygwin
mailing list for the Cygwin project.
NTFS fragmentation
- From: Vladimir Dergachev <vdergachev at rcgardis dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 2 Aug 2006 18:33:04 -0400
- Subject: NTFS fragmentation
Hi all,
I have encountered a rather puzzling fragmentation that occurs when
writing files using Cygwin.
What happens is that if one creates a new file and writes data to it
(whether via a command line redirect or with a Tcl script - have not tried C
yet) the file ends up heavily fragmented.
In contrast, native Windows utilities do not exhibit this issue.
Someone suggested to me that Windows requires an expected file length
to be passed at the time of open, thus I searched on Google and
found "fsutil" program that allows to reserve space on the filesystem.
I attached a small Tcl script that, when run, creates two 30 MB files -
one using regular open/write pair (and which is fragmented into about 300
pieces on my system) and one using fsutil/open in append mode/seek 0 method.
To see the problem defragment your system, run the test script and then
run analyze and ask to view report. You will see a.dat at top of the list,
while b.dat never appears in the report.
Despite the workaround, it is still kinda hard for me to believe that
anyone has designed a filesystem that needs to know what is the file size
going to be - especially for a single program writing on an almost empty
disk. Perhaps there is some sort of environment variable that I need to set ?
Any suggestions and comments would be greatly appreciated.
Please CC me - I am not on the list.
thank you very much
Vladimir Dergachev
#!/usr/bin/env tclsh
foreach {var value} {
FRAGMENTED_FILE "a.dat"
CONTIGUOUS_FILE "b.dat"
FILE_SIZE 30000000
BUFFER_SIZE 1000000
} {
global $var
set $var $value
}
proc fragmented_write { filename size buffersize } {
puts stderr "DELETING $filename"
file delete $filename
puts stderr "fragmented_write $filename"
set F [open $filename "w"]
fconfigure $F -buffering full -buffersize buffersize
for { set i 0 } { $i < $size } { incr i } {
puts -nonewline $F "X"
}
close $F
puts stderr "closing $filename"
}
proc contiguous_write { filename size buffersize } {
puts stderr "DELETING $filename"
file delete $filename
puts stderr "preallocating $filename"
exec fsutil file createnew [file nativename $filename] $size
puts stderr "contiguous_write $filename"
set F [open $filename "a"]
fconfigure $F -buffering full -buffersize buffersize
seek $F 0 start
for { set i 0 } { $i < $size } { incr i } {
puts -nonewline $F "X"
}
close $F
puts stderr "closing $filename"
}
fragmented_write $FRAGMENTED_FILE $FILE_SIZE $BUFFER_SIZE
contiguous_write $CONTIGUOUS_FILE $FILE_SIZE $BUFFER_SIZE
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/