Memory Management 101

Memory Management 101

  • Comments 16
  • Likes

Memory Management issues make up a considerable portion of the support incidents that we handle.  At some point during the support incident we invariably engage in a discussion of Memory Management, Memory Tuning, the use of the infamous /3GB switch and more.  There's far too much information to compress into a single blog post, so think of this as the first part in a series.  In this post we'll cover the basics of 32-bit Memory architecture and the difference between Kernel and User mode memory.  So let's dive right in ...

Windows 32-bit Operating Systems implement a virtual memory system based on a flat 32-bit address space.  32-bits of address space translates into 4GB of virtual memory.  A process can access up to 4GB of memory address space (using the /3GB switch changes this behavior - and we'll cover that in a later post).

You can't have a discussion of Memory Management basics, without distinguishing between Kernel-mode and User-mode memory.  The system space (aka Kernel space) is the portion of the address space in which the OS and kernel-mode drivers reside.  Only kernel-mode code can access this space.  User-mode threads can access data only in the context of their own process.  User-mode threads cannot access data within another processes space directly, nor can it access the system address space directly.  Kernel-mode drivers are trusted by the OS and can access both kernel and user space.  When a driver routine is called from a user thread, the thread's data remains in the user-mode space.  However, the kernel-mode driver can access the user-mode data for the thread and access the kernel-mode space.

OK - so looking at the diagram above, we can see how the 4GB memory address space is divided.  Windows allocates the lower half of the 4GB address space (from 0x00000000 to 0x7FFFFFFF) to processes for their own unique private storage, and reserves the other half (from 0x80000000 to 0xFFFFFFFF) for the Operating System's use.  Virtual memory provides a view of memory that does not necessarily correspond to the physical layout of memory.

This is usually the point in the discussion where the majority of folks start getting confused and their eyes start to glaze over.  In simplistic terms, the memory manager translates the virtual memory addresses into physical addresses where the data is stored.  Every page in virtual memory is listed in a page table which in turn identifies the correct physical page.  The system and CPU use the information from the virtual address to find the correct page table entry for a specific page. 

So, looking at the diagram on the left, we can see that a virtual address points to a specific location on a virtual page.  The virtual address contains a byte offset and several index values that are used to locate the page table entry that maps the virtual page into physical memory.  After the memory manager finds the page table entry, it uses the offset to find a byte in physical memory - identified by a physical address.

And there you have it - a quick look at the basics of Memory Management.  Over the course of the next few posts on Memory Management, we'll talk a bit more about the following topics:Pool Memory, Memory Tuning, Troubleshooting Memory Issues and the infamous /3GB switch.

 - CC Hameed

Your comment has been posted.   Close
Leave a Comment

  • Awesome post, goes over the basics very well but for those of you who like a bit more detail take a look at this.

    keep em coming guys!

  • No sure how I found this blog but its damm good. Check out these that I have been reading today! IE7

  • Only a couple of years ago, desktop machines with 4GB of RAM were rare. Only high-end CAD designers and

  • As promised - here's the long awaited post on the infamous /3GB switch. At least once a week we have

  • In previous posts, we've discussed the Basics of Memory Management , Pool Resources and of course the

  • In previous posts we've discussed the basics of memory management including an overview of kernel and

  • Almost everyone that has ever used Windows has either heard of or experienced a bugcheck - the infamous

  • There is an almost constant stream of posts on forums asking about configuration of SQL Server 2005 memory,

  • Goos summary on the memory manager. Process share memory as they reference a single instance of a DLL. Your web page points IPC and data transfer on disk (in bytes/ sec or quantity of bytes). Note that if an executable loads, only a piece of it loads, and only rerferenced part of the DLL needed loads : a vitualization. As features of the executable are used, then it is paged from disk. the memory manager has to calculate how much physical memory a process needs. It must involve an algorithm based on a prediction schedule obtained from a prefetch file, or something like that. Cool web site.

  •   Being a functional illiterate, I'm tired of low memory on the hard drive and warning messages.  

    Currently there is 60% RAM and 3% hard drive.  While looking for items to uninstall I notice multiple automatic updates and a gazillion uninstall files.  

      When an updaye installs does it include previous updates, therefore, duplicating?  What is safe to uninstall and/or delete?

  • hi hameed,

    you have explained about virtual address space, i would like to know who assigns this virtual address space of 4gb to the process.

    for eg : if i have 3 processes running , does it require to have 12 GB hard disk space ?

  • no, what its talking about is that each process has its own address range.. a virtual pool of memory that is 2GB in size... that 2 GB of virtual space is not allocated on physical memory until its used... so the process thinks it has 2G available to it, but lets say its only using 24MB.. that means only 24MB of physical memory is used.. the virtual memory manager (VMM) does a translations, or a mapping... of this virtual to physical for each process... also, each process has the same address range (00000000-7fffffff) so processA can be using address 00110011 in virtual memory.. but in physical memory it can be anything (you wont really know where it is in physical memory) and at the same time processB can also be using the address 00110011, which is the same virtual address, but on physical memory its different... its just a mapping.... translation... association... basically apps have no idea of physical memory, only virtual

  • should there be any problem if i would up grade my 1gb ram to 2gb,my pc is hp pavillion dv6000 and its kind of slow starting specially when  i browse the internet.

  • I installed windows 7 X64 hearing that the 64 bit version would see up to 24GB. I bought 6-2GB modules and the computer only counts up 8GB. It says 12 in the the control panel and info pages but then it reports: total 12GB:8GB useable. How can windows(or is it my Gigabtye X58-UD3R motherboard?) see,use and report up to 24GB?