14

In the default autoexec.bat for DOS 6.22, you see these lines:

C:\DOS\SMARTDRV.EXE /X
@ECHO OFF
PROMPT $P$G
PATH C:\DOS
SET TEMP = C:\DOS

According to this source, /X disables write-behind caching. Write-behind caching is when the computer writes to the cache after a certain amount of time.

Why is write-behind cache disabled in DOS by default?

5
  • 6
    Write-behind caching is where the cache writes to the disk after a certain amount of time. But to the question, I'd guess, in a hand-wavy way, that having SMARTDRV cache data and the disk cache data could lead to coherency problems.
    – dave
    Commented May 29, 2021 at 22:30
  • 2
    @another-dave They're on different abstraction levels. Disk knows nothing about data cached inside smartdrv's memory and not physically sent to drive yet and smartdrv intercepts everything sent to be written to disk. So there's no different sources of data to write and introduce inconsistencies, unless you deliberately go low level enough to explicitly bypass smartdrv. Commented May 31, 2021 at 9:23
  • 1
    I'd supposed that it was disabling caching that was part of the on-disk controller; I recall there were such things at the time.
    – dave
    Commented May 31, 2021 at 13:40
  • 1
    DOS users were accustomed to being able to turn off the computer by removing the power as soon as the DOS prompt was shown. Any cache entries not yet written to disk would then be lost. Commented Jun 1, 2021 at 9:59
  • 1
    @ThorbjørnRavnAndersen not in MS-DOS 6.22 though (the cache was flushed before the prompt was shown). Commented Jun 5, 2021 at 20:39

3 Answers 3

25

It's quite simple: write-behind caching means that after you have (for example) saved a file in a word processor, the saved file may live in the cache in RAM for a while before being written to the disk. If the computer crashes during that time, or is just switched off without using some command that flushes the cache to disk, then the file will be lost, or will still exist in its previous version. Worse still, if only some of the blocks of the file have been written, it will be a garbled mixture of the old and new versions.

Without caching (or with write-behind disabled) you can be sure that any saved file will have actually made it to the disk in a short time, so that waiting for a couple of seconds, or waiting for the disk light to stop flashing, before switching off the machine would ensure that the work was properly saved. With MS-DOS, it was normal to switch off the machine without any shutdown procedure.

As Stephen Kitt notes in another answer, SmartDrive would make sure the cache was flushed after exiting an application before the DOS prompt was shown again, making it safe to exit the program and then switch off. What wouldn't be safe would be to save a file and then switch the machine off without exiting the program. This behaviour of SmartDrive made it safer but a bit less effective, because a sequence of DOS commands (maybe from a batch file?) couldn't benefit from write caching between one command and the next.

The risk of crashes or unplanned shut-downs makes it safer to disable write-behind caching as the default setting, so that the cache is used only to hold copies of blocks on the disk that have been recently read or written. Even this use of a RAM cache is highly effective in speeding up average access times, because a typical workload would contain ten times as many block reads (for programs, input files, fonts, etc.) as block writes.

7
  • 1
    In my childhood experience, not adding /X was not so much of a problem with HDD as it was with floppies. In many cases, instinctually, one would pop out the floppy and lose data if it wasn't yet written it back using /C. Nevertheless, floppy writes seemed "blazingly fast" without the /X option! and was a go-to idea if you wanted to show off to your friends :D With HDDs, one would usually remember to write back the cache before shutting down.
    – user21908
    Commented May 30, 2021 at 9:22
  • 3
    @Aravindh SMARTDrive didn’t cache writes to floppies even if /X wasn’t specified. The acceleration came from caching reads, not writes. Commented May 30, 2021 at 15:12
  • 1
    @StephenKitt I see, thank you! I remember floppy writes being cached but it could just be a false memory. I was quite young when using SMARTDRV...
    – user21908
    Commented May 30, 2021 at 20:11
  • 1
    @Aravindh it was possible to force caching on floppy drives, with SMARTDRV A+ for example; perhaps that was the case on the machine you remember! Commented May 30, 2021 at 20:35
  • 5
    @AravindhKrishnamoorthy Another reason to not write back to floppies is that floppy media tend to be less reliable (if handled by the average user) than hard drive media. If SMARTDRV tries to write back later, it can't just return an error to the application, that hopefully shows an error message to the user. Instead, it displays a scary full-screen message trying to explain why data just got lost, and that nothing can be done about it. Commented May 30, 2021 at 20:55
19

The /X flag was specified by default in MS-DOS 6.22 at least. (See further down for the detailed history.)

What /X does is disable the write-back cache in all cases. The write-back cache is used to store data being written to a device, allowing programs to continue working while the data is written. This introduces the risk that, if power is lost or the computer crashes before the data is written, data will be lost, even though the program writing it and the user are under the impression that it’s safe. This is particularly relevant in DOS since there is no enforced shutdown procedure¹ and many users weren’t all that careful with how they powered their computers down (or rebooted them).

There are a number of subtleties which come into play here:

  • SMARTDrive disables the write cache on removable devices by default, even without the /X flag, so writing to a floppy and ejecting it is safe – once the drive light goes off at least;
  • SMARTDrive, along with all other well-behaved caches, ensures that all the data waiting to be written is written before returning to the DOS prompt, and this was the documented shutdown procedure: users were supposed to return to the DOS prompt before powering their system down (but see the history below).

