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




Recommended
The Winn L. Rosch Hardware Bible, 6th Edition (2 Vol. Set)
The Winn L. Rosch Hardware Bible, 6th Edition (2 Vol. Set), by Winn L Rosch (Que), starting at $2.32
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 Celeron E1500 Socket 775 65mm Dual-Core Processor with 2.2GHz 800MHz FSB 512KB L2 Cache Model BX80557E1500 Retail Box Free Ground Shipping $.
Directron: $49.99 Newegg: $49.99
CircuitCity: $49.99 CDW: $62.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
  • Penryn Core New Features
  • nVidia Tesla Technology
  • Inside Intel Nehalem Microarchitecture
  • Core 2 Duo, Core 2 Quad, Phenom X3 and Phenom X4: Which One is the Best USD 200 CPU?
  • Everything You Need to Know About the CPU C-States Power Saving Modes

  • Recommended Deal.
    Phenom II Black CPU Processor Edition AM3 965 3AMD Phenom II X4 965 Black Edition Deneb 3.4GHz 4 x 512KB L2 Cache 6MB L3 Socket AM3 140W Quad-Core Processor - Retail HDZ965FBGIBOX


    Newegg: $195.99 CircuitCity: $209.99
    Directron: $209.99 CDW: $249.99

    RSSLatest News
    Spire Announces CoolNess Laptop Cooler
    November 6, 2009 - 3:07 PM PST
    Mushkin Launches Memories with Copper-made Heatsink
    November 5, 2009 - 3:49 PM PST
    Super Talent Launches USB 3.0 Flash Memories
    November 5, 2009 - 3:47 PM PST
    VIA Announces Nano 3000 Processor Series
    November 5, 2009 - 3:42 PM PST
    Sapphire Announces Vapor-X HD 5870 and HD 5750 Video Cards
    November 5, 2009 - 3:38 PM PST
    Gelid Unveils Tranquillo CPU Cooler
    November 5, 2009 - 3:36 PM PST
    Noctua Intros NH-D14 Premium CPU Cooler
    November 3, 2009 - 8:14 PM PST
    Transcend Unveils DDR3-1333 Memory Kits
    November 3, 2009 - 7:57 PM PST
    EVGA Launches GeForce GTX 275 CO-OP PhysX Edition
    November 3, 2009 - 7:51 PM PST
    Akasa Launches Freedom Xone Mid-tower Case
    November 2, 2009 - 6:05 PM PST
    .:: More News ::.

    RSSLatest Content
    SilverStone Grandia GD04 Case Review
    Can We Trust the 80 Plus Certification?
    NZXT Gamma Case Review
    Patriot Box Office Media Player Review
    ASUS U-75HA 750 W Power Supply Review
    MSI P55-GD80 Motherboard
    Thermaltake Element V Case Review
    Nokia 7705 Twist Cell Phone Review
    Cooler Master Hyper TX3 CPU Cooler Review
    Some Pictures from Our Office
    Antec Two Hundred Case Review
    Corsair TX950W Power Supply Review
    XFX Radeon HD 5770 Video Card Review
    XFX Radeon HD 5750 Video Card Review
    Scythe Big Shuriken CPU Cooler Review

    Our Most Popular Articles
    Maximum CPU Temperature
    1,070,670 views
    How to Find Out Your Motherboard Manufacturer and Model
    695,030 views
    nVidia Chips Comparison Table
    671,344 views
    Connecting Two PCs Using a USB-USB Cable
    585,729 views
    How To Correctly Apply Thermal Grease
    555,873 views
    AMD ATI Chips Comparison Table
    554,055 views
    ATI Radeon X1300 Pro Review
    485,778 views
    ATI Radeon X1600 XT Review
    474,829 views
    How To Perform a BIOS Upgrade
    389,311 views
    Sempron vs. Athlon XP
    336,531 views

    Latest Threads in Our Forums
    Is it a vga problem or motherboard has shocked?
    by ftomsuk
    Patriot Box Office Media Player Review
    by cchjde
    Is it possible LCD Monitor leaked by itself ?
    by delta32
    Suddenly death syndrome and pendrives
    by Desert Fox
    better cpu cooler?
    by sam_wade07
    Video Transfer camcorder to PC
    by fjs559
    Spire Announces CoolNess Laptop Cooler
    by Hardware Secrets Team
    Can We Trust the 80 Plus Certification?
    by Merman
    SilverStone Grandia GD04 Case Review
    by Olle P
    Understanding Over Current Protection
    by Olle P
    .:: Visit Our Forums ::.


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