Memory management is an important function of an operating system


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.

Legal Disclaimer

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

Related Articles

1. Editing methods in computer graphics
Interactive shape editing is an important field of research in computer graphics, and consequently a variety of different solutions were propos...

2. The guided poisson based method
Inputs to this method are a static triangle mesh M and affine transformations (rotation and scale/shear components), to be applied to nc select...

3. The iterative volumetric laplacian method
In contrast to the two previous methods, the iterative volumetric Laplacian method works on a tetrahedral mesh Ttet and mt tetrahedra Ttet.. A ...

4. New consumer journey in the advertising industry
One could argue therefore that the agenda for advertising shifted from short-term ambition – what people bought after seeing an advertisement – to long term o...

5. Battery life and charging tips for your iPod Touch
Your iPod touch may already have some battery life, but it's a good idea to charge it completely so you can enjoy uninterrupted hours of use as soon you get it set up....

6. Connecting your iPod Touch to iTunes is quite easy
iTunes allows you to activate and register your iPod touch and tie it to your Apple ID. Once you do that, you can buy songs, movies, books, and just about anything else...

7. Maintaining and cleaning tips for your iPod Touch
Cleaning your iPod touch screen After using your iPod touch a little while, you'll see that your fingers (or other fingers besides yours) have left smudges and ...

8. Settings you might find useful for your iPod Touch
Locking the screen in Portrait Orientation As you tilt your iPod touch on its side, in some apps you'll notice that the iPod touch screen rotates to a horizonta...

9. A few accessibility features on the iPod Touch
There are a number of accessibility features on the iPod touch that can be useful, even if you don't have any special problems. The VoiceOver option, for example, reads t...