Tuesday, December 16, 2008

Cache

You will hear of many different types of caches associated with your computer system. There are caches for your CD-ROM, memory caches and hard drive caches. Your favorite browser even keeps a cache on your hard drive of the most recent websites you've visited. If the site hasn't changed, it can load it quicker from your hard drive than it can over the phone lines. A cache is meant to improve access times and enhance the overall performance of your computer. The type we're concerned with in this section is cache memory.

Everything you do on your computer requires RAM (Random Access Memory). RAM allows for quick access of data and instructions. Access to your ROM chips, drives, CD-ROM etc., is miserably slower than Random Access Memory. Therefore, that's where all the different devices and components get their data from. RAM is where your CPU processes information and instructions. Random Access Memory is the go-between for all your devices. When you start your computer, the operating system, device drivers, any active files and all running programs are loaded into RAM. (Hence the term "loading a program"). This is also why one of the best upgrades you can do for your computer is to increase the amount of memory. If your memory is low, then you have to wait each time new information is swapped into memory from the slower device.

Personal Computers use Dynamic Random Access Memory (DRAM) for system memory or RAM. These chips need a constant electrical 'kick in the but' to remind them what they have stored in their registers. In other words, they need to be constantly 'refreshed'. This constant refreshing takes up a lot of the CPU's time. There's another type of RAM called Static Random Access Memory (SRAM). SRAM will hold its information as long as there's electricity to the chip. It doesn't need constant refreshing and therefore is faster than DRAM. However, SRAM is a lot more expensive than DRAM, and it takes up a lot more space. You wouldn't have enough room on your motherboard for even 16MB of SRAM, and the cost would take it out of the realm of the affordable home computer. This makes DRAM the affordable and practical choice for system memory. But SRAM is used for Cache memory.

So where does cache come in? Cache is the way that most CPUs are matched to RAM. In between the CPU and system memory (DRAM) there is a small cache of the faster SRAM. Circuitry on the motherboard, called a cache controller, decides the content of this cache. The most recently accessed information or instructions can help the controller to guess at what RAM locations may be accessed next and these are stored in the cache. When the CPU needs its next instruction or piece of data, it looks in the cache. If the info is there, it's called a 'cache hit' and is retrieved at a faster speed than it would be from system memory. If it isn't in the cache, then it's called a 'cache miss' and the information is retrieved from system memory (slower DRAM). The cache controller then guesses at the next access and loads it into the cache. The number of cache hits, far outnumber the misses and this speeds up system performance dramatically.

Two of the main factors that affect a cache's performance are size (or amount of cache memory) and level.

No comments: