Calculating HPFS386 Cache Size--Algorithm and Explanation
ID: Q117227
|
The information in this article applies to:
-
Microsoft LAN Manager, versions 2.2, 2.2b
SUMMARY
When you load an operating system, some memory is always allocated for
cache. You can determine how much is allocated with HPFS386 by using
/CACHE:nnnn on the parameter line when you load the HPFS386 driver in
CONFIG.SYS. Because the relationship between cache size and system
performance is not simple, it can be difficult to determine optimal
cache size.
This article describes how cache memory is computed and allocated. The
observations and suggestions given here are supported by pseudo code
demonstrating the algorithm used to determine the cache size, and by
examples of how much cache is allocated for several configurations.
MORE INFORMATION
Cache memory is used to hold data read from the disk, then referenced
during a disk read. If a later disk read requests data that is still in
the cache, the read takes the data from there rather than going to the
disk to read it again.
The frequency with which valid data is retrieved from the cache is called
the "cache hit rate." A higher cache hit rate usually means better system
performance because fewer reads must go to the disk to get data.
Calculating Optimum Server Cache Size
Determining optimal cache size is a trial and error process. To complicate
things further, some algorithms useful for determining the value in
certain configurations are of little use in setting the cache size on a
LAN Manager server
To determine optimum cache size on a server you must consider the services
and applications that will be run on the server, and the amount of server
memory. Server memory is usually fixed, but the services, drivers and
applications loaded vary so much that generalizations are of little use.
It is better to understand how cache size is computed, then adjust the
values to achieve the result you want.
If server memory were large enough, you could simply increase cache size
until you achieve maximum hit rate. It's not that simple, though, because
after a certain size hit rate does not significantly increase along with
cache size. The trick is to find the optimum cache size without going
beyond the point of diminishing returns--the point at which increasing
server memory no longer increases cache hit rate.
When balanced against other system memory requirements in most cases, the
optimal cache size is somewhere between 2-4 MB. Allocating more than 4 MB
to cache will probably degrade system performance.
The /CACHE:nnnn and /M(XXX):nnnn Parameters
Two command line options affect how cache is allocated on a LAN Manager
server: /CACHE:nnnn and /M(XXX):nnnn
The /CACHE:nnnn parameter can take two forms. It can be used to specify
the amount of cache explicitly, as in /CACHE:512 or /CACHE:4096. It can
also be set as /CACHE:AUTO to let the operating system determine how much
memory to allocate to the cache. If no /CACHE: parameter is used then it
is the same as /CACHE:AUTO.
The /M(XXX):nnnn parameter is treated as a cache reduction value and is
documented to imply that its value increases or decreases the amount of
cache allocated.
Understanding Pseudo Code of General Algorithm
The following pseudo code gives the general algorithm used to determine
the amount of memory allocated to the cache. This may not (and usually
isn't) the same as you would assume by looking at the /CACHE:nnnn and
/M:nnnn parameters. Keep these things in mind when looking at the code:
- CacheSize is the amount of memory that will ultimately be allocated
as cache; it changes as it is tested against various other values until
the system has computed an acceptable value--not necessarily the best
value for system performance.
- AvailMem is the amount of memory free when cache sizing takes place.
This code is at the beginning of the CONFIG.SYS file, so it is executed
after the kernel has been loaded but before other drivers, protocols,
services, applications and the Presentation Manager have been loaded
or started. After the cache has been sized and allocated, available
memory is reduced accordingly, reducing the amount of memory available
to system drivers, services, etc.
- Parameters of the form /M:nnnn or /MRAS:nnnn or /MSFM:nnnn are, for the
purposes of the following code, termed "cache reduction" values. They
are cumulative and can be positive or negative: /MRAS:512 is valid. and
so is /M:-1024. The key point is that this is the amount by which you
want to reduce the cache to make sure that nnnn amount of memory is
reserved for applications, services, etc. However, as will be shown
below this can be very misleading.
- The /M notation is only notation. For example, if you specify /MRAS:512
(reserve 512 K of memory for Remote Access Service), this is merely
a note. The letters after the /M (RAS in this case) can be anything:
all they do is note in the CONFIG.SYS file note what you are reserving
the memory for--the operating system does not use them to assign memory
specifically to RAS. In fact, it may not even affect the cache size at
all as will be seen from the code below.
Pseudo Code
The following pseudo code is in a combined English and C style:
AvailMem /* KB of available memory after kernel load */
ReservedMem /* KB of available memory reserved including /R switches*/
CacheReduction /* KB to reduce cache amount (sum of /M switches) */
MIN_CACHE = 256K /* minimum cache size in KB */
MIN_REMAIN = 2048K /* min memory required for PM and other uses */
/* The table below is indexed by amount of physical memory (in MBs)
/* which is then used to compute the cache size in KBs: */
const PhysToCache[] =
{ 256, 256, 256, 256, /* 1, 2, 3, 4 MB system */
256, 256, 512, 1024, /* 5, 6, 7, 8 MB system */
2048, 3072, 4096, 5120, /* 9,10,11,12 MB system */
6144, 7168, 8192, 9216 }; /* 13,14,15,16 MB system */
ReservedMem = sum of all /R switches on the HPFS386 line in CONFIG.SYS
if (AvailMem >= ReservedMem + MIN_CACHE + MIN_REMAIN)
AvailMem -= ReservedMem
else
Error BadTooMuchReduction
if (/CACHE:AUTO) { // same as no /CACHE parameter
get amount of physical memory (PhysMem)
CacheSize = PhysToCache[PhysMem]
/* walk down the table till you achieve a workable cache size */
while ((CacheSize + MIN_REMAIN > AvailMem ) && PhysMem != 0) {
PhysMem--
CacheSize = PhysToCache[PhysMem]
}
if (CacheSize >= (sum of /M switches) + MIN_CACHE)
CacheSize -= (sum of /M switches)
else
CacheSize = MIN_CACHE
} else { /* /CACHE:XXXX */
CacheSize = size specified on command line
if ((CacheSize + (sum of /M switches) + MIN_REMAIN) > AvailMem)
if ((MIN_CACHE + (sum of /M switches) + MIN_REMAIN) > AvailMem)
CacheSize = MIN_CACHE
else
CacheSize = (AvailMem - MIN_REMAIN - (sum of /M switches))
else
No change to CacheSize: it stays as specified on command line
}
AvailMem -= CacheSize
return(success)
Note these things about the pseudo code:
General Rules
Here are some general rules to apply when sizing the cache:
- Never use /CACHE:AUTO. The possibility of the cache being correctly
sized automatically for your server is very slim. It may be OK if
the server isn't doing much of anything, but this is highly unlikely.
Further, an automatic sizing could be a disaster waiting to happen if
any of these services or applications are being run:
- SFM - services for Macintosh
- RAS - Remote Access Service
- SQL - SQL server
- Sytos backup software
- If you suspect that you need to reserve memory for a service or
application, lower cache size by adjusting the /CACHE:nnnn parameter.
The /M switch is not a reliable tool for reducing cache size. It also
can be misleading if it causes someone looking at the CONFIG.SYS to
think that memory has been reserved for a specific service (such as
RAS, with /MRAS:512) when this is not the case.
- System performance is never improved by allocating cache at the expense
of memory available to services or applications. If a service or
application does not have enough memory to run, it causes some other
task to be swapped to disk, which degrades performance much more than
does a lower cache hit rate caused by reducing cache size.
Sample Test Cases
Below are some test cases determined by changing the /CACHE and /M
switches in CONFIG.SYS. These tests bear out the pseudo code above. Using
these examples and the general rules and comments in this article you
should be able to determine how best to set the necessary parameters in
your CONFIG.SYS file.
The examples are based on a 486/66 with 16 MB RAM.
CONFIG.SYS Settings: Cache Size Notes and Errors
-------------------- ---------- -----------------
/Cache:3096 3096
/Cache:3096 /M:2048 3096
/Cache:3096 /M:-2048 5144 //The - sign increases cache size
/Cache:5144 /M:2048 5144
/Cache:7168 /M:2048 7168
/Cache:7168 /M:-2048 9216 //The - sign increases cache size
/Cache:9216 /M:2048 9216
/Cache:9216 /M:-2048 11264
/Cache:11264 /M:2048 10230 //Error: Available memory is less than
the cache plus the sum of the /M
switches. Cache size is reduced.
/Cache:11264 /M:-2048 2864 //Error: Cache size required is
too large: 20% of available
memory will be used.
/Cache:Auto /M:2048 6144
/Cache:Auto 8192
/Cache:Auto /M:-2048 10240
REFERENCES
"Microsoft LAN Manager Administrator's Guide" version 2.2
Additional query words:
1.30 cache sizing hpfs hpfs386
Keywords :
Version : :2.2,2.2b
Platform :
Issue type :
|