What is the function of L2 Cache,
how does it work and how does it differ from and relate to Disk Cache?
Corey Sims <firstname.lastname@example.org> wrote:
Would someone please explain to me the basic function of L2 cache?
A cache is a small, higher speed memory system which stores the most recently used instructions or data from a larger but slower memory system. Because programs frequently use a subset of instructions or data repeatedly, the cache is a cost effective method of enhancing the memory system in a "statistical" method, without having to resort to the expense of making ALL of the memory system faster.
For example, when the processor (CPU) performs a read (fetch) operation, it will first check to see if the data or instruction it requests is in the cache - if it is, then the cache provides the data very quickly to the processor, without having to access slower main memory (DRAM or ROM). If the data or instruction is NOT in the cache, the CPU fetches the item needed from DRAM or ROM, AND also stores a copy in the cache (assuming the "page" of the address has been marked as "cacheable" by system software). Now this instruction or data item is available in the cache if the processor requests it again. The larger the cache, the more instructions and data the cache can store, and the more likely it is for the requested item to be in the cache.
An n-th level cache is n-1 levels away from the CPU. A 1st Level cache, (also called an internal, or L1 cache) is usually built into the processor chip itself, while 2nd level caches (also called external, or L2 caches) and higher level caches are usually outside the processor chip. Some systems may have levels beyond L2. Each cache level away from the processor (larger value of n) is typically larger, but slower, than levels closer to the processor.
The PowerPC 601 processor, for example, has a 32K cache inside the processor itself. This is the Level One, or L1 cache. This cache is extremely high speed, but obviously very small compared to the amount of DRAM (main memory) in the system, which is at least 8 megabytes for a Power Macintosh.
For that reason, Apple put an expansion slot specifically for additional cache memory on each Power Macintosh motherboard. This cache memory is the Level Two, or L2, cache. This slot can accommodate a cache of ANY size on the 6100 / 7100 / 8100 PowerMacs, including The L2 Company's 1024 KBbyte (1MegaByte) cache - the largest and fastest currently available. In the case of the Power Macs, L3 would be the main memory (DRAM) or ROM itself - there are no cacheing levels beyond L2 in the current Apple Power Macintosh implementation. (Unless you consider the case of Virtual Memory, where it could be argued that the "physical" DRAM could be considered as a L3 level, while the hard drive space used for VM could be considered "main" memory.
With cache memory being much faster than DRAM or ROM, it can be accessed more quickly, resulting in faster system throughput. For example, in the 7100 with no cache card installed, if the 601 processor requests a "burst" of data (4 consecutive fetches of 64 bits each - a typical fetch), it takes 12 clocks to fetch this if the access is to DRAM, and 16 clocks if the data has to come from ROM. However, with an L2 cache card, if the ROM or RAM address is in the L2 cache (a cache "hit"), the access only takes 6 clocks!
However, there is a slight catch - if a cache card is installed, and the requested item is NOT in the cache (a cache "miss"), then it takes 14 clocks to access a burst of data from DRAM, and 17 clocks to access a burst of data from ROM - there is some overhead involved in "checking" to see if the address is in the cache. For this reason, a L2 cache that is too small could theoretically decrease performance. If its "hit" rate is too low, then you always incur the overhead of checking the cache, without the benefit of the requested address often being there.
The good news is that the overhead of checking to see if the requested fetch is in the cache does NOT increase with a larger size cache - it is always the same number of clocks. Therefore, a larger cache is beneficial in two regards - it incurs no more overhead than a smaller cache, and its "hit ratio" will be higher than a smaller cache.
Now, what is the "disk cache" in the memory control panel? This is also a "cache", but its function is to enhance the performance of your hard drive or other mass storage devices (CD, for example). It does this by allocating a portion of your main memory (DRAM) to store the most frequently used sections of your hard drive. Because main memory (DRAM) is much faster than a hard drive, this enhances your hard drive performance.
However, unlike a hardware L2 cache, there must be a software routine which runs to check to see if the requested hard drive sector is in the disk cache in main memory. If the disk cache is set too large, this software routine will take so long to do its checking that it will offset the benefits of cacheing the sector. For that reason, in DISK caches (NOT L2 CACHES), some experimention is necessary to find the optimum size to avoid a performance DECREASE.
Interestingly, it is possible, when running both a disk cache AND an L2 cache, to have the L2 cache contain hard drive data, causing a tremendous speed increase in apparent disk throughput. How? The disk cache puts frequently used hard drive data in DRAM, and then the L2 cache puts frequently used sections of DRAM in L2 cache. If the DRAM sections cached by the L2 cache contain hard drive data, then your hard drive's read performance will be greatly enhanced. This effect would be most likely with a large (1024K) cache, with the memory control panel's disk cache set to roughly the same size as the L2 cache.
Larry Knight -- The L2 Company http://www.mindspring.com/~l2co 3544 Jefferson Township Pkwy eMail: L2Co@mindspring.com Marietta, GA, USA, 30066-1782 Sales: (800) 527-9772 (US only) International: +1 770 641 9650 FAX : +1 770 641-9433