Macintosh Disk Cache fix

From Higher Intellect Wiki
Jump to: navigation, search
Date: Wed, 10 Aug 1994 09:11:50 -0400 (EDT)
From: Edwin Chee <>
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 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: (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 <>
 * <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)


Share your opinion