Hoe kan ik het windows 2000/XP/2003 virtuele geheugen (pagefile) optimaliseren.
Geheugen tweaking is een taak voor de systeembeheerder. Teveel geheugen kangeen kwaad maar soms komt het nou eenmaal voor dat meer geheugen even niet beschikbaar is. Dit artikel kan je helpen bij het optimaliseren van het geheugen beheer van Windows 2000, XP en 2003 server.
Parts of this page have information taken from MS MVP Alex Nichol's excellent article about XP Virtual Memory found HERE. Other pieces of information were collected from a blog written by Mike Lee, HERE.
What is Virtual Memory?
In a 32-bit computer, the memory addresses are 32 bits long and stored as binary (base 2) numbers. There are approximately 4 billion possible different 32-bit binary numbers (2^32=4,294,967,296). Because of this, there is a 4GB limit for addressable memory in a 32-bit computer.
A program instruction on an Intel 386 or later CPU can address up to 4GB of memory, using its full 32 bits. Each process is assigned an address space of 4GB of virtual memory, regardless of the amount of available physical memory. Each process is isolated from the rest and has its own 4GB address space. This means that the 4GB addressability limit applies on a per-application basis, not across all applications taken together.
This is normally far more than the RAM of the machine. The amount of physical memory on the computer is not related to the amount of memory address space. If a computer has 256MB of physical memory, there is still a 4GB memory address space, and if a computer has 8GB of physical memory, there is still a 4GB memory address space.
Applications are not allowed direct access to physical memory. When an application requests more memory, Windows maps some physical memory (as long as some is available) into the process's address space.
The hardware provides for programs to operate in terms of as much as they wish of this full 4GB space as Virtual Memory, those parts of the program and data which are currently active being loaded into Physical Random Access Memory (RAM). Windows maintains several tables that keep track of all of this, and the application knows only about the virtual memory address.
The processor itself then translates (‘maps’) the virtual addresses from an instruction into the correct physical equivalents, doing this on the fly as the instruction is executed. The processor manages the mapping in terms of pages of 4KB each – a size that has implications for managing virtual memory by the system.
Why do I need page file optimization?
Optimizing your page file when you're running low on RAM is always a good idea. When all physical RAM in a computer is in use, Windows starts using the hard disk as if it were additional RAM. This is why we have a Pagefile (also called the swap file). Because RAM memory is a lot more faster than the hard disk, whenever the computer begins to use the Pagefile to relieve memory pressure, we begin to experience a drastic performance degradation.
One of the most effective things you can do to improve performance is ensure that there is enough RAM available to avoid frequent paging (swapping) of memory contents between disk and RAM.
This means that the actual limit on the memory used by all applications is the amount of RAM installed plus the maximum size of the Pagefile.
How much swap space do you need? That depends the amount of RAM you have and the programs you use. The rule of the thumb is 1.5 times the amount of system memory, unless you have too much load on your system.
Can the Virtual Memory be turned off on a really large machine?
Strictly speaking Virtual Memory is always in operation and cannot be ‘turned off’. What is meant by such wording is ‘set the system to use no page file space at all’.
This would waste a lot of the RAM. The reason is that when programs ask for an allocation of Virtual memory space, they may ask for a great deal more than they ever actually bring into use – the total may easily run to hundreds of megabytes. These addresses have to be assigned to somewhere by the system. If there is a page file available, the system can assign them to it – if there is not, they have to be assigned to RAM, locking it out from any actual use.
Do you have any specific tweaking tips?
Here are some basic rules you should follow:
If you can spare an extra Hard Disk (preferably a fast one) or if you have some free HD space on your system (again, preferably on a fast HD, and NOT on the HD that's holding the SYSTEM or DATA partitions) I'd suggest you use it for the sole purpose of the Pagefile. Remember that using another partition on the same SYSTEM or DATA HD will not improve your system's performance at all. To do that you'll need a separate fast HD, preferably connected to a different controller.
You can also improve performance by spreading your page file across multiple physical disks, don't worry about the relative speeds of the hard drives Windows 2000/XP/2003 automatically selects the fastest drive to page memory to.
When creating page files, don't confuse hard drives with partitions. You shouldn't create page files on multiple partitions on the same hard drive. This set-up degrades system performance significantly because when Windows NT writes to these page files, the disk arm of the hard drive is forced to swing back and forth across the disk rather than being able to stay in the general area of the single page file. For those with IDE hard drives, it is recommended to place the page file on separate IDE channels.
Let's say we have 512MB of RAM and we decided to create a Pagefile of 768MB.
In Windows 2000 go to My Computer, right click it and then choose Properties, go to the Advanced tab, click Performance Options, then click Change. Now you can view and set the parameters you need:
Notice how Windows 2000/XP/2003 place the Pagefile on the boot partition (I know it says "system" in the image, but still they reference it as the "boot" partition. In this case it's both), the one the OS is installed on (in this case C:). Windows 2000/XP/2003 also make the Pagefile's initial size 1.5 times the size of the physical memory (RAM) installed. The maximum size is 3 times your RAM. Windows NT used a different calculation here.
You can write your settings in the initial and maximum boxes, and then click Set. You'll have to reboot in order for the changes to take place. Note that you have to specify the *same* amount for both values. This will keep your Pagefile from resizing, fragmenting and eventually slowing itself down.
You can also divide the Pagefile between your physical disks (not partitions!) to speed up its performance. Select the required disk from the Drive list, write the sizes in the initial and maximum boxes, and then click Set. Repeat this for all the required drives.
In Windows XP go to My Computer, right click it and then choose Properties, go to the Advanced tab, click Performance Options, then click Settings.
Again click the Advanced tab and then in the Virtual Memory section click Change.
Now you can view and set the parameters you need.
Under Drive [Volume Label], click the drive that contains the paging file you want to change.
Under Paging file size for selected drive, click Custom size, type a new paging file size in megabytes (MB) in the Initial size (MB) or Maximum size (MB) box, and then click Set.
If you decrease the size of either the initial or maximum paging file settings, you must restart your computer to see the effects of those changes. When you increase the paging file size, you typically do not need to restart your computer.
How big should my Pagefile be?
To have Windows choose the best paging file size, click System managed size. The recommended minimum size is equivalent to 1.5 times the amount of RAM on your system, and 3 times that figure for the maximum size. Example, if you have 256 MB of RAM, the minimum size would be 384, the maximum size would be 1152.
For best performance, do not set the initial size to less than the minimum recommended size under Total paging file size for all drives. The recommended size is equivalent to 1.5 times the amount of RAM on your system. Usually, you should leave the paging file at its recommended size, although you might increase its size if you routinely use programs that require a lot of memory.
To delete a paging file, set both initial size and maximum size to zero, or click No paging file. Microsoft strongly recommends that you do not disable or delete the paging file.
To determine your preferred Pagefile size you should monitor your system and see how much RAM and virtual memory it uses. Do a baseline monitoring for a week or so (you can skip the baseline or shorten its duration if you know exactly how much Pagefile you need) and see what was the largest amount of memory your system ever used. If you see it never gets close to the maximum amount of RAM you have installed – don't worry. Your Pagefile is virtually left untouched (not exactly correct, because the system uses the Pagefile for some internal operations and it should keep it at around 5%-10% usage on normal systems). If, on the other hand, you see your system uses more memory than it physically has, this means it uses some Pagefile.
How much Pagefile does your system use?
You should first find out how much memory you're using, and how much of it is on your disk.
Using System Monitor
One accurate way is by monitoring the %Usage Peak counter in the System Monitor tool (The peak usage of the Pagefile instance in percent):
Open Performance console from the Administrative Tools. Click System Monitor and then point at the PLUS (+) sign.
In the Add Counters dialog box open the Performance Objects drop-down list. Look for the Paging File object.
When you click that object select the %Usage counter and click Add.
Look at the graph. Notice if it's steady or increasing in size (you might want to capture this data over a longer period of time – a week or more – by using the System Logs in the Performance Logs and Alerts sub-menu of the Performance console). Notice the Average counter.
Using Task Manager
Another (faster) way to find out is by using Task Manager:
Open Task Manager and go to the Performance Tab.
Notice the Physical Memory section. Look at the Total figures: 785904 K (that's the amount of installed RAM).
How much RAM is available? 372924 K – more than half of the installed RAM. You're doing ok for now.
How much memory is your system committed to? Look at the Commit Charge section, at the Total figures: 429604 K.
What was the largest amount of memory your system has ever committed itself to since the last boot? Look at the Peak figures: 453168 K. This means that you're running close to your peak, and although your system has peaked to around 450000 K, it's still far from using up its RAM. You're ok for now.
Bill James MS MVP has a convenient tool, ‘WinXP-2K_Pagefile’, for monitoring the actual usage of the Page file, which can be downloaded here. A compiled Visual Basic version is available from Doug Knox's site which may be more convenient for some users. The value seen for ‘Peak Usage’ over several days makes a good guide for setting the Initial size economically.
Now, since our system automatically sets its initial Pagefile size to 1.5 times the amount of RAM, you're using 1152 MB or hard disk space on a Pagefile that's not even used (Remember? You're not even close to using ALL you RAM…) Seems like a lot of space to waste. You can safely lower the Pagefile size to around 700 MB, and you can safely assume you'll never even touch it. The only drawback it losing the ability to create a dump file in case your system BSODs on you…
I've taken another snapshot, this time of a Windows XP computer:
Here the Peak was 758064 K, which is ALMOST all the RAM you have. You cannot tell if this was a one-time surge, or something you should expect all the time (here you do need a baseline to tell). You can only say that right now you're safe because you're only using 192992 K or memory out of 785904 K you have. But if you do see that the peak is something that always happens to you, you should set your Pagefile to the minimum of 1.5 times the RAM (which is in fact the default setting).
By the way, you can also see the current amount of memory used by looking at the lower right corner of Task Manager, where it says Commit Charge: 188M / 1426M.
This next snapshot is of a Windows Server 2003 which is having problems:
Had this been YOUR computer, then you could have had problems on your system. Here you're using 530MB out of 934MB of memory you have (made of RAM + Pagefile). This means your system is relying on the Pagefile to operate. Here you must add more RAM ASAP, or at least configure the Pagefile for optimum use.
Are there any more tweaks that can be done to optimize the use and location of the Pagefile?
Yes. There are a few available options.
Even when you set the values properly, some systems don't retain your settings. If this happens, perform the following steps:
Remotely changing Pagefile size and location:
You can also change the value of the Pagefile remotely by manipulating registry values.
Pagefile information is stored in the registry as a multi_string (so you HAVE to use regedt32.exe) and can be changed locally as follows:
To change on another machine you should use the resource kit REG.EXE utility but the command below will replace the current Pagefile and will NOT check you have enough disk space so you may want to create a script that does check. Make sure the machine is rebooted after the change.
C:> reg update "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerMemory ManagementPagingFiles"="<location> <initial size> <max size>" <remote machine>
C:> reg update "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerMemory ManagementPagingFiles"="C:pagefile.sys 700 700" london.nwtraders.msft
Make sure you test this before trying to use on live machines.
If the Pagefile gets fragmented your system's performance will decrease. System Internals has released PageDefrag, a free utility that shows fragmentation in the Pagefile and then offers the option of defragmentation at boot time.
The utility can be downloaded from HERE
Once you download just unzip the file and run pagedfrg.exe. Below is a sample output:
Group Policy Settings
There are a few Group Policy settings available for use.
Create a Pagefile:
Computer ConfigurationWindows SettingsSecurity SettingsLocal PoliciesUser Rights Assignment
This setting determines which users and groups can create and change the size of a Pagefile. You can create a Pagefile by specifying a paging file size for a given drive in System Properties Performance Options.
Shutdown: Clear virtual memory Pagefile:
Computer ConfigurationWindows SettingsSecurity SettingsLocal PoliciesSecurity Options
This setting determines whether the virtual memory Pagefile is cleared when the system is shut down. On a running system, the Pagefile is opened exclusively by the operating system, and it is well protected. However, systems that are configured to allow booting to other operating systems might have to make sure that the system Pagefile is wiped clean when this system shuts down. This ensures that sensitive information from process memory that might go into the Pagefile is not available to an unauthorized user who manages to directly access the Pagefile.
When this policy is enabled, it causes the system Pagefile to be cleared upon clean shutdown. If you enable this security option, the hibernation file (hiberfil.sys) is also zeroed out when hibernation is disabled on a portable computer system.
Problems with Virtual Memory
It may sometimes happen that the system give ‘out of memory’ messages on trying to load a program, or give a message about Virtual memory space being low. Possible causes of this are: