Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to index page
Thread view  Board view
georgpotthast

Homepage

Germany,
26.09.2010, 21:37
 

DOS copy command (Developers)

I am testing with MS-DOS 7.0. When I use the DOS copy command to copy a file of 515 MB to a different name on the same disk it takes about 20 seconds.

I wrote a small test program in assembler which opens and then reads the same file in 64k blocks using function 3Fh. It does not write the file to a different name, just reads it. This program takes 77 seconds just to read the file.

Why is copy that much faster and how am I able to access the file just as fast as copy?

Georg

ecm

Homepage E-mail

Düsseldorf, Germany,
26.09.2010, 23:46

@ georgpotthast
 

DOS copy command

> Why is copy that much faster and how am I able to access the file just as
> fast as copy?

Are you actually in DOS, or is Windows running? I imagine COPY might call Windows-specific interfaces (or a redirector "copy file" call, which might be hooked by Windows) so that the low-level data copying can be done faster by only using Windows code. This would cause a comparison of 21.3F's and COPY's performance inside Windows to be useless. (Potentially, there could even be more efficient undocumented functions for this in EMM386 or the kernel itself. Though I don't remember any such functions right now.)

COPY possibly aligns calls on clusters or something, but (A) ostensibly there are no (MS-)DOS interfaces that can read/write more than 64 KiB and (B) your cluster size probably is less than 64 KiB anyway so that this shouldn't give COPY an advantage. It might still be useful to know what file system and cluster size you use, and/or how this file system is accessed by DOS (redirector, block device on Int13, etc).

Maybe your code is slower somehow. Could you post it here? A simple program to read a file should not be longer than a few lines so we could easily check it.

A definite answer can possibly only be obtained by reverse-engineering the relevant code in COPY (which is a part of COMMAND.COM), and comparing that with your code. You might want to do that yourself with a disassembler or debugger.

---
l

Japheth

Homepage

Germany (South),
27.09.2010, 02:06

@ georgpotthast
 

DOS copy command

> Why is copy that much faster and how am I able to access the file just as
> fast as copy?

The block size of 64 kB may be a problem. Try 32 kB!

---
MS-DOS forever!

georgpotthast

Homepage

Germany,
27.09.2010, 21:28

@ georgpotthast
 

DOS copy command

Thank you for your suggestions! It is always helpful to ask the experts.:-)

No, I am not running in a Windows DOS box. Its even faster there, it just takes 15 seconds on the first copy and 6 on the second copy since Windows already has the entire file in its memory then.

I tried 32k, but this made it a little bit slower.

However, the cluster size was a good point. My cluster size is 20 sectors per cluster. So when I select 61440 bytes which is 6 clusters instead of the former 64k, the program runs just as fast as copy!

Georg

ecm

Homepage E-mail

Düsseldorf, Germany,
27.09.2010, 21:40

@ georgpotthast
 

DOS copy command

> However, the cluster size was a good point. My cluster size is 20 sectors
> per cluster. So when I select 61440 bytes which is 6 clusters instead of
> the former 64k, the program runs just as fast as copy!

Ah well. What kind of file system is this? I thought "sectors per cluster" for FAT file systems need to be a power of two - at least, to be compatible to (MS-)DOS. There is a field in an internal structure that suggests this. If it is a FAT file system (and you ain't using a special driver), did you format it using the default MS-DOS utilities or a specialized program? In the latter case, does it work well with MS-DOS?

---
l

georgpotthast

Homepage

Germany,
27.09.2010, 22:46

@ ecm
 

DOS copy command

You immediately spotted my error. The cluster size is 20h sectors or 32 in decimal - FAT32. I tried it again with 65.024 bytes which is 127 sectors and it run just as fast. Maybe DOS caches the sectors up to the number of 4 clusters and this makes it fast.

Georg

bretjohn

Homepage E-mail

Rio Rancho, NM,
28.09.2010, 00:15

@ georgpotthast
 

DOS copy command

The default DOS "cache" is controlled by the BUFFERS statement in CONFIG.SYS, so playing with that setting will probably make a huge difference in how fast everything works (assuming you're not using an external cache like SMARTDRV or LBACACHE or ...).

Also, according to MS-DOS 6.2 HELP, you can give BUFFERS two different numbers:

BUFFERS=n[,m]

where m is the size of the secondary cache. Does anybody have any idea how MS-DOS uses a two-stage cache? HELP doesn't really explain it, but indirectly refers to the secondary buffer cache in the context of SMARTDRV (and possibly double-buffering?).

ecm

Homepage E-mail

Düsseldorf, Germany,
28.09.2010, 01:16
(edited by cm, 28.09.2010, 01:27)

@ bretjohn
 

DOS copy command

> Also, according to MS-DOS 6.2 HELP, you can give BUFFERS two different
> numbers:
>
> BUFFERS=n[,m]
>
> where m is the size of the secondary cache. Does anybody have any idea how
> MS-DOS uses a two-stage cache? HELP doesn't really explain it, but
> indirectly refers to the secondary buffer cache in the context of SMARTDRV
> (and possibly double-buffering?).

I've seen sites that state the "secondary cache" is only useful for 8086 CPUs - however, that might be related to SMARTDRV (is it unable to run on 8086?). It is apparently recommended to leave the "secondary cache" unused if SMARTDRV (or another cache) is used. Apparently the setting is limited to 0..8, or at least that's what some sites say.

I vaguely remember it to be some kind of look-ahead cache, but I don't remember where I read that and didn't find any source supporting that claim right now. So that might be wrong.

EDIT: Also here's some stuff Eric sent us per mail for whatever reason:

> Hi, a comment on the dos copy command threat: Try first setting
> the file to the right size (seek to end-1, write a byte, close)
> and then reopen the file and start writing data, for example in
> 32k blocks, taking care that the 32k buffer does not wrap around
> a multiple of 64k in terms of linear address / DMA boundary. The
> idea is that setting the final size immediately avoids having to
> update the FAT again later: The file size does not change later,
> while it would change all the time if starting with an empty file
> and appending data to it until all content is there...
>
> Eric

Good call, at least setting the size initially. Does COPY do this? It should. (What about FreeCOM's COPY, and FD's XCOPY?)

EDIT:

Ah well Bret. Try this (search for "secondary cache"). Though I'd guess Richard doesn't know more than that either.

---
l

Rugxulo

Homepage

Usono,
28.09.2010, 05:37

@ ecm
 

DOS copy command

It seems the fastest method(s) are as follows:

* copy while only reading in one pass, avoiding spurious reads (a la TurboCopy)
* XMS (a la MS-DOS 6.2+ XCOPY? or ZCOPY)
* 32-bit, aligned code, optimized appropriately (a la NDN)
* SMARTDRV etc. (a la LBACACHE)
* DMA, UDMA (a la UIDE)
* direct sector manipulation (TurboCopy ???)

Well, xWCopy is pretty fast too, and it doesn't really do it optimally at all, nor RxCopy, IIRC. So who knows, who cares, only for really big files does it even matter. Patience is a virtue. ;-)

EDIT: I think FD DISKCOMP (and/or DISKCOPY ??) uses MD5 to avoid re-reading too much.

Rugxulo

Homepage

Usono,
28.09.2010, 22:40

@ ecm
 

DOS copy command

> EDIT: Also here's some stuff Eric sent us per mail for whatever reason:

Here's some more, for completeness:

> On one hand, FreeDOS
> does not implement secondary caches in the kernel. On the other
> hand, you can use TICKLE together with LBACACHE for readahead...
>
> Make sure to read the docs or at least /? screens to use options
> properly, you have to enable e.g. lba harddisk readahead manually.
>
> I think the cache by Jack also had something with readahead? And
> of course it is quite possible that your disk has it built in so
> you only have to wait for the piece by piece transfer while the
> disk already buffered larger chunks in the RAM inside the drive.
>
> Of course it is faster to do a real readahead. You could even set
> the "cooling" temperature mode of LBACACHE, do a dir /s or do e.g.
> chkdsk or dosfsck, and then switch back to normal temperature, to
> force the FAT and DIR data into the cache before copying.
>
> Anyway... My theory is still that seeks and small writes to the
> FAT are what makes copying slower, so tweaking read speed or the
> speed of file content read / write may have only small effects.
>
> As usual, you can try whether a write pooling or delayed write
> cache helps you, for example the NWCACHE from DRDOS... You can
> probably find some suggested command line options for that in
> your mail archives and the freedos mailing list archives... ;-)

Rugxulo

Homepage

Usono,
30.09.2010, 06:51

@ Rugxulo
 

DOS copy command

> > I think the cache by Jack also had something with readahead?

Apparently not (nor needed either), says Jack.

BTW, newer (ESATA? SATA II? SSD?) hard drives are weird. I don't know the details, obviously, but some even have something like 4 kb for genuine sectors and internal caches and just emulate 512 bytes for compatibility (or something dumb, see Linux FS discussions for details). Yeah, it's very arcane, very annoying. In short, who cares, if it works, it works! ;-)

georgpotthast

Homepage

Germany,
30.09.2010, 19:59

@ Rugxulo
 

DOS copy command

I had a SATA disk connected to a SATA 6 Gb/s (III) port and it run rather slow with DOS. When I connected the disk to a SATA 3 Gb/s (II) port it run faster, however, my impression is that it is still slower than on my other PC with IDE.

tom

Homepage

Germany (West),
01.10.2010, 15:12

@ georgpotthast
 

DOS copy command

> I had a SATA disk connected to a SATA 6 Gb/s (III) port and it run rather
> slow with DOS. When I connected the disk to a SATA 3 Gb/s (II) port it run
> faster, however, my impression is that it is still slower than on my other
> PC with IDE.

a) whatever 'rather slow', 'faster', and 'still slower' means.
use http://www.drivesnapshot.de/freedos/rawread.htm or similar to discuss disk speed.

b) read speed is entirely up to your BIOS. if the BIOS doesn't support 6Gb/s but only 3Gb/s, you won't see 6 Gb/s.
somewhat similar to usage of UDMA mode which only very few BIOS vendors supported until only recently.

georgpotthast

Homepage

