30.06.2013 Views

Under the Hood of .NET Memory Management - Simple Talk

Under the Hood of .NET Memory Management - Simple Talk

Under the Hood of .NET Memory Management - Simple Talk

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 7: The Windows <strong>Memory</strong> Model<br />

3. The virtual address is broken down into its constituent parts and used to find <strong>the</strong> PTE<br />

in <strong>the</strong> page table.<br />

4. If <strong>the</strong> PTE thinks <strong>the</strong> page is in physical memory, <strong>the</strong>n <strong>the</strong> page frame entry is<br />

retrieved from <strong>the</strong> PFD.<br />

5. It is checked for validity, and used to retrieve <strong>the</strong> actual data from <strong>the</strong> direct location<br />

in physical memory, which is <strong>the</strong>n returned to process A.<br />

6. If <strong>the</strong> page isn't in physical memory, <strong>the</strong>n a page fault occurs and it has to be loaded in<br />

from <strong>the</strong> page file. An existing physical page may have to be replaced to achieve this.<br />

7. Once restored, <strong>the</strong> requested memory can be returned from physical memory.<br />

It really is that simple!<br />

OK, that was a joke. The truth is that it is a bit convoluted and complicated, but if you had<br />

designed a system to achieve something similar, you would probably have used many <strong>of</strong><br />

<strong>the</strong> same structures and processes.<br />

<strong>Memory</strong> Caching<br />

So as not to confuse you with information overload, I have deliberately left out <strong>the</strong> role <strong>of</strong><br />

<strong>the</strong> processor memory caches in all <strong>of</strong> this.<br />

Basically, <strong>the</strong> contents <strong>of</strong> <strong>the</strong> most frequently accessed memory addresses will be stored<br />

on <strong>the</strong> CPU itself (or just <strong>of</strong>f) inside a multilevel data cache, <strong>the</strong> purpose being to speed up<br />

memory access with fast memory hardware and shorter access paths.<br />

The data cache is split into three levels called L1, L2 and L3. The L1 and L2 caches are<br />

on <strong>the</strong> CPU, with L1 allowing for <strong>the</strong> fastest access, and typically storing between 8<br />

and 64 KB. The L2 cache store is larger than <strong>the</strong> L1 cache (typically up to 2 MB), but<br />

access is slower.<br />

211

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!