Hardware Secrets
Home | Audio | Case | Cooling | CPU | Input | Memory | Mobile | Motherboard | Networking | Power | Storage | Video | Other
Content
Articles
First Look
News
Reviews
Tutorials
Main Menu
About Us
Awarded Products
Compare Prices
Datasheets
Dictionary
Download
Drivers
Forums
Gabriel's Blog
Links
Manufacturer Finder
Newsletter
On The Web
RSS Feed
Test Your Skills
Newsletter
Subscribe today!
Search




Recommended Book
The Winn L. Rosch Hardware Bible (6th Edition)
By Winn L Rosch
Que
Price: $0.25

Home » CPU
How The Memory Cache Works
Author: Gabriel Torres
Type: Tutorials Last Updated: September 12, 2007
Page: 7 of 9
$ Check REAL-TIME pricing for Intel Core 2 Duo Retail Boxed E7200 Processor - 2.53GHz, 3MB Cache, 1066MHz FSB, 45nm Wolfdale E700 Boxed Processor $
Dell SMB: $135.99 ZipZoomfly.com: $119.90
Office Depot: $147.95 Amazon: $119.90
Netrithms: $149.99 TheNerds: $132.99

Memory Cache Organization

The memory cache is divided internally into lines, each one holding from 16 to 128 bytes, depending on the CPU. On the majority of current CPUs the memory cache is organized in 64-byte lines (512 bits), so we will be considering a memory cache using 64-byte lines in our examples throughout this tutorial. On the last page we will present the main memory cache specs for all CPUs currently found on the market.

So a 512 KB L2 memory cache is divided into 8,192 lines. Keep in mind that 1 KB is 2^10 or 1,024 bytes and not 1,000 bytes, so the math is 524,288 / 64 = 8,192. We will be considering a single-core CPU with 512 KB L2 memory cache in our examples. On Figure 5 we illustrate this memory cache internal organization.

Memory Cache Organization
Figure 5: How a 512 KB L2 memory cache is organized.

The memory cache can work under three different configurations: direct mapping, fully associative and set associative (a.k.a. n-way set associative). The later is the most used configuration nowadays, but let’s take a look on how these three configurations work.

Direct Mapping

Direct mapping is the simplest way of creating a memory cache. In this configuration the main RAM memory is divided into the same number of lines there are inside the memory cache. If we have a system with 1 GB of RAM, this 1 GB will be divided into 8,192 blocks (assuming the memory cache uses the configuration we describe above), each one with 128 KB (1,073,741,824 / 8,192 = 131,072 – keep in mind that 1 GB is 2^30 bytes, 1 MB is 2^20 bytes and 1 KB is 2^10 bytes). If our system had 512 MB the memory would be also divided into 8,192 blocks, but this time each one would have 64 KB. And so on. We illustrate this organization on Figure 6.

Direct Mapping Cache
click to enlarge
Figure 6: How direct mapping cache works.

The main advantage of direct mapping is that it is the easiest configuration to implement.

When the CPU asks for a given address from the RAM memory (e.g. address 1,000), the cache controller will load a line (64 bytes) from the RAM memory and store this line on the memory cache (i.e. addresses 1,000 thru 1,063, assuming we are using 8-bit addressing scheme just to help our examples). So if the CPU asks again the contents of this address or of the next few addresses right after this address (i.e. any address from 1,000 to 1,063) they will be already inside the cache.

The problem is that if the CPU needs two addresses that are mapped to the same cache line, a cache miss will occur (this problem is called collision or conflict). Continuing our example, if the CPU asks address 1,000 and then asks address 2,000, a cache miss will occur because these two addresses are inside the same block (the first 128 KB), and what was inside the cache was a line starting from address 1,000. So the cache controller will load the line from address 2,000 and store it on the first line of the memory cache, cleaning the previous contents, in our case the line from address 1,000.

The problem goes on. If the program has a loop that is more than 64 bytes long, there will be a cache miss for the entire duration of the loop.

For example, if the loop goes from address 1,000 to address 1,100, the CPU will have to load all instructions directly from the RAM memory thru the duration of the loop. This will happen because the cache will have the contents from addresses 1,000 thru 1,063 and when the CPU asks for the contents from address 1,100 it will have to go the RAM memory, and the cache controller will load addresses 1,100 thru 1,163. When the CPU asks address 1,000 back it will have to go back to the RAM memory, as the cache doesn’t have the contents from address 1,000 anymore. If this loop is executed 1,000 times, the CPU will have to go to the RAM memory 1,000 times.

That is why direct mapping cache is the least efficient cache configuration and not used anymore – at least on PCs.

Fully associative

On fully associative configuration, on the other hand, there is no hard linking between the lines of the memory cache and the RAM memory locations. The cache controller can store any address. Thus the problems described above don’t happen. This configuration is the most efficient one (i.e. the one with the highest hit rate).

On the other hand, the control circuit is far more complex, as it needs to keep track of what memory locations are loaded inside the memory cache. That is why a hybrid solution – called set associative – is the most used one nowadays.

