Nov 30
2007Memory Management
Filed Under (Windows Xp) by Admin on 30-11-2007
Tagged Under : , cpu, How Virtual Memory Works, memory, Memory Management, Memory Pages, ram, rom, Virtual Memory
The memory on your machine is divided into two categories. First, there is the system’s physical memory—RAM chips. These chips are built for exchanging data with the CPU at very high speeds. Unfortunately, high speeds come at high costs, and even the richest know that it isn’t wise to invest all one’s money in RAM.
Instead, we load our systems with all the physical memory our budgets allow, and add to it a cheaper (and slower) storage medium like a hard disk drive. This hard drive is now used to provide us with virtual memory.
Let us look at an OS running multiple tasks. One option for it would be to divide the available physical memory among the tasks, and give each portion to one task. This may make sense for two, maybe three processes which will get all the memory they need, but any more and your system would be slower than a pregnant hippo. Rather than face this, a better option would be to let each process have the memory it needs, and should the physical memory fall short, to store the process’ data on a hard disk, and bring it into the physical memory when needed. This space that the operating system uses on the hard disk is called virtual memory. Using virtual memory, the OS ‘fools’ programs into believing that they have the system memory all to themselves.
How Virtual Memory Works
Consider the case of a process running on your system. It’s one that requires a large amount of memory, but your OS cannot spare that much. What it does instead is load only the most essential part of the process into the physical memory, putting the rest in the virtual memory. Soon enough, the process will raise a ‘page fault’, because it couldn’t find a page it wanted in the physical memory. This, of course, is because your OS put it on the hard drive. At this point, the OS suspends this process, and begins to look for the page in the virtual memory. If it cannot find the page, it tells you that the process cannot go on under these conditions, and kills it. If, however, it does find the required page, it begins to look for free space in the physical memory for it to store this page. If the memory is full, the OS will look for pages that haven’t been used in a long time; it will then take the oldest of these pages, put it into the virtual memory, and use the newly freed space to load the page it got from the virtual memory. It now wakes up the process and tells it that its page is ready.
Memory Pages
Imagine you are looking for a word in the dictionary. You open the dictionary, turn to the page that has your word, and move your finger down to hunt for it. Memory is organised in much the same way. The entire system RAM is your dictionary, memory is organized into pages which hold lots of data, and the OS runs its supposed ‘finger’ down the page to find the data it is looking for.
ABOUT
I would say that I have learned a lot from this post. I will keep coming here.