An important function of the operating system is memory management, which is the service associated with the allocation of main memory. Essentially, the memory manager decides which main memory addresses are associated with which processes at any given time. All the processes currently running, and the operating system itself, have main memory needs that must be met.
When a program is first begun, it is given enough memory to hold some part of the program and data. Over time, the program may request additional main memory space. A request for main memory that occurs during a program's execution is known as a dynamic memory allocation and is a function provided by the operating system.
One problem with dynamic memory allocations is that a program must remember to deallocate the memory when it is no longer needed so the memory can be used by another program, and all programs are expected to return all dynamic memory before closing. If a program neglects to deallocate its dynamic memory when it no longer needs it, the result is a memory leak, a block of memory that is allocated but unused. Memory leaks degrade system performance because, in essence, the system now has less main memory.
Another complication of dynamic memory is that some memory is shared between processes. When this happens, the memory manager's job is more difficult, because it must track each use of the allocated memory. Just because one process has signaled it is done with the memory doesn't mean the memory can be deallocated. Instead, the operating system must wait until all processes have signaled.
Although today's computers have large main memories, they are often not large enough. As memory sizes have grown, the size of the average program has grown even faster. Consider that some software packages come in multiple CD-ROM sets, and a single CD-ROM can hold more data than the main memory for most computers. In addition, because of multitasking, many users are running multiple programs at once.
One way to never run out of RAM is through a technique called virtual memory, in which a larger main memory is simulated through the use of storage on the hard drive. The operating system maintains a table that maps each program's simulated address with the physical addresses in main memory.
The blocks of physical memory that the operating system hands out are called pages. When a process requests a virtual memory range that is not currently in main memory (as TypeEdit did in the second part of the example), it's known as a page fault.
Pages may also need to be written to the hard drive. If a page contains nothing but program instructions, it can simply be written over by another page because the operating system can always retrieve that part of the program again. But if a page contains a program's current data, that data needs to be kept for when the program needs it again.
The operating system maintains a special area on the hard drive, called the swap file, for the temporary storage of pages. For the best performance, this file is usually allocated as one contiguous block in the middle of the disk so that whatever other hard drive access is going on, the needed page is never far away from the read/ write head's current position.
Over time, a process may gain pages or lose pages. The more active a program is, the more pages it is awarded. The goal of the virtual memory manager is to minimize the number of page faults because every page fault is a slow trip back to the hard drive. If you've ever had a large number of programs open at once and then switched from a program you've been using a lot to one you haven't used in a few minutes, you may have noticed a temporary slowdown.
That's because, over time, the active program grabbed most of the pages in memory. When you switched to the inactive program, it suddenly needed a lot of pages it hadn't needed in minutes, and this generated a large number of page faults. In extreme cases, there are so many active processes competing for main memory that the computer spends most of its time swapping pages, a phenomenon known as thrashing. In general, when you see the hard drive light flash and you are not opening or saving a file, it's a good bet you're seeing the virtual memory manager at work.
Our website is not responsible for the information contained by this article. Articleinput.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.
Note: This article was sent to us by: Ryan Welsh at 02122011
1. Editing methods in computer graphics
All articles are property of their respective authors. Please read our Privacy Policy!
© 2009 ArticleInput.com.
Partners: Damenmode