Cache Management
Learn how the average memory access time of a program can help in cache management in this lesson.
We'll cover the following
Before diving into policies, we first describe the problem we are trying to solve in more detail. Given that the main memory holds some subset of all the pages in the system, it can rightly be viewed as a cache for virtual memory pages in the system. Thus, our goal in picking a replacement policy for this cache is to minimize the number of cache misses, i.e., to minimize the number of times that we have to fetch a page from disk.
Alternately, one can view our goal as maximizing the number of cache hits, i.e., the number of times a page that is accessed is found in memory.
Average memory access time
Knowing the number of cache hits and misses let us calculate the average memory access time (AMAT) for a program (
where represents the cost of accessing memory, the cost of accessing the disk, and the probability of not finding the data in the cache (a miss); varies from 0.0 to 1.0, and sometimes we refer to a percent miss rate instead of a probability (e.g., a 10% miss rate means = 0.10). Note you always pay the cost of accessing the data in memory; when you miss, however, you must additionally pay the cost of fetching the data from disk.
For example, let us imagine a machine with a (tiny) address space: 4KB, with 256-byte pages. Thus, a virtual address has two components: a 4-bit VPN (the most-significant bits) and an 8-bit offset (the least-significant bits). Thus, a process in this example can access or 16 total virtual pages. In this example, the process generates the following memory references (i.e., virtual addresses): 0x000
, 0x100
, 0x200
, 0x300
, 0x400
, 0x500
, 0x600
, 0x700
, 0x800
, 0x900
. These virtual addresses refer to the first byte of each of the first ten pages of the address space (the page number being the first hex digit of each virtual address).
Let us further assume that every page except virtual page 3 is already in memory. Thus, our sequence of memory references will encounter the following behavior: hit, hit, hit, miss, hit, hit, hit, hit, hit, hit. We can compute the hit rate (the percent of references found in memory): 90%, as 9 out of 10 references are in memory. The miss rate is thus 10% (). In general, ; hit rate plus miss rate sum to 100%.
To calculate AMAT, we need to know the cost of accessing memory and the cost of accessing disk. Assuming the cost of accessing memory () is around 100 nanoseconds, and the cost of accessing disk () is about 10 milliseconds, we have the following AMAT: , which is , or , or about $$1 millisecond. If our hit rate had instead been 99.9% (), the result is quite different: AMAT is 10.1 microseconds, or roughly 100 times faster. As the hit rate approaches 100%, AMAT approaches 100 nanoseconds.
Get hands-on with 1400+ tech skills courses.