From: mmshah@im.lcs.mit.edu (Milan Shah)
Newsgroups: comp.windows.ms
Subject: Re: Fastdisk or 32 bit access in Win 3.1
Date: 17 Apr 92 05:53:17 GMT
	<1992Apr16.184941.22516@news.Hawaii.Edu>
Organization: MIT Lab for Computer Science



>WHAT IS FASTDISK FOR?
>At the moment, FASTDISK is used only in 386 enhanced mode for
>fast access of virtual memory (the swapfile).  FASTDISK will
>not speed up any disk operations that don't use virtual memory.

There is an excellent discussion of FASTDISK in the Windows Resource
Toolkit (which I downloaded from cica's upload directory). There it
explains exactly why FASTDISK can be expected to both speed up regular
applications that make standard IO calls, and why it enhances virtual
memory.

In a nutshell, the picture looks like this:

  ------------------------------------------
  | 0    Windows Protect Mode Software     |----------\ (Fastdisk)
  ------------------------------------------     -------
     /\        \/  /\        \/-- this guy       | HD Controller
  ------------------------------------------     ------
  | 1 VMM_A | 2 DOS    | 3 BIOS            |----------/ (No Fastdisk)
  ------------------------------------------

In the picture above, you have either windows apps running in the 
Virtual Machine Monitor, or VMM, (1) or a DOS app in that VMM. Either 
could be running along, and then it issues an INT 21 to do some disk IO.

When it issues the Interrupt instruction, control is transferred to
the protect mode software (0). This software determines that this is a
Disk IO request, so it 'reflects' the interrupt into Virtual Machine
2, where there is a copy of DOS running . 

The int 21 handler fulfils the request by calling on the BIOS (3). A
call to the BIOS is via int 13, so guess what happens when DOS issues
an int 13 - control pops right back to layer 0, the protect mode
software. Once again, the protect mode software sees that it is an
int 13 that the BIOS should handle, and since the BIOS runs in real
mode, it 'reflects' the interrupt to the BIOS.

It turns out that switching from virtual mode to protect mode and vice
versa is a very expensive deal (ie, many instructions). Also, to satisfy
a singe Int 21 request, the DOS interrupt handler could issue many Int 13s.
So, there could be many of the transitions labelled 'this guy' for every
one Int 21 request.

What FASTDISK does is bypasses the BIOS. So now, when the DOS int 21 
handler issues an int 13, the layer 0 protect mode software satisfies the
request itself - ie, it does not call upon the actual BIOS, but talks 
directly to the hardware controller. Note that the transition labelled
'this guy' has been eliminated. Since there are many of the 'this guy'
transitions for every disk IO request, this should speed up any disk IO
that originates from the user application running in VMM_A (1).

Now, one remaining question - why would this enhance the virtual memory
manager? One reason is obvious, that because the virtual memory includes
pages residing on disk, the virtual memory manager does not have to keep
bouncing back and forth between BIOS requests, it can simply use FASTDISK
to satisfy all the int 13 requests. The second reason is this - going 
through FASTDISK enables it to *page* memory belonging to DOS apps 
running in a window. The reason this is is the following - suppose there
were no FASTDISK, and we are back to relying on the BIOS for int 13s. Lets
say a DOS app issues a read disk request. Control goes from VMM_A (1) to 
layer 0, which bounces the request to DOS (2). Now, suppose the buffer
into which the read was supposed to go has been paged out. Well, the layer
0 software can't bring the page into memory because it *relies* on DOS for
its Disk IO, but DOS is in the middle of another Disk IO itself. But DOS
can't complete the *current* Disk IO until the read buffer gets paged in.
Deadlock. This occurs because DOS is non-preemptive (Don't snicker: even
the UNIX kernel is non-preemptive!)

However, if you are running FASTDISK, the FASTDISK code is reentrant, so
the read buffer can be paged in even while another request to FASTDISK is
currently in progress. Thus, FASTDISK allows windows to page memory 
belonging to DOS apps.

In summary, FASTDISK has two benefits - it speeds up any standard DISK IO
(including those requested by its virtual memory manager) by eliminating
Protect-mode-to-virtual-mode transitions because it no longer needs to go
to virtual mode to run BIOS code, and it allows memory belonging to old 
DOS apps to be paged, so that a single DOS app no longer chews up a hefty
640K of your physical ram.

According to the WRK, Microsoft has completely opened up the FASTDISK 
interface so that manufacturers of non-standard HD controllers can write
their own FASTDISK device drivers. 

Lastly, this should exemplify why DOS is such a needed part of windows,
because all int 21 requests end up in DOS code.


Milan