Update
This commit is contained in:
parent
9c911cc430
commit
232c0266bf
21 changed files with 1928 additions and 1871 deletions
2
cache.md
2
cache.md
|
@ -1,6 +1,6 @@
|
|||
# Cache
|
||||
|
||||
Cache is a very small but fast computer [memory](memory.md) that helps make communication between computer components much more efficient (typically by making it much faster or taking less bandwidth) by remembering recent requests and answers so that they don't have to be expensively repeated. The concept of cache memory is extremely important and one of the very basics for designing and [optimizing](optimization.md) [hardware](hardware.md) and [software](software.md) (as cache may be implemented both in hardware and software). A cache may also help prevent expensively recomputing results of [function](function.md)s in the same way, by remembering the recent results of the function (we may see this as a more abstract CPU-function communication). Though caches find wide use almost everywhere, without further specifying the context or type of cache the word *cache* most often refers to the [CPU](cpu.md) cache -- cache memory found in a CPU (nowadays in all PC CPUs, however still NOT in all [embedded](embedded.md) CPUs), which is typically further subdivided into multiple levels (L1, L2 etc.) -- here we will be using the term cache the same way, but keep in mind the principles apply everywhere and caches really are used in many places. Cache is not to be confused with a [buffer](buffer.md) (which also helps optimize communication but rather by means of creating bigger chunks to be transferred at once).
|
||||
In the world of [hardware](hw.md) a *cache* is a very small but fast [computer](computer.md) [memory](memory.md) that helps make communication between computer components much more efficient (typically by making it much faster or taking less bandwidth) by remembering recent requests and answers so that they don't have to be expensively repeated; this principle is also extended to the world of [software](sw.md) programming where *cache* means a [file](file.md) (or several files) that remembers some recently retrieved data (such as websites) so that they can repeatedly be accessed faster. Here we will primarily focus on the original concept of hardware cache -- software caches basically just generalize them. The concept of cache memory is extremely important and one of the very basics for designing and [optimizing](optimization.md) [hardware](hardware.md) and [software](software.md) (as cache may be implemented both in hardware and software). A cache may also help prevent expensively recomputing results of [function](function.md)s in the same way, by remembering the recent results of the function (we may see this as a more abstract CPU-function communication). Though caches find wide use almost everywhere, without further specifying the context or type of cache the word *cache* most often refers to the [CPU](cpu.md) cache -- cache memory found in a CPU (nowadays in all PC CPUs, however still NOT in all [embedded](embedded.md) CPUs), which is typically further subdivided into multiple levels (L1, L2 etc.) -- here we will be using the term cache the same way, but keep in mind the principles apply everywhere and caches really are used in many places. Cache is not to be confused with a [buffer](buffer.md) (which also helps optimize communication but rather by means of creating bigger chunks to be transferred at once).
|
||||
|
||||
**Basic principle**: cache can be seen as a [black box](black_box.md), "man in the middle" component that's placed in the line of communication between a CPU and main memory (RAM). (Physically it is nowadays part of the CPU itself, but we may imagine it as a separate component just sitting "on the wire" between CPU and RAM.) When reading from memory, we have a pretty simple situation -- once CPU requests something from the memory, the request first goes to the cache; if the cache has the result stored, it just quickly returns it -- we call this a **cache hit** (this is good, we saved time!). A **cache miss** happens when the cache doesn't have the result stored -- in such case the cache has to expensively forward the request to the memory and retrieve the data; usually the cache retrieves a whole smaller block of memory because it can be expected the CPU will access something in nearby memory in the near future (see the principle of locality below). When writing data to memory the situation is a bit more complex as the cache may choose different [strategies](strategy.md) of behavior: for simplicity it may just write the data through every time, but a more efficient (and also more complicated) approach is to just store the data for itself and write it to the main memory only when necessary (e.g. when it needs to load a different block of memory). Here we get into things such as cache coherence etc., which may cause pretty nasty [bug](bug.md)s and headaches.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue