Sei sulla pagina 1di 8

WXES2113 Operating System [Virtual Memory]

Name: FOONG WENG HUI Matric number: WEK 100021

Virtual memory
Virtual memory is a common part of most operating systems on desktop computers. It has become so common because it provides a big benefit for users at a very low cost. Most computers today have something like 4 or 6 gigabytes of RAM available for the CPU to use. Unfortunately, that amount of RAM is not enough to run all of the programs that most users expect to run at once. For example, if you load the operating system, an e-mail program, a Web browser and word processor into RAM simultaneously, 4 gigabytes is not enough to hold it all. If there were no such thing as virtual memory, then once you filled up the available RAM your computer would have to say, "Sorry, you cannot load any more applications. Please close another application to load a new one." With virtual memory, what the computer can do is look at RAM for areas that have not been used recently and copy them onto the hard disk. This frees up space in RAM to load the new application. Because this copying happens automatically, you don't even know it is happening, and it makes your computer feel like is has unlimited RAM space even though it only has 4 gigabytes installed. Because hard disk space is so much cheaper than RAM chips, it also has a nice economic benefit. The read/write speed of a hard drive is much slower than RAM, and the technology of a hard drive is not geared toward accessing small pieces of data at a time. If your system has to rely too heavily on virtual memory, you will notice a significant performance drop. The key is to have enough RAM to handle everything you tend to work on simultaneously -- then, the only time you "feel" the slowness of virtual memory is when there's a slight pause when you're changing tasks. When that's the case, virtual memory is perfect. When it is not the case, the operating system has to constantly swap information back and forth between RAM and the hard disk. This is called thrashing, and it can make your computer feel incredibly slow. The area of the hard disk that stores the RAM image is called a page file. It holds pages of RAM on the hard disk, and the operating system moves data back and forth between the page file and RAM. On a Windows machine, page files have a .SWP extension.

Virtual Memory Configuration


Windows 98 is an example of a typical operating system that has virtual memory. Windows 98 has an intelligent virtual memory manager that uses a default setting to help Windows allocate hard drive space for virtual memory as needed. For most circumstances, this should meet your needs, but you may want to manually configure virtual memory, especially if you have more than one physical hard drive or speed-critical applications. To do this, open the "Control Panel" window and double-click on the "System" icon. The system dialog window will open. Click on the "Performance" tab and then click on the "Virtual Memory" button. Click on the option that says, "Let me specify my own virtual memory settings." This will make the options below that statement become active. Click on the drop-down list beside "Hard disk:" to select the hard drive that you wish to configure virtual memory for. Remember that a good rule of thumb is to equally split virtual memory between the physical hard disks you have.

In the "Minimum:" box, enter the smallest amount of hard drive space you wish to use for virtual memory on the hard disk specified. The amounts are in megabytes. For the "C:" drive, the minimum should be 2 megabytes. The "Maximum:" figure can be anything you like, but one possible upper limit is twice physical RAM space. Windows default is normally 12 megabytes above the amount of physical RAM in your computer. To put the new settings into effect, close the dialog box and restart your computer. The amount of hard drive space you allocate for virtual memory is important. If you allocate too little, you will get "Out of Memory" errors. If you find that you need to keep increasing the size of the virtual memory, you probably are also finding that your system is sluggish and accesses the hard drive constantly. In that case, you should consider buying more RAM to keep the ratio between RAM and virtual memory about 2:1. Some applications enjoy having

lots of virtual memory space but do not access it very much. In that case, large paging files work well. One trick that can improve the performance of virtual memory (especially when large amounts of virtual memory are needed) is to make the minimum and maximum sizes of the virtual memory file identical. This forces the operating system to allocate the entire paging file when you start the machine. That keeps the paging file from having to grow while programs are running, which improves performance. Many video applications recommend this technique to avoid pauses while reading or writing video information between hard disk and tape. Another factor in the performance of virtual memory is the location of the page file. If your system has multiple physical hard drives (not multiple drive letters, but actual drives), you can spread the work among them by making smaller page files on each drive. This simple modification will significantly speed up any system that makes heavy use of virtual memory.

Virtual Memory Fragmentation


Virtual memory is a way of providing every running process with the same liner memory address space, all processes can allocate memory from the same virtual location as they are completely isolated from each other, an operating systems memory manager provides a translation from the processes virtual address space into the physical memory it occupies. On a 32-bit Windows operating system, every process is allocated a 4Gb virtual address space. On a standard system configuration this is split into 2 equal parts. 0x00000000 0x7FFFFFF 2Gb of user mode virtual address space applications can allocate for their own use. 0x80000000 0xFFFFFFFF 2Gb of kernel mode virtual address space which contains the operating system image, device drivers, page frame umber (PFN) database, system page table entries (PTEs), paged and nonpaged memory pools. The user mode portion of the address space is unique to every running process giving every process up to 2Gb of memory to consume. The kernel mode portion is shared and is mapped into every process. Its for this reason people refer to the 32-bit 2Gb kernel memory limit as one of the main resource limitations in a Terminal Server / Citrix environment. Hundreds of users can be running thousands of processes all with their own 2Gb user mode address space, but all sharing the same 2Gb kernel mode space. The /3GB boot.ini switch can alter the split giving each processes a 3Gb user mode virtual address space, limiting the shared kernel mode address space to 1Gb. With 64-Bit Windows, virtual address space sizes have increased significantly. The current size of the user mode address space is 8192GB and system PTE, system cache, paged pool and nonpaged pool all having a 128GB allocation in kernel mode.

What is Fragmentation? Fragmentation of any virtual address space occurs over time as more and more blocks of memory are allocated and freed. Memory allocations can only succeed in contiguous blocks of memory, for example if a 2mb allocation was requested it would be allocated from a complete contiguous 2mb block of virtual memory and not from a 1mb block at the start of the pool and a 1mb block at the end. When a virtual address space is initially created all of it is available for allocation and requests are simply satisfied from the next available virtual address.

Fragmentation only begins to occur when memory allocations are freed.

Fig 2 shows a single fragmentation of 20Mb. Blocks of free space in between allocations can be reused providing the requested allocation is small enough to fit. Figure 3 below shows the 20mb fragmentation reused by 2 additional 10mb allocations.

So when does fragmentation become a problem?

When an address space becomes very fragmented it can cause larger memory allocations to fail as there is not enough contiguous space to satisfy the request. Take Figure 4 as an example, as the address space is fairly fragmented the largest single allocation possible is 30mb, anything larger would fail even though there is a total of 80mb available for allocation in the address space. 8 allocations of 10mb would succeed where as 2 allocations of 40mb would fail. Is this a problem? Typically a user would never have problems with fragmentation, in user mode a process would need to allocate close to the 2Gb limit (x86), before experiencing any problems, it also depends on how an application developer has written their application. For example a 10kb buffer is required to perform an operation which will be repeated several thousand times. Does the developer allocate the 10kb buffer once when the program starts, or does it get allocated and freed each time it is required. The more memory allocations an application performs the more fragmented the address space can become. Memory allocation failures due to fragmentation are most often seen in the kernel mode address space specifically in the paged and nonpaged system memory pools. As these 2 pools are used by almost every component in all operations performed in kernel mode they can

become exhausted and very fragmented especially under workloads such as Terminal Services. I have seen examples of users failing to connect to a Citrix XenApp server because the ICA remote display driver could not allocate 400Kb of paged pool memory even though there was more than 30mb available at the time. What can be done? Today there is not a lot that can be done to resolve this. When memory allocations succeed a pointer to the start of the memory block is returned, if Microsoft were to implement background memory defragmentation routines, the original returned memory pointers would change as a result. There are no notification methods available in Windows to signal processes that memory allocations have moved. Windows applications assume the address given after a successful memory allocation is valid and will not change until it is freed.

Conclusion
The virtual memory functions enable a process to manipulate or determine the status of pages in its virtual address space. They can perform the following operations:

Reserve a range of a process's virtual address space. Reserving address space does not allocate any physical storage, but it prevents other allocation operations from using the specified range. It does not affect the virtual address spaces of other processes. Reserving pages prevents needless consumption of physical storage, while enabling a process to reserve a range of its address space into which a dynamic data structure can grow. The process can allocate physical storage for this space, as needed. Commit a range of reserved pages in a process's virtual address space so that physical storage (either in RAM or on disk) is accessible only to the allocating process. Specify read/write, read-only, or no access for a range of committed pages. This differs from the standard allocation functions that always allocate pages with read/write access. Free a range of reserved pages, making the range of virtual addresses available for subsequent allocation operations by the calling process. Decommit a range of committed pages, releasing their physical storage and making it available for subsequent allocation by any process. Lock one or more pages of committed memory into physical memory (RAM) so that the system cannot swap the pages out to the paging file. Obtain information about a range of pages in the virtual address space of the calling process or a specified process. Change the access protection for a specified range of committed pages in the virtual address space of the calling process or a specified process.

Potrebbero piacerti anche