Germany,
02.10.2010, 22:56

@ tom
 

DOS copy command

Hi Tom,

thank you for the link! Rawread is a very helpful utility. Yes, I had not tested it properly and rawread shows that the SATA II connection is 35% faster than the IDE.

Georg

RayeR

Homepage

CZ,
08.10.2010, 10:10

@ georgpotthast
 

DOS copy command

On SATA, the speed under DOS is limited by quality of IDE mode emulation (chipset + BIOS + SMI code?). I tested the speed on intel ICH7 and ICH10, where ICH7 was significantly faster than newer ICH10. They simply don't care about legacy stuffs just be happy you have some IDE mode at all. Probably newer ICHs will drop this compatability :( ...

---
DOS gives me freedom to unlimited HW access.

nidud

E-mail

Norway,
03.10.2010, 17:17

@ ecm
 

DOS copy command

> Hi, a comment on the dos copy command threat: Try first setting
> the file to the right size (seek to end-1, write a byte, close)
> and then reopen the file and start writing data, for example in
> 32k blocks, taking care that the 32k buffer does not wrap around
> a multiple of 64k in terms of linear address / DMA boundary. The
> idea is that setting the final size immediately avoids having to
> update the FAT again later: The file size does not change later,
> while it would change all the time if starting with an empty file
> and appending data to it until all content is there...
>
> Eric

I did a brief test by setting the size of the default.$$$ to the same size as the default.zip prior to add a file to the archive. The file size will change later, but the copying prior to the adding takes a long time, and this increase for each file in the loop.

\doszip\src\clib\zip\wzipadd.asm:

    wzipadd_copylocal:
        xor     ax,ax
        mov     local_size_ax,ax
        mov     local_size_dx,ax
        inc     ax
        cmp     copy_fast,al
        jne     wzipadd_copyslow
  ifdef ERIKS_FASTCOPY
        mov     ax,4200h + SEEK_END     ; get .ZIP file size
        mov     bx,STDI.ios_file
        xor     cx,cx
        mov     dx,cx
        int     21h
        jc      wzipadd_error
        push    dx
        push    ax
        mov     ax,4200h + SEEK_SET     ; back to start..
        mov     bx,STDI.ios_file
        xor     cx,cx
        mov     dx,cx
        int     21h
        pop     dx
        pop     cx
        or      cx,cx
        jnz     wzipadd_size_ok
        cmp     dx,16
        jb      wzipadd_skip            ; skip if < 16 byte
    wzipadd_size_ok:
        sub     dx,1
        sbb     cx,0
        mov     ax,4200h + SEEK_SET     ; seek outfile to size-1
        mov     bx,STDO.ios_file
        int     21h
        jc      wzipadd_error
        mov     bx,STDO.ios_file
        mov     cx,1
        mov     ax,4000h                ; write one byte
        int     21h
        jc      wzipadd_error
        mov     ax,4200h + SEEK_SET     ; back to start..
        mov     bx,STDO.ios_file
        xor     cx,cx
        mov     dx,cx
        int     21h
    wzipadd_skip:
  endif


This reduced the compression time from 455 to 180 sec.

georgpotthast

Homepage

Germany,
28.09.2010, 21:04

@ bretjohn
 

DOS copy command

I found a description of the buffers command in "QUE - Using MS-DOS 6.2". I try to upload this as an image.

Georg

[image]

[image]

ecm

Homepage E-mail

Düsseldorf, Germany,
29.09.2010, 14:05

@ georgpotthast
 

DOS copy command

> I found a description of the buffers command in "QUE - Using MS-DOS 6.2".

Thanks, that explains it to me somewhat.

---
l

DOS386

13.10.2010, 04:02

@ georgpotthast
 

DOS copy command | FATPLUS.EXE

> I am testing with MS-DOS 7.0

This looks like Windaube (as already pointed above)

> When I use the DOS copy command to copy a file of 515 MB to a different
> name on the same disk it takes about 20 seconds.

> I wrote a small test program in assembler which opens and then reads the
> same file in 64k blocks using function 3Fh. It does not write the file to a
> different name, just reads it. This program takes 77 seconds just to read

Why don't you use my infamous FATPLUS.EXE tool to test ?

Known DOS issues:

- File reading is almost as fast as raw sector reading
- File writing is cca 3 times slower than file reading or raw sector writing, but depends from DOS version (EDR-DOS faster than FreeDOS) , FAT subversion, and cluster size (bigger is better)
- Very poor writing performance (more than 10 times slower) with small blocks (4 KiB ??? or less ???) in some cases with both FreeDOS and EDR-DOS

FATPLUS.EXE issues:

- Abandoned, there will be no updates
- Codebase is obsolete and crappy, no source will be ever released
- No progress indicator
- No performance calculation

Features:

- (CL) Public Domain
- Supports files up to 256 GiB
- Reports time consumed


FATPLUS C XXX 99'999'999'999

---
This is a LOGITECH mouse driver, but some software expect here
the following string:*** This is Copyright 1983 Microsoft ***

Back to index page
Thread view  Board view
22049 Postings in 2034 Threads, 396 registered users, 240 users online (0 registered, 240 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum