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.31
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.gif Intel Core i7 Extreme Edition 975 / 3.33 GHz processor BX80601975 $.
Computers4Sure: $23.40 Amazon: $1086.31
Newegg: $999.99 CircuitCity: $974.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.
    Power Supply VX450W 450W ATXAmazon.com Corsair CMPSU-450VX 450-Watt VX Series 80 Plus Certified Power Supply compatible with Core i7 and i5 Electronics


    Amazon: $73.89 Wal-Mart: $89.98
    Newegg: $64.99 TigerDirect: $79.99

    RSSLatest News
    IN WIN LAN Party in Southern California
    November 20, 2009 - 12:37 PM PST
    Patriot Announces PS-100 SSD Series
    November 19, 2009 - 7:30 AM PST
    Antec Launches TPQ-1200 PSU
    November 18, 2009 - 11:30 AM PST
    AMD/ATI Launches Radeon HD 5970
    November 18, 2009 - 10:18 AM PST
    OCZ Launches Colossus SSD Series
    November 17, 2009 - 1:39 PM PST
    NZXT Unleashes Tempest EVO Mid-Tower Case
    November 17, 2009 - 1:06 PM PST
    nVidia Launches GeForce GT 240
    November 17, 2009 - 10:18 AM PST
    Arctic Cooling Announces Accelero TWIN TURBO PRO VGA Cooler
    November 16, 2009 - 11:46 AM PST
    PowerColor Announces PLAY! HD5770 Video Card
    November 13, 2009 - 12:51 PM PST
    G.Skill Announces Falcon II SSD Series
    November 11, 2009 - 3:31 PM PST
    .:: More News ::.

    RSSLatest Content
    Ultra X4 500 W Power Supply Review
    Seagate Barracuda XT 2 TB Hard Disk Drive Review
    Nintendo Wii Fit Plus Review
    AMD ATI Chips Comparison Table
    nVidia Chips Comparison Table
    Gigabyte G41M-ES2L Motherboard
    Netflix on Playstation 3 Review
    CM Storm Sentinel Advance Mouse Review
    Titan Skalli CPU Cooler Review
    Nexus RX-6300 630 W Power Supply Review
    Gigabyte P55-UD6 Motherboard
    Nintendo Wii Review
    SilverStone Grandia GD04 Case Review
    Can We Trust the 80 Plus Certification?
    NZXT Gamma Case Review

    Our Most Popular Articles
    Maximum CPU Temperature
    1,078,340 views
    How to Find Out Your Motherboard Manufacturer and Model
    706,273 views
    nVidia Chips Comparison Table
    679,154 views
    Connecting Two PCs Using a USB-USB Cable
    593,458 views
    How To Correctly Apply Thermal Grease
    562,468 views
    AMD ATI Chips Comparison Table
    560,137 views
    ATI Radeon X1300 Pro Review
    487,938 views
    ATI Radeon X1600 XT Review
    477,113 views
    How To Perform a BIOS Upgrade
    394,522 views
    Sempron vs. Athlon XP
    338,528 views

    Latest Threads in Our Forums
    Dell Inspiron 6000 Powers but will not boot...
    by Merman
    Ultra X4 500 W Power Supply Review
    by Merman
    IN WIN LAN Party in Southern California
    by Hardware Secrets Team
    Getting A Hard Copy
    by Trevorrross
    Am I Making The Right Choice?
    by need2know
    Is it available to mount the Zalman cooler?
    by Olle P
    dsl modem prob
    by Sherry
    Seagate Barracuda XT 2 TB Hard Disk Drive Review
    by Hardware Secrets Team
    Overclocking a dell xps 410
    by 6dracing
    How to recover mp3's, pdf & chm files, applications from formated harddrive partition
    by tomahawk 1705
    .:: 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)