Thus, by default (with no flags), SMARTDrive was safe for users following recommended practice, and SMARTDRV did not have to be started with /X. Presumably Microsoft realised that that wasn’t sufficient, because even a small number of users not following recommended practice and losing data was too much, and thus added the /X switch to the default configuration in AUTOEXEC.BAT.

On a system running SMARTDrive, invoking SMARTDRV will show the current configuration, including cache information:

C:\>smartdrv
Microsoft SMARTDrive Disk Cache version 5.01
Copyright 1991,1993 Microsoft Corp.

Cache size:  2 097 152 bytes
Cache size while running Windows:  2 097 152 bytes

            Disk Caching Status
drive   read cache   write cache   buffering
--------------------------------------------
  A:       yes           no           no
  B:       yes           no           no
  C:       yes           yes          no
Write behind data will be committed before command prompt returns.


For help, type "Smartdrv /?".

The /X switch can be used to disable write-back caches even if SMARTDrive was initially loaded with the caches enabled.

To understand why the /X flag exists, and isn’t the default, some history is necessary. Microsoft provided a brief summary in Q127021: SMARTDrive Version History, and the salient points are as follows:

  • write caching was introduced in SMARTDrive 4.0, which shipped with Windows 3.1 and 3.11 (not for Workgroups); this enabled the write cache by default, without any special provisions for flushing it (although the commit cache function was implemented);
  • MS-DOS 6.0 shipped with SMARTDrive 4.1, which added support for DoubleSpace, still with no “prompt flushing” and contributed to DoubleSpace’s terrible reputation;
  • SMARTDrive 4.2 was released as an interim release (PD0805), adding the /X flag and ensuring that caches were flushed before the DOS prompt was displayed.

So SMARTDRV, with no switches, always enables write caching at least on hard drives; one can only guess why the default wasn’t switched to /X, and instead the latter was added to the default AUTOEXEC.BAT invocation (Microsoft’s overriding drive for backwards compatibility presumably plays a role). Significantly, for a little while, waiting for the DOS prompt wasn’t safe.

(Later versions of 4DOS include explicit support for cache flushes, controlled by the SDFlush configuration setting, and the documentation claims that “Under PC DOS 6.1 and above, and MS-DOS 6.20 and above, COMMAND.COM instructs SMARTDRV to write all cached data to the disk before the command prompt is displayed.” I haven’t found any evidence of explicit support in COMMAND.COM, and I think that the general hook used in SMARTDrive 4.2 is how this was implemented in later versions too. This has been described somewhere but I haven’t found the reference yet.)

Note that all this only describes the cache provided by SMARTDrive itself, i.e. an area of RAM reserved to provide caches for the system’s drives. Drives can have their own caches, which SMARTDrive doesn’t control; back when SMARTDrive was still relevant, hard drives had tiny caches (the 1996 Quantum Fireballs had a whopping 128KiB of cache, which was large at the time; the 1998 IBM DeskStars increased that to 512KiB!) and those caches were write-through.


¹ Enforced meaning that the operating system complains vocally if it isn’t followed.

0
11

There is no “shutdown” process/command in DOS. You just cut the power at the end of your work. That was fine when PCs were simple, your storage options was either One Floppy or Two Floppies, and DOS never touched the disks when waiting at the command prompt. Things like Write Behind Caches make things more complicated and human habits die hard.

Write behind cache would lead to file corruption if you didn’t have the discipline to wait for the cache to flush before shutting down.(*)

In fact, I’ve known people who didn’t even bother closing the program: they would just finish entering data in say Lotus 1-2-3, type the Save command, wait for the disk light to stop and BANG hit the power switch. No amount of complaining on my part made a dent. I even saw the same habit with Windows, especially Windows 3.1 and earlier.

Now a bit of speculation: Microsoft must have added Write Behind cache to SmartDrive as ON by default in the original version. Once the complains came in about lost files and it became clear that Write Behind was too dangerous for the “uninitiated”, they must have felt they couldn’t change the default behavior without causing even more trouble, so they instead relied on Setup to add the /X parameter by default.

(*) I don’t remember if hard drives at the time were all smart enough to protect the disks during all power shutdown scenarios, so you might even risk media damage. I know early hard drives came with a “Park” command you were supposed to run to move the head to a safe location before shutting down (and yes I also know people who ignored it anyway). But that didn’t last very long and auto-parking drives became standard pretty quickly, so I presume it wasn’t a significant risk. However I suppose it’s possible even some auto-parking drives could have caused damage to the platters if power failed during writes.

2
  • 3
    To mitigate the "the drive light is off, so I can turn off the computer now" problem, most DOS write-behind caches auto-flush (by default) when the command prompt is displayed. So if the user terminates the application and waits for the DOS prompt to appear, there is no risk of data loss. Commented May 30, 2021 at 7:57
  • 2
    The "parking" process was not required on every shutdown. There was no relevant risk of media damage by just spinning down and spinning up again. Parking was recommended when you intended to physically move the machine, because that could cause the heads to bang onto the platter. That better happened in an area designed to withstand it and not having any data on it. Commented May 30, 2021 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .