Your questions

What is a cache?

Could you please tell me what cache is, as it has been used several time in the web notes, but no clear explanation is given?

You didn't go to the revision lecture, did you?

Caches are common to many areas of software engineering/ system design. Principle is that there is some kind of information which it takes a long time to retreive or to produce. For example, disk blocks are expensive to read, since reading them requires potentially a disk seek, followed by some rotational latency, followed by some transfer time. In many applications, the same piece of information, e.g. the same disk block, is being read repeatedly, which is very inefficient.

The principle of the cache is that if a piece of information is requested many times in a short period of time, it should not be necessary to retreive it several times; it should be cached the first time, and read from the cache on subsequent occasions.

When studying operating systems, we see that caches are a common solution to a common problem: disks are very slow compared to memory---cache disk blocks; page table access is too slow compared to speed of processor---cache page table entries; access to pages on disk is too slow---cache virtual pages in physical memory frames; the Web is too slow for belief; cache Web pages.

The cache usually has a limited amount of storage, and it does not store a copy of all the information in the thing being cached. It must discard some of the items in the cache occasionally, when new items are to be cached. The algorithm which is usually most successful as a cache-replacement algorithm is least-recently used: discard items from the cache which have been used longest ago, under the assumption that most recently used items are most likely to be used again in the near future. In the absense of precognition, this approach seems to work well.

When an item is found in a cache, this is known as a 'cache-hit'; when the item is not found, it is a 'cache miss'.

A cache hit typically costs very little. Usually we would not even consider the cost of a cache hit. It requires only that the cache be examined and the item be returned.

A cache miss costs quite a lot: the cache must be examined, the item is not found, the item is retreived from the slower backing store, another item may have to be ejected from the cache, and the new item placed in the cache, then returned.

The proportion of hits to overall cache accesses is known as the 'hit ratio'

Cost of accessing an item therefore becomes:

(cost of hit × hit ratio) + (cost of miss × (1 - hit ratio))

A translation lookaside buffer is just a cache, but it is not a cache of pages, or of memory, or of disk blocks, it is a cache of page table entries.


updated 19 May, 1998