Macintosh Disk Cache fix -- 25 times speedup

Revision as of 18:12, 30 July 2020 by Netfreak (talk | contribs) (Created page with "<pre> Date: Wed, 10 Aug 1994 09:11:50 -0400 (EDT) From: Edwin Chee <[email protected]> Subject: Macintosh Disk Cache fix -- 25 times speedup Below is an interesting thre...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Date: Wed, 10 Aug 1994 09:11:50 -0400 (EDT)
From: Edwin Chee <[email protected]>
Subject: Macintosh Disk Cache fix -- 25 times speedup

Below is an interesting thread on making the Macintosh Disk Cache much 
more efficient with a simple hack.  Stuart Cheshire has written a simple, 
useful system extension that he is distributing as freeware.  I would 
welcome any discussion on his idea particularly regarding data integrity, 
reliability, stability, and efficiency.  Also, does anyone have any 
ideas on how to improve on his program?  If his modification to the write 
cache is really as good as I suspect, I would hope that Apple would 
include this in their next version of the Mac OS.

Please forward replies to [email protected] and I will compile a 
complete record of this thread and distribute it at a later date.


Here's a message I posted on Thursday to the Nuntius mailing list:


Has anyone else noticed that at the end of extracting a binary in
Nuntius the disk light comes on, stays on for a few seconds, and
freezes the Mac for that duration? It gets unbearable if you have
a large disk cache, but even with only a 256K cache it can freeze
the Mac for up to 5 seconds.

This is not the fault of Nuntius -- many other programs like BinHex
decoders, uudecoders, archive expanders etc. seem to suffer the same

This really annoys me. One of the good features of Nuntius is the way
it lets you continue working while it is doing other things in the
background, so having it freeze like this is particularly galling.

The problem is that Nuntius (and other programs) write their data to
disk in chunks (say 4K each) and the Mac caches the blocks in its
disk cache. When the file is closed the data is finally written to disk,
and this is what causes the big freeze up. It would be much better if
the data were written continually to disk, instead of in one big burst
at the end.

Yesterday morning I wrote a little INIT which sets the File Manager
"don't cache" bit for disk writes of 1K or more. It does this by
installing the following patch on the _Write system call:

                 tst.w   IOParam.ioRefNum(a0)         ; Is this a file write?
                 bmi.s   @sys_write
                 cmp.l   #1024, IOParam.ioReqCount(a0); Is it at leask 1K?
                 blo.s   @sys_write
                 ori.w   #0x20, IOParam.ioPosMode(a0) ; Set "Don't cache" bit
extern sys_write:jmp     0x12345678                   ; Resume the system 

One surprising artifact of this is that it not only amortises the disk
time over all the writes, but it also makes it 25 times faster.


Yes, it's true.

I set my disk cache to 768K, and wrote a test program which wrote to a
file in 32 blocks of 16K each, making a total of 512K.

Without the INIT, the writes took almost no time, but the Close call
took 11 seconds, averaging about 45K/second write rate.

With the INIT, the whole thing took under half a second, averaging
over a megabyte per second.

Go figure.

This may not make much difference to people connecting over modem, but
for people on Ethernet it makes a huge difference.

The INIT is below, in BinHex form. Decode it, install it, and let me
know what you think.

It has no ICON, because the total size of the INIT (including balloon
help) is just under 1K, and it seemed a pity to spoil that with a big
fat colour icon. (Besides, I couldn't be bothered to draw one.)


Here is one reply I got, which proves I wasn't hallucinating:

>> From: [email protected] (Joanna L. Castillo)
>> Subject: Re: Long Mac freezes with Nuntius (and other program)
>> Hi, Stuart -
>> >Yesterday morning I wrote a little INIT  [ ... ]
>> Wow!  I installed the INIT... I tried copying a folder that had several
>> files and sub-folders (a little over 900K total) to a floppy.  With the
>> Wow!  I installed the INIT... I tried copying a folder that had several
>> files and sub-folders (a little over 900K total) to a floppy.  With the
>> INIT installed, it took about 30 seconds.  Without, it took 2 minutes.
>> Thank you so much.
>> Joanna.
>> FYI:  I'm running a Mac IIci, 24MB RAM, cache card, ethernet, tuned
>>       7.0.1 system, several inits, and disk cache set at 512K.

I'll post the source code for the INIT, and the test program, to a
separate thread. This INIT itself is below.

Stuart Cheshire <[email protected]>
 * <A HREF="file://">WWW</A>
 * Stanford Distributed Systems Group Research Assistant
 * Escondido Village Resident Computer Coordinator
 * Macintosh Programmer

(This file must be converted with BinHex 4.0)

!)!!X6[N50&Ci6R919[rm51F(!#`Z!!JZ"J+(!!!)!%U(C`4`[email protected]!#F!!D!%U(Cd!
@`%3!60m!i%[email protected](*KF%&[email protected]@*XC3!!,`Y(q[[email protected]$bJ!k0'*SK"q[mb-$b
J!k*(,c`!!+'B6VVr3%[email protected])pR"%kk!"SQAdje)Pm5(c!I5J&R"+G'B!+M4Lk)6Y%
[email protected]@pZ)'*jF'&cFf9c)(4SC5"[email protected]"MEh"j,@*KBfXJC'PcDb"[email protected]
SC5"QEh)[email protected])(GbDA4PFb"dEb"NDA0V)'pQ)$&,)'pb)'[email protected]&dCA)Z)%pZ)'e
j)&&[email protected]!h-$!X)(GTG'JJB5"NDA0V)'0KBfKP)'pQ)$-i0%XX)([email protected]&
VCA-JBf9bG'&TEL"KF("[email protected]'P[ER-J-M8JG'PYCA-JCQ&cG'9b)([email protected]'K
`!!!!4J%!J!!!!!-a,M!lU5!fG'JJ3A"[email protected]`J-6Nj0#"6G(9KFR3J3fKPFfKTFQ8
J2'0SCA0SDA*P3'0c,[email protected]*N,Q9NG6i!!!%!!!!$K3!!!S8!!!"c!*@8'!Y
r!!!")J!!!!!!![rr!!!#(!#9NM3!!Irr!!!#1`#9Nf`-9h*TG'98D(*[[email protected])