THE 10 BYTE RULE FOR TRADING MEMORY FOR CPU TIME Jim

THE 5 MINUTE RULE FOR TRADING MEMORY FOR DISC ACCESSES
and
THE 10 BYTE RULE FOR TRADING MEMORYFOR CPU TIME
Jim Gray
Franc0
Tandem Computers,
Putzolu
Cupertino,
item
is
ABSTRACT: If
an
accessed
frequently
enough,
it
should
be
main
For current
technology,
memory resident.
"frequently
enough"
means about
every
five minutes.
The derlvatlon
If maklng a 1Kb data record
resident
saves la/s,
then it
2K$ worth of disc accesses at
5$, a good deal.
If it saves
It saves about 200$, still
a
the break-even
Continuing
this,
one access every 2000/5 - 400
the
.5
hence
second
It
per
about
main-memory
saves about
a cost
of
.la/s
then
good deal.
point
1s
seconds.
the break-even
point
For smaller
records,
1s longer (1 hour for 100 byte
records)
and for
larger
records
the break-even
point 1s shorter
(2
minutes
for
4K
records).
At a certain
point
the
size
record
exceeds the disc
transfer
size.
For
page-faulting
a 1OOK program
example,
requires
twenty five
4K disc
reads. So
size
(4K in Tandem's
above the transfer
for
the
case) one must use the rule
Wz;sfer
size
(2 minutes
in
Tandem's
.
THE FIVE MINUTE RULE
Data referenced
every five minutes
should be memory resident.
years
access
1KB
record
accessed
So, any
more
frequently
than every 400 seconds
should
live in main
400 seconds
1s
memory
"about"
5 minutes,
hence the name. the
Five Minute Rule.
response
time
situations,
In
some
main
memory
data
be
dictates
that
Introduce
resident
because disc accesses
are
These situations
too much delay.
More commonly, keeping data
mainrare.
is purely
an economic
memory resident
When does lt make economic sense
Issue.
to make data resident
In main memory?
A
good rule of thumb 1s:
ago
disc
The
supportlng
A megabyte of maln memory costs
5K$, so a kllobyte
costs 5$.
If data 1s disc resident
it must be moved
read or
to being
to main memory prior
time
This movement costs
both
written.
and money.
twenty
five
minute rule
disc,
and half
a
deliver
15 random
and are priced
at
the
extra CPU and channel cost for
a disc is lK$/a/s.
So one disc
second costs about ZK$/a/s.
THE FIVE MINUTE RULE
years
of
accesses
per second
about
15K$ [Tandem]
So the price
per
access
per second
is about lK$/a/s.
These results
depend on current
price
ratios
of processors,
memory and disc
These ratios
are changing
and
accesses
rn the rules
are
hence the constants
changing.
applied,
to be
USA
goes as follows:
A
controller
comfortably
vein, one can frequently
Along a similar
For
trade memory space for
cpu trme.
example, bits can be packed in a byte
at
instructions
to
the expense
of extra
It
makes
economic
extract
the bits.
sense to spend ten bytes of main memory
to save one lnstructlon
per second.
Twenty
CA,
A more formal
1s:
rule
Let:
1s likely
The
exact
the
5 hour
rule.
dependent
on current
constant
1s very
the
argument
To make
price ratios.
use Tandem 1986 prices
concrete,
we will
similar
later,
discussed
here
As
IBM or
conclusions
result
from current
DEC prices.
RI:
MS:
AS:
B:
derivation
and
statement
interval
in seconds
expected
between references
to the data
(second/access).
of main
the cost
of a byte
memory ($/byte)
the cost of a disc
access
per
second ($/access/second).
the size of the data (byte).
PermIssion to copy wlthout fee all or part of this material 1sgranted provided that the copies are not made or dlstrlbuted for chrect commercial
advantage, the ACM copyright notice and the title of the pubhcatlon and Its date appear, and notxe 1sgiven that copymg 1sby permIssIon of the
Assoclatlon for Computmg Machmery To copy otherwise, or to repubhsh, reqmres a fee and/or specific permIssIon
0 1987 ACM O-89791-236-5/87/0005/0395
754
395
Bmax: the maxlmum transfer
disc (byte).
size
The Five Mrnute Rule also seems to apply
uniformly
to IBM systems
(prices
are
higher for IBM 30XX machlnes
and about
and for
the same for IBM 43xx machines)
everythlng
1s
(where
mini-commuters
uniformly
less expensive).
from
Then, assuming B < BmaX, the savings
In
dollars
of keeping
the
record
B main
memory resident
1s.
A$
---- M$*B
RI
At the break-even
IS zero.
Solving
point,
this
for RI gives
The Five Minute Rule does not
apply
to
reasons.
two
computers
for
personal
discs
one cannot
First
.add and subtract
Will.
worKstatIons
at
from PCs and
one has the choice of zero
or
Typically,
Second, memory and disc
one hard discs.
economics are different
for PCs -- a disc
of
costs about the same as a megabyte
main memory.
expression
AS
RI = _-_-__M$*B
Substituting
for the Tandem numbers
2000, MS = .005):
400,000
RI = ------B
In the next
decade
64Mblt
memory chips
are likely
to reduce the memory vs dlscby another
factor
of
access cost ratio
5 hour
give rise to the
100. This will
rule.
(A$ =
second/access
illustrates
an
The following
case study
Minute Rule.
A
application
of the Five
entire
his
keep
designer
wanted
to
The
res ldent.
database
main memory
database had 500,000
records
and each
record was about 1000 bytes long, so the
The
whole database was about 5OOMbytes.
following
argument convinced
him to adopt
a hybrid disc-memory design.
Minute
As shown in Figure
1, the Five
particular
approximates
a
Rule only
Using
regron of the curve: B near
1K.
for
larger
data
the five
mrnute
rule
items antlclpates
the advent
of cheaper
memory.
We used standard PRICES. If we had
standard COSTS (about
10% of price)
the ratios
would have been similar.
Break
Even
used
then
Reference
Interval
vs
Data
Size
1oooa
RI
IN
1000
SEC
100
10
100
1000
MEMORY RESIDENT
10000
DATA SIZE IN BYTES
Figure 1 A log-log graph of teh break-even
reference Interval (RI) vs the
size (B) of the data being stored in main memory This IS based on 1986
Tandem prices Notice that beyond Bmax (the maximum disc transfer size)
the data size does not affect the break-even point
396
were quite
The application
transactlons
transactlons
all
the
Almost
simple
accessed a single
record and demanded one
The
time.
response
average
second
and
transactlon
used 40ms of cpu time
The total
application
30ms of disc time
had a 600 transactlon
per second
peak
load.
similar
is
The argument
One picks
Minute Rule.
for memory (say
SK$/MB)
to the
Five
a certain
price
and a Certain
This means
f;;;elqe;yy::
d:::
E?!2;.
Similarly
about
costs
one instruction
per second
SO 10 bytes
costs about
the
Same
.05$.
as 1 lnstructlon
per
second. This gives
rise to the ten byte rule:
needed
design
The all-ln-maln-memory
each with 16MB
about 36 VLX processors,
of main memory Two mirrored
discs stored
Its indices
and the
the entire
database,
would be idle during
programs. The discs
normal operation
since the database would
be memory resident.
j.,...
to save 1 rnstruction
per second.
The Ten Byte Rule is applied
as follows.
Let
I: how many lnstructlons
are saved by
the new design (lnstructlons)
F: how frequently
the
instruction
sequence is executed (l/second)
S: how many bytes are saved by the new
design (bytes).
rule suggested that only
The five minute
of 5
interval
records with a reference
minutes or less should be in marn memory.
later
confirmed
in
Based on estimates,
applicat:~;or~;ro"
&
another videotext
are
few
very
Hoelskenl,
observed
They
referenced.
frequently
80% of
the
that 3% of the records
got
estimate
statistical
references.
indicated
that tt
600TPS, only 30,000 of
the 500,000 records would
be referenced
interval.
In
minute
twice in a five
this 6% of the data
would
get
addition,
96% of all
accesses
so only
24 disc
The product
savings of
negative
if
of I and F 1s the lnstructlon
the
change.
It
will
be
the design adds lnstructlons.
Using the Ten Byte Rule compare S (the
memory savings)
with
the
instruction
savings by dividing
S by 10.
The net
savings
is:
I*F-S/10
If it is a large
positive
number,
then
the new design provides
a large savings.
introduced
(4%
accesses per second were
Two disc drives
storing
the
of 600TPS).
data could comfortably
support this
read
The consequent design saved 470Mb
rate.
This was a
of main memory and six cpus.
3.5M$ savings
(a 30% savings)
over the
entirely
main memory design.
As an example,
of
suppose the dispatcher
an operating
system
has a code sequence
like:
LOAD
BYTE
MASK
FLAG
BRANCH ON NONZERO
Suppose the dispatcher
1s invoked
1000
times each second.
reference
database
Any application's
this
logic
to
string
can be used with
of disc cache
size
compute the optimal
and optimal
number of disc arms.
This Five
Minute
Rule
applies
equally
If a
well to virtual
memory management.
virtual
memory page (typically
4K bytes)
1s referenced
every
2 minutes,
lt should
CLOCK
Hence a
stay memory resident.
virtual
memory algorithm
[Carrl
should be
given enough memory to cycle once every
minute at peak loads or one should try to
detect such "hot" pages (using a 2 minute
such
"hot"
hlstory
string)
and treat
pages specially.
*
If flag
- . were stored as a byte it would
avoid the mask step
and hence save
1000 instructions
per second.
*
This translates
to about 10000 bytes
of storage based on the Ten Byte Rule.
*
If flag were stored as a byte it would
use eight
times the storage.
If there
_ ^_
are 1UU processes
in tne processor,
this translates
to about
88
extra
bytes.
*
Since we have a 10,000
byte
budget,
this 1s a profit
of 9912 bytes for
an
88 bvte lnbestment.
A good trade -about a 1OO:l return
on investment.
THE TEN BYTE RULE
Another interesting
question
1s: "When
does it make economic sense to use more
or
some cpu powerTn,
memory to save
the
memory
at
conversely
save some
This issue
expense of some cpu cycles?
arises
in code optlmlzatlon
where one can
unwinding
by
save some lnstructlons
design where
loops, and in data structure
one can pack data at the expense of extra
bytes
cpu instructions
to mask and shift
to extract
the bits.
On
non-RISC
machines,
the
MASK
instruction
may use 2 micro-clocks
while
the average
instruction
uses 6 mlcroclocks.
In this case, one needs to weight
the saved instructions
with their
microclock cost.
That
is,
in the example
above, would
save
only
2/6
of
an
397
instruction
each time
"real"
step. So the
hypothetical
non-RISC
only (100*(2/6)):1
+
deal.
saved a MASK
savings
on the
machine
would
be
33:l.
Still
a good
we
THE FUTURE
The idea underlying
these rules is a way
tradeoffs
of
of evaluating
the economic
design decisions.
As technology
changes
these
price-performance
ratios,
the
design rules must also change.
disc module
Over the last
two decades,
capacity
have
capacity
and memory chip
grown about a factor
of 100 every
decade
with a proportional
drop
in price
per
megabyte.
Processor
speeds have grown a
with
a
every
decade
factor
of ten
Disc
consequent drop in price
per mip.
constant
accesses have had a relatively
cost over this
period,
discs continue
to
accesses/arm/second
deliver
about
15
60
accesses/arm/second
random
and
sequential.
Extrapolating
these trends to 1996, the 5
rule
minute rule will
become the 5 hour
-- data used once every five
hours
will
In that timebe main memory resident.
considerable
will
be
frame,
there
cache
optimizing
interest
in
cpu
occupancy since main memory will
begin to
look like secondary storage to processors
and their memory caches.
Similarly,
the 10 byte rule is likely
to
become the 100 byte rule -- one will
be
main memory in order
willing
to squander
to save a few instructions.
ACKNOWLEDGMENTS
Dina Bitton,
Haran Boral,
Fritz
Graf, and
Pete Homan
pointed
out
errors
and
suggested many improvements
to earlier
versions
of this paper.
REFERENCES
[Cari-]
Virtual
Memory Management
University
Microfilm,
1984.
[Froxun & Hoelskenl
Fromm, H
Hoelsken,
H
"Beilschirmtext'
Usage
ChAracteristics
and
Performance
Aspects
of the
German
Videotext
System" Digest of Papers, Compcon 87,
IEEE Computer
Society
Press,
order
#764, pp. 152-160, Feb. 1987.
[Tandem] Tandem Product and Price
Guide,
Tandem Computers Inc.
Cupertino,
CA.
Sept 1986.
398