[sclug] performance puzzle

Alex Butcher lug at assursys.co.uk
Sun Jul 10 22:12:49 UTC 2005


On Sun, 10 Jul 2005, Tom Dawes-Gamble wrote:

> On Sun, 2005-07-10 at 19:34 +0100, Alex Butcher wrote:
>
>> One thing I'm not clear about; is this an actual problem you're
>> experiencing, or /just/ a puzzle?
>>
>
> Just  puzzle hence the subject.
>
>> Also, can you run 'du -sch' on all the files in the test, please?
>>
> # du -sch *
> 1.1G    bar
> 1.1G    baz
> 16K     fast
> 16K     foo
> 16K     lost+found
> 2.1G    total
>
> :-)

As I (eventually :) thought, foo and fast have holes in them caused by
seeking whilst writing:

#include    <sys/types.h>
#include    <sys/stat.h>
#include    <fcntl.h>
#include    <stdio.h>
#include    <stdlib.h>
//#include    "ourhdr.h"

char    buf1[] = "abcdefghij";
char    buf2[] = "ABCDEFGHIJ";

int
main(void)
{
     int     fd;

     if ( (fd = creat("file.hole", O_RDWR)) < 0)
         fprintf(stderr,"creat error");

     if (write(fd, buf1, 10) != 10)
         fprintf(stderr,"buf1 write error");
     /* offset now = 10 */

     if (lseek(fd, 10485760, SEEK_SET) == -1)
         fprintf(stderr,"lseek error");
     /* offset now = 40 */

     if (write(fd, buf2, 10) != 10)
         fprintf(stderr,"buf2 write error");
     /* offset now = 50 */

     exit(0);
}

(Borrowed from Stevens)

>> I have my suspicions as to what you're doing (or, more specifically, what
>> the creation tool is doing) but unfortunately, my discs are not slow enough
>> to replicate the speed differential. :-P
>
> Now you should be able to do it.  :-)

$ ~/hole
$ ls -Al
total 20
----------  1 alex alex 104857610 Jul 10 23:07 file.hole
$ chmod 600 file.hole
$ time dd if=file.hole of=/dev/null bs=1024
102400+1 records in
102400+1 records out

real    0m0.513s
user    0m0.093s
sys     0m0.340s
$ time dd if=file.hole of=file.copy bs=1024
102400+1 records in
102400+1 records out

real    0m1.050s
user    0m0.098s
sys     0m0.643s
$ time dd if=file.copy of=file.copy2 bs=1024
102400+1 records in
102400+1 records out

real    0m5.399s
user    0m0.101s
sys     0m0.603s
$ for i in *; do time md5sum $i; done
627dcbeba8769ee02ec24197a9d44580  file.copy

real    0m2.705s
user    0m0.482s
sys     0m0.135s
627dcbeba8769ee02ec24197a9d44580  file.copy2

real    0m2.356s
user    0m0.478s
sys     0m0.122s
627dcbeba8769ee02ec24197a9d44580  file.hole

real    0m0.803s
user    0m0.498s
sys     0m0.219s
$ du -sch file.*
101M    file.copy
101M    file.copy2
20K     file.hole
201M    total

Just, but it needs the order of hundreds of megabytes to be apparent. ;-)

> tom.

Best Regards,
Alex.
-- 
Alex Butcher      Brainbench MVP for Internet Security: www.brainbench.com
Bristol, UK                      Need reliable and secure network systems?
PGP/GnuPG ID:0x271fd950                         <http://www.assursys.com/>


More information about the Sclug mailing list