Cache memory
Categories: none
On most modern computers, the CPU runs at a faster speed than the rest of the computer. This is mainly due to the amount of time it takes for an electrical signal to travel across the motherboard. The CPU is small, so signals take less time for signals to travel, so it can be clocked at a faster rate.
Because of this, each time the CPU needs to access RAM memory (which is located on the motherboard), it has to wait a few cycles until the data has been read or written. This wastes time and slows the processor down.
Cache memory
Cache memory is a small amount of very fast memory which is usually located on the CPU chip (or very close to it on the motherboard). The CPU can access cache memory more quickly than normal RAM, but there is much less of it.
Cache memory is used to store bot instructions and data, so the can be accessed faster by the CPU.
The system tries to keep the most frequently used data in the cache. It uses an algorithm to decide which data should go in the cache. Algorithms can be quite complex, but here are some simple techniques:
- The most recently executed instructions might be held in the cache, in case the processor loops back and needs to execute them again.
- Data which has been accessed frequently might be held in the cache, as it is likely to be accessed again.
- Instruction and data might be pre-fetched. This means values are fetched from memory if the system thinks it might be used next, even if the CPU hasn't requested it yet.
Levels of cache
Often the cache memory is arranged in levels:
- the L1 cache contains a small amount of very fast memory
- the L2 cache contains a larger amount of slightly slower memory
- the L3 cache contains an even larger amount of even slower memory
Some systems have more levels. Even the slowest cache memory is faster than the system RAM, otherwise there would be no point using it!
Often, each core has its own fast cache (e.g. the L1 cache), but the slower caches are shared between all the cores. The faster caches are always on the CPU chip, but the slowest cache is sometimes on the motherboard close to the chip. Here is an example, although the details vary for different systems:
See also
Sign up to the Creative Coding Newletter
Join my newsletter to receive occasional emails when new content is added, using the form below:
Popular tags
555 timer abstract data type abstraction addition algorithm and gate array ascii ascii85 base32 base64 battery binary binary encoding binary search bit block cipher block padding byte canvas colour coming soon computer music condition cryptographic attacks cryptography decomposition decryption deduplication dictionary attack encryption file server flash memory hard drive hashing hexadecimal hmac html image insertion sort ip address key derivation lamp linear search list mac mac address mesh network message authentication code music nand gate network storage none nor gate not gate op-amp or gate pixel private key python quantisation queue raid ram relational operator resources rgb rom search sort sound synthesis ssd star network supercollider svg switch symmetric encryption truth table turtle graphics yenc