Pages (9): « 1 2 3 4 5 6 [7] 8 9 »
Print Version | Send to Friend | | Bookmark Article | Comments (0)

Related Content
  • How Chips are Manufactured
  • Intel Fab18 Factory Tour in Kiryat Gat, Israel
  • Intel EM64T Technology Explained
  • All CPU Sockets
  • Sempron 3000+ and Celeron D 331 Review

  • Recommended Deals
    AMD Athlon 64 3500+, 2.2 GHz (ada3500dik4b) OEM / Unboxed Processor


    eBay: $52.00 ZipZoomfly.com: $39.99
    Hpshopping: $491.99 Amazon: $749.99
    Intel Core 2 Duo E6850, 3 GHz (BX80557E6850) Boxed Processor


    eBay: $200.93 CompuVest: $190.61
    Dell SMB: $249.99 Office Depot: $229.99
    Amazon.com Marketplace: $201.99 Next Warehouse: $200.28
    AMD Athlon 64 X2 3800+, 2.4 GHz (ADA3800DAA4BW) OEM / Unboxed Processor


    eBay: $54.58 Amazon: $749.99
    Hpshopping: $491.99
    Intel Core™2 Quad Q6600, 2.40 GHz (BX80562Q6600) Boxed Processor


    CompUSA.com: $189.99 Dell: $219.99
    TigerDirect.com: $189.99 CompuVest: $205.16
    ZipZoomfly.com: $193.90 Buydig: $1569.00

    RSSLatest News
    New Thermalright Fans
    November 28, 2008 - 4:44 AM PST
    Glacialtech Launches UFO V51 CPU Cooler
    November 27, 2008 - 3:18 PM PST
    Lexar Media Launches Triple-Channel DDR3 kits for Core i7 Processors
    November 26, 2008 - 6:23 PM PST
    OCZ Intros Fatal1ty Power Supplies
    November 26, 2008 - 5:53 PM PST
    Hynix Introduces 7 Gbps GDDR5 Memory Chips
    November 25, 2008 - 6:42 PM PST
    Geil Launches EVO Cyclone Memory Cooler
    November 24, 2008 - 6:19 PM PST
    Cooler Master Intros New Silent Force Power Supplies
    November 24, 2008 - 5:56 PM PST
    Akasa Launches Smart Fan Case Fans
    November 21, 2008 - 2:58 PM PST
    Titan Launches Cooler for Intel Core i7 CPUs
    November 20, 2008 - 4:47 PM PST
    Thermaltake Launches Fanless 330 VGA Cooler
    November 19, 2008 - 6:17 PM PST
    .:: More News ::.

    RSSLatest Content
    New Page: Awarded Products
    KeyScan KS810 Keyboard-Scanner Review
    Everything You Need to Know About Camera Sensors
    Zalman ZM750-HP Power Supply Review
    How does or would your notebook improve your quality of life? What role does or would it play in your life?
    SilverStone Decathlon 700 W Power Supply Review
    Antec Signature 650 Power Supply Review
    Seventeam ST-550P-AG Power Supply Review
    Logitech QuickCam Pro 9000 Review
    GeForce GTX 260 with 216 cores Video Card Review
    Laptop Design: What are some ways that form can enhance function?
    Panasonic Link-to-Cell Phone System Review
    Topower TOP-1100P10 Power Supply Review
    Gigabyte MA78GM-S2H Motherboard
    OCZ Neural Impulse Actuator Review

    Our Most Popular Articles
    Maximum CPU Temperature
    829,031 views
    nVidia Chips Comparison Table
    516,990 views
    AMD ATI Chips Comparison Table
    454,846 views
    How to Find Out Your Motherboard Manufacturer and Model
    440,267 views
    ATI Radeon X1300 Pro Review
    431,140 views
    ATI Radeon X1600 XT Review
    424,587 views
    Connecting Two PCs Using a USB-USB Cable
    390,787 views
    How To Correctly Apply Thermal Grease
    373,638 views
    Sempron vs. Athlon XP
    291,483 views
    Sempron 3400+ Review
    283,679 views

    Latest Threads in Our Forums
    Build or buy - long post..
    by Aknot
    Can viruses really steal ID information?
    by cs0khunter82
    Cases: How to Avoid Overheating
    by Merman
    need help building gaming desktop under $1.5k
    by ray-solomon
    Need help what to buy for PC build
    by ray-solomon
    Nintendo DS Lite Ice Blue
    by Hardware Secrets Team
    UpGrade BIOS
    by Philphoto
    Too much thermal grease? [pics]
    by darkabis315
    How long have you been with Vista?
    by cs0khunter82
    Good CPU for around $200?
    by DavidFlorida
    .:: Visit Our Forums ::.


    © 2004-8, Hardware Secrets, LLC. All rights reserved.
    Advertising | Legal Information | Privacy Policy
    All times are Pacific Standard Time (PST, GMT -08:00)