|
Free Open Book
PC Hacks 100 Industrial-Strength Tips and Tools |
Hack 34 Manage the Paging File
Windows can get confused about what memory is and how it uses it. Giving Windows some guidance will keep things running smoothly. Ever encounter an "out of memory error"? Been advised by an on-screen dialog message to "close some applications to free up memory"? These errors are usually not about adding or removing memory, but about how the operating system uses the memory available. Windows and some applications can present any number of "out of memory" error messages, such as:
Microsoft Windows 3.x-95/98/Me manage many types of memory—mostly RAM, but within and beyond the obvious system RAM, other resources that store data while the operating system and applications do their things. There are three causes for "out of memory" conditions under Windows 9.x: truly having too little RAM to support the operating system, having too little free disk space for the operating system to be able to swap memory contents to the swapfile on a hard drive, or forcing the swapfile size into too small and overcrowded small segments of memory called "system resources." A solution to the first problem is of course to add more memory [Hack#32]. When you've reached that point, 64-128MB of RAM or more if applications need it, it's time to look elsewhere for what's keeping Windows from being happy [Hack #35] or examine the Windows swapfile The paging file or swapfile is controlled by Windows. While users can configure how much disk space to allocate to this file, only Windows decides how and when it is used. Left on its own, Windows could create a swapfile that is larger than necessary, or you could manually configure an unreasonably large swapfile yourself and waste hundreds of megabytes of disk space. If the hard drive has too little free space available for making a swapfile, Windows can indicate "out of memory," meaning it could not swap out enough RAM contents to disk to leave your applications or data and the operating system enough memory to work with. If the swapfile size is left for Windows to decide, it will also suffer fragmentation and be broken up across many different regions of the disk drive, further reducing performance. Swapfile fragmentation will occur if there is no single area of free space large enough to contain the entire swapfile, or, if the swapfile starts out at one size, files are subsequently stored "around it," and then the swapfile has to grow into a separate area of free space.
There are several rules of thumb that can be applied to configuring the size of the swapfile. In most cases, the swapfile size should be at least equal to the amount of RAM installed on the system—that is, if you have 32 MB of RAM, the swapfile should equal at least 32 MB of disk space and preferably 2-3 times more (64-96 MB). The debate rages at this point whether or not the size of the swapfile should be exactly equal to, 150%, or 200%, or more of the amount of RAM in the system. Depending on the amount of RAM installed, most of us use 150% as the maximum value to give Windows a little extra room, but not an excessive amount, to play with. It is important to remember that each version of Windows has a minimum RAM requirement, as shown in Table 4-1. Your system should have enough RAM to accommodate Windows (the minimum requirement) plus your applications and data if you want to reduce swapfile use and manage its size. Setting the swapfile size tells Windows how much disk space it can play with when it decides it's time to swap a program or data out the file. You want Windows using the hard drive sparingly, and when it does use it, you want it to use it as efficiently as possible. So how do you determine what "size" to make the swapfile?
If you have less than 128 MB of RAM, set the swapfile to be at least equal to, or up to 150% of, the amount of RAM. At less than 128 MB of RAM, Windows is going to swap out idle programs and data more than it would with 128 MB of RAM. Going to a 150% swapfile size gives Windows room to rattle around and enough space for applications to play in memory, and enough swapfile space to swap it all out if necessary. If you have more than 128 MB of RAM, you have to start believing that you have more than enough RAM to keep the operating system (at least Windows 95-Me) and most of your applications happy, since you've met the minimum RAM requirement for the operating system plus additional RAM for applications. At 128, 256, or 512 MB of RAM, the swapfile size should be equal to no more than the amount of RAM—after all, even a portion of 128, 256, or 512 MB is a lot of disk space to waste and a lot of data to read and write on a disk drive if Windows has to swap out, which considerably slows the system performance but is better than running out of memory. It is obviously far better to add more RAM than hit the ceiling of RAM+swapfile size or keep increasing the swapfile size to overcome having too little RAM. For systems with abundant amounts of RAM, certainly at the 512 MB to 1 GB level, setting the swapfile to no less than 50% of the amount of RAM typically provides good performance. However, if you frequently use multiple large applications or have multiple large datafiles open, the swapfile should equal the amount of RAM so Windows has adequate space to swap to. Table 4-3 gives recommendations for swapfile sizes.
To ensure the best performance of the swapfile and prevent the swapfile from changing size and becoming fragmented, set the minimum and maximum size of the file to the same values. For a recently defragmented PC, setting the swapfile size will create a new, unfragmented swapfile. If you set the minimum and maximum sizes to different values, the swapfile can become fragmented and only a disk defragmenter that can defragment the swapfile can put it back together for a short time. To set the swapfile size, follow these specific instructions for your operating system:
4.6.1 Windows 95, 98, 98SE, Me
4.6.2 Windows NT, 2000, XP, 2003
4.6.3 Hacking the HackWindows NT, 2000, XP, and Windows Server 2003 can't defragment the pagefile, because it is open for exclusive use while the system is up and running. Sysinternals PageDefrag (http://www.sysinternals.com/ntw2k/freeware/pagedefrag.shtml) gets around this problem by defragmenting your pagefile at the next reboot: it uses the same defragmentation mechanism that Windows uses, but it runs before the operating system has opened the pagefile for exclusive use.
|
Main Menu
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |