paging file, swapfile, optimization.

Although the hard disk is much slower than RAM, it is also much cheaper and users always have a lot more hard disk space than RAM. So, Windows and other OSs are designed to create this pseudo-RAM or in Micro$oft's terms - Virtual Memory, to make up for the shortfall in RAM when running memory-intensive programs.

Virtual memory is created using a special file called a swapfile or pagig file.

Whenever the operating system has enough memory, it doesn't usually use virtual memory. But if it runs out of memory, the operating system will page out the least recently used data in the memory to the swapfile in the hard disk. This frees up some memory for your applications. The operating system will continuously do this as more and more data is loaded into the RAM.
However, when any data stored in the swapfile is needed, it is swapped with the least recently used data in the memory. This allows the swapfile to behave like RAM although programs cannot run directly off it. It must be noted that the operating system cannot directly run programs off the swapfile, and that some programs may not run, even with a large swapfile, if you have too little RAM. (This may be due to the program needing to store sensitive data on something less volatile than the RAM etc) 

The swapfile and paging file are really quite different. Although both are used to create virtual memory. The main difference is that Swapfiles operate by swapping entire processes from system memory into the swapfile. This immediately frees up memory for other applications to use. In contrast, paging files function by moving "pages" of a program from system memory into the paging file. These pages are 4KB, or more, in size. The entire program does not get swapped into the paging file.
While swapping occurs when there is heavy demand on the system memory, paging can occur pre-emptively. This means that the operating system can page out parts of a program when it is minimized or left idle for some time. The memory used by the paged-out portions is not immediately released for use by other applications. Instead, they are kept on standby.

If the paged-out application is reactivated, it can instantly access the paged-out parts (which are still stored in system memory). But if another application requests for the memory space, then the system memory held by the paged-out data is released for its use. so, this is really quite different from the way a swapfile works. Swapfiles were used by Microsoft prior to Windows 95. From Windows 95 onwards, all Windows versions use only paging files. The correct term for the file used to create virtual memory in current operating systems is paging file, not swapfile.

Virtual memory

Nowadays; when the average home user's computer comes with at least 512MB of RAM, the paging file is still very important. The large amount of RAM found in the average user's computer reduces the risk of memory shortage with single applications, however; the paging file is essential when multi-tasking.

As multi-tasking has arrived for good at last on the PC platform (the Amiga OS had it from the very start). We can now run loads of applications at the same time. It is common to have 15 or more applications running together.

With 512MB of RAM, it could be possible to load everything into memory. But a paging file is really needed to stop the system from crashing, and store the least used data into the virtual memory.

It should be noted that Win98 and XP allocate a sizeable portion of the RAM to the disk cache. This speeds up accesses to hard disk data by caching the most frequently used as well as data that are most likely to be accessed next by the computer. This cuts down on the amount of available RAM. So, without a paging file, you won't be able to open many applications with, say, 256MB of RAM.

Unless your computer at least a Gigabyte of RAM, it will almost always use the paging file. As such, its performance affects the performance of the whole computer. Even the fastest hard disk is currently over 70X slower than the slowest dual-channel PC2700 DDR memory common in many computers. (But hopefully you're using the faster PC3200 DDR memory or PC2-4200 DDR2 memory.)

Remember: Paging file is only a stopgap solution for the lack of sufficient RAM. As long as you use the paging file, there will always be performance degradation. The ideal solution for insufficient RAM is always more RAM, not more Virtual Memory.
But, until you save up for more memory, a paging file is necessary to run today's memory guzzling programs.

Remember, more paging file space will give you the ability to run more memory intensive programs at once. However, it will not speed up your system. But there are a few tricks we can do to optimise the paging file so that the performance degradation when using it is minimized.
There have been many theories on how to optimise the paging file.
The most important ones are listed below

  • Making the paging file contiguous.
  • Moving the paging file to the outer tracks of the hard disk.
  • Creating a huge paging file.
  • Moving the paging file to a different partition in the same hard disk.
  • Moving the paging file to a different hard disk.
  • Creating multiple paging files
  • Using an optimal cluster size
  • Moving the paging file to a RAID array
  • Moving the paging file to a RAM drive
  • Reducing reliance on virtual memory

Back in the bad old days of DOS 6.22 and Windows 3.1, a permanent swapfile was the best solution for optimal swapfile performance. Windows 3.1 only creates contiguous, permanent swapfiles. A contiguous swapfile is a swapfile that consists of an uninterrupted block of hard disk space. When a swapfile is contiguous, the read-write heads of the hard disk can read and write data on the swapfile in a continuous fashion.
In Windows 3.1, if the swapfile was set up as a temporary swapfile which is created every time Windows 3.1 boots up, it will end up at the end of the hard disk and fragmented too. So, every time the swapfile is read from or written to, the hard disk heads have to seek all over the platters to conduct those operations. This degrades the performance of the swapfile. So it was important to make the swapfile permanent in Windows 3.1 - so that the swapfile will become contiguous.
From Windows 95 onwards, Microsoft encouraged the use of its new dynamic virtual memory system. Of course, there is nothing new about the virtual memory part but the keyword in this new technique is dynamic.
The new dynamic virtual memory system no longer relies on a fixed-size swapfile but a paging file that dynamically resizes itself according to need. When the computer runs out of memory, more memory is created by increasing the size of the paging file. Once the virtual memory is freed up, theoretically the paging file diminishes in size.
Microsoft claims that while its dynamic virtual memory system will create a fragmented paging file, it is still faster than Windows 3.1's static virtual memory system. As a bonus, no hard disk space will be tied up in a permanent paging file.

However, this dynamic virtual memory system does have a big disadvantage - it cannot be moved to the outer tracks of the hard disk platters.
There are people who assert that when left alone, Windows XP will actually create virtual memory pages in close proximity to frequently-used data in the hard disk, like documents. In other words, they claim that Windows XP monitors disk usage, maintains a database of frequently-used files in the hard disk and uses that information to create the paging file based on spatial locality.
With virtual memory pages created close to frequently-used data, this apparently allows shorter seeks between frequently-used data and the paging file. That is the premise behind their theory of letting Windows XP handles the paging file dynamically. However, this may not be true at all.
First of all, while Windows XP does monitor disk usage and maintain a database of frequently-used files, only disk defragmenting utilities use that database. The built-in Disk Defragmenter, as well as third-party disk defragmenting utilities, use this database to rearrange the hard disk so that frequently-used data.
And it seems that the paging file does not arrange the location of the pages according to this database; Windows XP simply uses the nearest available clusters for the dynamic paging file. In fact, Microsoft states that if you create multiple paging files, Windows XP will favour the partition that is least active. This completely refutes the theory of virtual memory pages being allocated according to spatial locality. Here is a quote from Microsoft's Knowledge Base.
By design, Windows uses the paging file on the less frequently accessed partition over the paging file on the more heavily accessed boot partition. An internal algorithm is used to determine which paging file to use for virtual memory management.
In any case, it doesn't make sense for Windows XP to create the paging file based on spatial locality to work files like your documents. Once opened, Windows keeps the working copy in the Temp folder, not your paging file.
Windows pre-emptively pages out pageable parts of an application in system memory. Windows does not directly load data from the hard disk into the paging file. Creating virtual memory pages close to frequently-used files will not help at all.
Even though Microsoft asserts that the new dynamic virtual memory system does not benefit much from a contiguous paging file, the fact is maintaining a contiguous paging file will definitely improve the paging file's performance.

A contiguous paging file eliminates the need for the hard disk heads to seek all over the platters while accessing the paging file.

Fragmented paging file (brown)

See how a contiguous paging file differs from a fragmented paging file? Instead of seeking and reading from a continuous block of hard disk space in the case of a contiguous paging file, the hard disk heads have to seek all over the platters to access the clusters allocated to a fragmented paging file.

As a result, a common operating pattern like the following may emerge :-

Contiguous paging file (brown)

Of course, the amount of time needed to do the seek operation is different from the time needed to read a block of data off the paging file but the logic remains.

Now that we agree that making the paging file contiguous will greatly improve its performance, let's figure out how to make it contiguous.

Fragmented : seek-read-read-seek-read-seek-read-read-read-seek-read-read-seek

Contiguous : seek-read-read-read-read-read-read-seek-read-read-read-read-read

"Simple! Just make the paging file permanent!"

Hum, creating a permanent paging file is usually the way to create a contiguous paging file. A permanent paging file ensures that the paging file will remain in one single block. However, creating a permanent paging file does not mean the paging file will automatically become contiguous. That may have been true in Windows 3.1 but, Windows XP does not force the creation of a contiguous paging file when you make the paging file permanent!
When you create a permanent paging file, Windows XP automatically uses the nearest (to the outer tracks) sectors to create the paging file. This creates a permanent but fragmented paging file. Naturally, this reduces the performance of the paging file.
But that's not the end of the world. To avoid this problem, defragment your hard disk before creating the permanent paging file. That will create a contiguous area for Windows XP to create a permanent paging file.
But making a permanent paging file is not the only way to create a contiguous paging file. You can also create a contiguous paging file that is also dynamic in nature!
All you need to do is create a separate partition for the paging file. This allows the paging file a contiguous space on the hard disk to freely expand according to usage. At first glance, the benefits of this method seem obvious. It ensures the paging file is always contiguous and yet has the ability to expand when the need arises. However, this method is really not very desirable when you examine it closely. The main reason for using a dynamic paging file is to save hard disk space by using it only when there is a need for more virtual memory. But creating a partition to allow the paging file to dynamically resize is really defeating the purpose. The size of the partition limits the maximum size that the dynamic paging file can expand to and you cannot use the partition to store anything else because that would interfere with its contiguity. If you create a big partition, that wastes hard disk space. If you create a small partition, which limits how big the paging file can expand. Therefore, this method is self-defeating.

A contiguous paging file allows data to be read with minimal amount of seeks. If the number of seeks can be reduced while accessing the paging file, then more data can be read in less time. This is the premise behind a contiguous paging file.
Although everyone knows about dynamic and permanent paging files, there is a third type of paging file - a semi-permanent paging file.
A semi-permanent paging file theoretically allows you to receive the performance benefits of a contiguous permanent paging file without its main disadvantage - the need to predetermine an optimal size. But what is a semi-permanent paging file?
A semi-permanent paging file is a combination of a permanent paging file and a dynamic paging file. It consists of a permanent part and a dynamic part. The permanent part of this paging file behaves exactly like a permanent paging file. It will not change in size and can thus be moved to the outer tracks of the hard disk.
The dynamic part, however, does not normally appear. In fact, it is only created when the permanent part of the semi-permanent paging file is unable to cope with increased memory requirements.
Once created, it dynamically resizes itself to suit the current paging file requirements. Just like the dynamic paging file, it will use any free space on the hard disk so it will be fragmented.
The semi-permanent paging file offers the advantage of never running out of virtual memory. That means even if the permanent part cannot handle the memory load, the application won't halt with an "Out of memory" error message. The dynamic part will come into action and provide the extra virtual memory required by the application.

With a permanent paging file, the application will just halt with the error message and you would have to close one or more applications to free up more memory. However, this is only true for older versions of Windows.

Newer iterations of Windows like Windows XP do not have a true permanent paging file. Even if you set a permanent paging file, Windows XP will automatically generate more virtual memory when it runs out of memory; by adding a dynamic component to the permanent paging file. In short, when you create a "permanent" paging file in Windows XP, you are actually creating a semi-permanent paging file. The bonus of a semi-permanent paging file, instead of a "permanent" paging file in Windows XP is that there isn`t the warning message that appears whenever Windows XP runs out of memory and has to create more virtual memory by adding a dynamic component to the permanent paging file.
However, not all is rosy with semi-permanent paging filing. With a dynamic component, it is inevitable that a dynamic paging file's disadvantages would also be applicable to it. The dynamic part will use any available space on the hard disk. Unfortunately, this means the dynamic part of the semi-permanent paging file will always be fragmented. Consequently, the performance of the paging file deteriorates whenever the dynamic part comes into action.

But just how bad could be the deterioration be?
The disk map below which shows a semi-permanent paging file with both permanent and dynamic components shown in brown

Contiguous paging file (brown)

You will notice that the paging file is split into two parts. The permanent part is at the outer tracks of the hard disk in one contiguous block. The lower, fragmented blocks of paging file are the dynamic part of the semi-permanent paging file. As the paging file requirement exceeds what the permanent part can provide, the dynamic part of the semi-permanent paging file will dynamically convert available hard disk space (which is usually on the inner tracks on the hard disk) into virtual memory.

Fragmented paging file (brown)

This shows a semi-permanent paging file (brown)

Because the paging file's two components are at opposite ends of the hard disk, the hard disk heads will have to seek up and down the platters while servicing the paging file! Needless to say, that greatly degrades the performance of the paging file. The head seeks required to service a dynamic paging file are already bad enough. The amount of head seeks required to service both the permanent part and the fragmented dynamic part will definitely put a big dent on the paging file's performance.

 

Performance-wise, both a permanent and a semi-permanent paging file will perform equally, if the virtual memory requirement does not exceed what the permanent component of the semi-permanent paging file can provide. As the dynamic part comes into play, the semi-permanent paging file gradually loses its performance advantage over the dynamic paging file. Eventually, it may even become slower than a dynamic paging file.
A way around this is to make sure that the permanent part of the semi-permanent paging file is large enough to meet your usual virtual memory requirements. Do not look at the semi-permanent paging file as a way to save hard disk space. Instead, think of it as a permanent paging file with a backup capacity for dynamic expansion in emergencies!
Hard disk space is no longer that much of a premium as it was back in the old days. With desktop hard disks approaching half a terabyte in size, allocating a few hundred megabytes or even a gigabyte or so for the paging file isn't going to break anyone's heart. The performance of the paging file, especially in systems with very little RAM or for people who multitask a lot, is definitely more important than saving a few hundred megabytes of hard disk space.

Creating a permanent or semi-permanent paging file inevitably causes numerous writes and rewrites of information in the same fixed area of the hard disk platters. Compared to other areas of the hard disk, the space allocated to the paging file will be the area where data is most often written, deleted and replaced with newer data.
Some users have expressed concern over this fact. Will the platter media in that area get worn out after continuous use? Like the magnetic cassettes that we used to record our favourite songs? Will bad sectors form in that area like the floppy disks that have been written to once too often?

Well, unlike magnetic cassettes or floppy disks, there is actually no contact between the hard disk read-write heads with the platters. The read-write heads actually fly over the platters on a thin cushion of air. In fact, at the high speed that the platters are spinning at, any contact between a read-write head with a platter would have resulted in a head crash, with disastrous consequences.
Therefore, friction isn't the concern here. What about the effect of changing the magnetic properties of the media during the write process? Will the magnetic properties of the media deteriorate after too many of such changes? Or in the context of this article, will creating a permanent paging file damage the drive in the long run and reduce its MTBF ( Mean Time Between Failures)?

This should not hurt the drive at all. As you are aware, the heads are actually suspended above the platters on an air bearing, so there is no direct contact with the media. As far as the recording and re-recording of the same tracks, also no problems. What we are dealing with here in order to write the data is simply moving the magnetic domain one way or the other, no wear involved.

- Bob
Seagate Tech Support

Remember, the heads truly fly above the media. The wear and tear factor only becomes an issue for bearings (heat) and physical damage to the media if the drive is shocked during operation. Performance is best at the outer tracks of the drive, so any recurring access directed there will benefit you in performance. Writing and rewriting data to a drive is good in that it remagnetises (refreshes) the area every time it is written.

Your swap file will not affect the MTBF of your drive.
- Don Gardner
IBM Hard Disk Technical Support/SIT Lab

Well, it appears to be so. The signal carried by the media weakens with time and rewriting it refreshes and strengthens the signal strength of the data carried by the media.
Creating a permanent or semi-permanent paging file won't harm your drive. In fact, it might even be good for your data!

Windows 95/98

Windows 98

Creating A Permanent Paging File In Windows 9x

Luckily, Microsoft gave us a relatively painless way to create a permanent paging file though the proper directions were not included.

First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties. Once in System Properties, click on the Performance tab.

Right at the bottom, you'll see a Virtual Memory button.

By default, it is set to Let Windows manage my virtual memory settings. (Recommended). Ignore the Recommended label and select Let me specify my own virtual memory settings.

Now, you will be allowed to choose the partition you wish to place the paging file in. We will touch on this later.

Next up is the minimum and maximum values for the paging file. To create a permanent paging file, both values must be the same. You would think that Microsoft could at least post a notice about that.

Please note that Windows 95/98 will not automatically add a dynamic component to a permanent paging file. If you run out of memory with a permanent paging file, it will halt the application and generate the "Out of memory" error message.

Naturally, you will have to decide on a size for the paging file. We will be discussing this later in the guide but in this example, we will use an arbitrary value of 150MB. Once you set the two values, click on OK and then let Windows 95/98 reboot the system. A permanent paging file will be created on your hard disk.

virtual memory

Virtual memory

For the curious, do not click on Disable virtual memory. (Not recommended) because that will force Windows 95/98 to use only physical RAM.

In Windows 2000, it takes a little bit more digging to get where you want.

First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties.

Once in System Properties, click on the Advanced tab. There will be three options. Click on Performance Options...

The second section you see is titled Virtual Memory. Under it, there's a Change button.

By default, there won't be any values set for both the Initial size (MB) and the Maximum size (MB) options.

You can select the partition you wish to place the paging file in by clicking on the list of partitions shown on the screen. Again, the selection of partition will be discussed in detail later in this article.

To create a permanent paging file, both values for the Initial size and the Maximum size must be the same.
Please note that Windows 2000 will not automatically add a dynamic component to a permanent paging file. If you run out of memory with a permanent paging file, it will halt the application and generate the "Out of memory" error message.
Naturally, you will have to decide on a size for the paging file. We will be discussing this later in this article but for now, we will use an arbitrary value of 150MB. Once you set the two values, click on OK and then let Windows 2000 reboot the system. A permanent paging file will be created on your hard disk.
You will note that Windows 2000 does not allow a paging file size of less than 2MB. Like in Windows 2000, it takes a little digging in Windows XP to get where you want.
First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties.

Once in System Properties, click on the Advanced tab. There will be three sections.

Click on Settings in the Performance section and the Performance Options screen will pop up.

Janus

The second section you see is titled Virtual memory. Under it, there's a Change button.

You can select the logical drive you wish to place the paging file in by clicking on the list of logical drives shown on the screen. Again, the selection of logical drives will be discussed in detail later in this article.

To create a permanent paging file, both values for the Initial size and the Maximum size must be the same.

Please note that Windows XP will dynamically expand the paging file when you run out of memory, even if you create a permanent paging file. When this happens, you will get an error message telling you that Windows XP is trying to expand the paging file to create more virtual memory.

In this example, we are using an arbitrary value of 512MB. Once you set the two values, click on OK and then let Windows XP reboot the system. A permanent paging file will be created on your hard disk.

You will note that Windows XP does not allow a paging file size of less than 2MB.

Creating a semi-permanent paging file is rather similar to creating a permanent paging file.

First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties.

Once in System Properties, click on the Advanced tab. There will be three sections.

Janus

Click on Settings in the Performance section and the Performance Options screen will pop up. Click on the Advanced tab.

The second section you see is titled Virtual memory. Under it, there's a Change button.

You can select the partition you wish to place the paging file in by clicking on the list of partitions shown in the window.

To create a semi-permanent paging file, you will need to set both the minimum and maximum values. They must not be the same. If they are the same values, then the paging file becomes a permanent paging file.

The minimum value determines the size of the permanent component of the semi-permanent paging file. The maximum value determines the maximum size of the paging file (both permanent and dynamic components) and thus limits how much the dynamic component can expand.


XP

My xp setup

Windows XP will create a permanent paging file of 512MB when it starts up. But if the paging file cannot meet the memory demands of the computer, it will dynamically expand the paging file, up to a maximum of 768MB.

It is highly recommended that you create a large permanent component that will meet all of your usual memory needs. Use the dynamic component as a backup for emergencies.

Once you set the two values, click on OK and then let Windows XP reboot the system. A permanent paging file will be created on your hard disk. Please note that the dynamic component of the paging file will only become active after the system's virtual memory requirements exceed the minimum value.

You will note that Windows XP does not allow a paging file size of less than 2MB.

 Creating a semi-permanent paging file is rather similar to creating a permanent paging file.                       

First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties.

Once in System Properties, click on the Advanced tab. There will be three sections.

Click on Settings in the Performance section and the Performance Options screen will pop up. Click on the Advanced tab.

The second section you see is titled Virtual memory. Under it, there's a Change button.

XP

You can select the partition you wish to place the paging file in by clicking on the list of partitions shown on the screen. Again, the selection of partition will be discussed in detail later in this article.

To create a semi-permanent paging file, you will need to set both the minimum and maximum values. They must not be the same. If they are the same values, then the paging file becomes a permanent paging file.

The minimum value determines the size of the permanent component of the semi-permanent paging file. The maximum value determines the maximum size of the paging file (both permanent and dynamic components) and thus limits how much the dynamic component can expand.

In the example above, Windows XP will create a permanent paging file of 512MB when it starts up. But if the paging file cannot meet the memory demands of the computer, it will dynamically expand the paging file, up to a maximum of 768MB.

It is highly recommended that you create a large permanent component that will meet all of your usual memory needs. Use the dynamic component as a backup for emergencies.

Once you set the two values, click on OK and then let Windows XP reboot the system. A permanent paging file will be created on your hard disk. Please note that the dynamic component of the paging file will only become active after the system's virtual memory requirements exceed the minimum value.

You will note that Windows XP does not allow a paging file size of less than 2MB.

Making The Paging File Contiguous

After creating a permanent or semi-permanent paging file, check and make sure it is contiguous. You can ensure it is contiguous by defragmenting the hard disk before you creating the permanent or semi-permanent paging file. However, that does not always work..

Moving The Paging File To The Outer Tracks

Moving the paging file to the outer tracks is a powerful way of increasing paging file performance. In fact, it will give the paging file a bigger boost in performance than just making it contiguous. Why is that?
The transfer rate of a hard disk is highest on the outer tracks and lowest on the inner tracks.
The area density of a hard disk's platters and its spin rate are constant. But the linear velocity at each point of the platter isn't constant. Therefore, the performance of the paging file depends on where it is located on the hard disk.
The time taken for the hard disk head to read from point A to point B is exactly the same as the time taken for the head to read from C to D. But because the area density of the platter is constant, a lot more data can be read from the outer tracks than from the inner tracks, in the same amount of time. Now that the outer tracks have been proven to be the fastest area on a hard disk, we can use that to our advantage. By moving the paging file to the outer tracks, we give the paging file a major boost in performance. For a normal HD, the transfer rate at the outer tracks are about 59MB/s while the central and inner tracks have transfer rates of about 49MB/s and 30MB/s respectively. Moving the paging file from the inner tracks to the outer tracks will almost double its performance! Even moving the paging file from the central tracks to the outer tracks will give the paging file a transfer rate boost of 20%.
But please note that this method must be used in conjunction with a permanent paging file. This is because the paging file cannot be moved to the outer tracks of the hard disk unless it is a permanent paging file.

Virtual memory

How Do We Move The Paging File To The Outer Tracks?

Before you can move the paging file to the outer tracks, you must first make the paging file permanent. Follow the steps outlined in the previous pages. Once you have a permanent paging file, you can use your favourite hard disk defragmentation utility to move the paging file to the outer tracks.

Unfortunately, Windows XP's Defrag utility does not have the ability to move paging file to the outer tracks. You will have to use a third-party defragmentation utility to move the paging file to the outer tracks. (though third party software does, eg disk keeper)

And Windows NT, 2000 and XP does not allow the paging file to be moved while it is in used.

A tweak that i have used is not use NTFS for the paging volume.
If you have a second harddrive, you can boost performance by moving your paging file ( pagefile.sys) onto your second drive formatted as FAT32
Create a volume on your second drive, making sure the volume is big enough to hold your paging file. (Three times your RAM amount will be more than enough.)
Simply Format the new volume using FAT32 instead of NTFS, since FAT32 gives slightly better read performance on smaller volumes.
It better that you don't create any additional volumes on your second drive; Just leave this drive for exclusive use by the paging file.

Task manager

Creating A Huge Paging File

Because games and applications often list a minimum paging file size, many people equate the size of the paging file with performance, just like they would with anatomy. But at least in the first case, that's not true.

What does a bigger paging file get you? Well, it gives you the ability to run more memory-intensive programs concurrently. But does a larger paging file make virtual memory faster or better? Unfortunately, the answer is no.

Why Not?

First of all, creating a large amount of virtual memory doesn't mean the operating system will use it all. Although Windows will pre-emptively page out parts of idle applications, there are limits to how much it can page out for each application. Therefore, creating an excessively large paging file will just waste hard disk space.

Second, if you ever move the paging file to the outer tracks of the hard disk, an excessively large paging file will take up outer track space that could have been used to store system or application files.

For many systems, 600MB of virtual memory is more than enough to multitask 7 or 8 applications at the same time or run the most memory-intensive 3D games out there. So, anything more is just taking space.

The extra space taken up by an excessively large paging file on the outer tracks could have been used to store system or application files for faster access. The amount of space regained from using a smaller page file can be seen as a red block in the second picture. You can bet on a faster loading time for Windows and other applications if you limit the size of your paging file. Therefore, the trick here is to gauge the maximum size of the paging file that you will ever need. This way, you will not create an excessively large paging file that wastes hard disk space and takes up the precious space on the outer tracks away from the system and application files.

How Much Virtual Memory Do I Need?

No one can tell you how much hard disk space you need to allocate to a permanent paging file because every system is different and everyone uses his/her system differently. If you create a permanent paging file that is too small, then Windows will continuously create more virtual memory via a dynamic extension to the permanent paging file. This reduces the paging file's performance.
If you create a permanent paging file that is too large, you are only wasting hard disk space, especially on the outer tracks.
So, the best method would be to accurately gauge how much virtual memory you actually need. This allows you to create a permanent paging file with the appropriate size. To do that, you need to monitor your paging file usage. Let's see how you can do that.

Finding Out In Windows 9x

Give your system a clean boot and once you are in Windows 95/98, load System Monitor. You can get to it via Start Menu > Programs > Accessories > System Tools.

Go to the Edit menu and click on Add Item...

In the next screen, select the Memory Manager category and add Swapfile in use. Click OK .

Now, you can monitor the size of your paging file. Start up and run all the applications that you usually use at the same time. Load several documents and work files. Play around with them and check the peak value for the paging file. Then play several of the most memory-intensive games you have. 3D games with large textures are good ones to test. At all times, record down the highest value for the paging file size that System Monitor reports.
Once you are done, select the highest value that has been recorded for the paging file size and round it up to the nearest 100MB. For example, if the biggest size your paging file ever went during the tests was 619MB, then 700MB is the ideal size for your paging file.
But always make sure you add at least 40-50MB as a cushion against future memory-guzzling applications or games. For example, if the largest size your paging file expanded to during your tests was 684MB, then 750MB would be an ideal size for your paging file.

How Much Virtual Memory Do I Need?

Virtual memory

Finding your optimal paging file size in Windows XP is much easier.

Just give your system a clean boot. Once you are in Windows XP, run Task Manager . You can get to it by right-clicking on the taskbar and selecting Task Manager. You can also access it through the keyboard shortcut of Ctrl-Alt-Del.

After you load Task Manager, click on the Performance tab.

The item of interest here is the PF Usage meter. The PF Usage meter shows you the amount of paging file that is being used as virtual memory. Now, you can monitor the size of your paging file.

Start up and run all the applications that you usually use at the same time. Load several documents and work files. Play around with them and check the peak value for the paging file.

Then play several of the most memory-intensive games you have. 3D games with large textures are good ones to test. At all times, record down the highest value for the paging file size that System Monitor reports.

Once you are done, select the highest value that has been recorded for the paging file size and round it up to the nearest 100MB. For example, if the biggest size your paging file ever went during the tests was 619MB, then 700MB is the ideal size for your paging file.

But always make sure you add at least 40-50MB as a cushion against future memory-guzzling applications or games. For example, if the largest size your paging file expanded to during your tests was 684MB, then 750MB would be an ideal size for your paging file.

 

Improve Swap File Performance (Windows 98)
On systems with large amounts of memory, more than 128Mb, the hard disk based swap file is not needed as much. This tweak optimises the use of the swap file on such systems. Using notepad open the SYSTEM.INI file in your Windows directory. Find the [386Enh] section and add a new line reading
"ConservativeSwapfileUsage=1".

If you've got an old win98 computer with 32MB of RAM or more, try setting the cache size at a fixed number. I recommend 4MB for systems with less than 48MB of RAM, and one QUATER total RAM for those with 48MB or more. Here's how to set it up:

Run SysEdit. (Select Run in your Start menu, type SysEdit in the text box, and press Enter.) Click in the system.ini window. Scroll down to the [vcache] section. If you don't see one, type in [vcache] as a new heading. If you have 48MB of RAM or less, enter these two lines:
MinFileCache=0
MaxFileCache=4096

If you have more than 48MB of RAM, enter these two lines:
MinFileCache=0
MaxFileCache=8192

Close SysEdit, saving changes on the way out, and restart Windozes.

 

Moving The Paging File To A Different Partition

Another popular technique proposed by many tweakers suggests moving a temporary paging file from the default first partition to a separate, dedicated partition.

There are two main reasons for this tweak:

  • to reduce fragmentation of the first partition
  • to ensure that the paging file will remain contiguous even though it is a temporary paging file
  • This idea looks good because it enables users of temporary paging files to keep their primary partition neat and the paging file contiguous for a speed boost.
    However, many users of this technique failed to take into account several things.

    Cylinders And Partitions

    If we take a look at a hard disk cylinder, we see that a cylinder consists of the same tracks on all the platters in the hard disk.

    Hard Drive

    The first cylinder, nominally called cylinder 0, (coloured in bright green), is the outer most cylinder and consists of the first track of all the platters in the hard disk. Such groups of tracks have a cylindrical look, hence the name. Cylinder n (in red) is the last cylinder of the hard disk, where n can be any integer.

    Partitions are constructed using full cylinders. The first one starts at cylinder 0 and go out to where you specify. The next one starts on the following cylinder, and so on. If you try to create a partition with an end that falls in the middle of the cylinder, FDISK or similar utilities will round it up so that the partition occupies the entire cylinder, instead of a partial cylinder.

     

    Needless to say, the first partition will always start with the first track of every platter. In other words, the first partition will always be the fastest partition in the hard disk, followed by the second partition and so on. Therefore, if you create a second partition and dump the paging file there, you will actually be moving it to a slower part of your hard disk!

    As you can see, while the temporary paging file will be remain contiguous using this technique, the transfer of the paging file from the outer tracks to the inner tracks of the hard disk will inevitably reduce its performance.

     

    Need More Reasons?

    Creating a dedicated partition for the dynamic paging file also means tying up hard disk space and inviting inflexibility.
    Users of FDISK will find it impossible to change the size of the paging file partition when they need to do so. In fact, they will have to remove at least two partitions to create a larger one. If they only have one primary and a secondary paging file partition, then they will have to remove both and recreate two new partitions.
    Users of special utilities like Partition Magic will have an easier time as they can easily adjust the sizes of the partitions. But in the end, this method is counter-productive because for all your trouble, you have just slowed down your paging file and orphaned off a portion of your hard disk for the dedicated partition.
    The main reason for using a temporary paging file is actually to save hard disk space. Users of a temporary paging file avoid tying up large amounts of hard disk space in a permanent swapfile.
    However, this method actually requires you to set aside a large amount of hard disk space and worse, place cordon off this space in an inflexible partition. If you can afford to allocate space for this dedicated partition, you would be better off using the space for a permanent paging file.
    In my opinion, this technique is a waste of time and needlessly endangers your data. Messing around with FDISK and partitions can be heartbreakingly exciting, if you catch my drift.

    More Partitions = Data Safety?

    The reason for using multiple partitions for safety is that in the event of a hard disk crash, corruption to the boot sector or FAT (File Allocation Tables), only the primary partition will be lost, leaving precious data safe in the other partitions.
    Unfortunately, hard disk crashes, usually wipeout every partition. When a hard disk head crashes with a platter, it wouldn`t avoid scoring through the areas that has been allocated to other partitions.

    "It's not a substitute for a good backup, but it may save you from having to restore all of your data from a backup. However, if your first partition is taken out, more than likely the whole drive will be lost. The first partition is also the location of the Master Boot Record and the partition table." - Russ Johnson, a Product Support Engineer from Symantec Corporation

    Storing your data on a different partition is actually a good practice. It can save your data if the first partition gets corrupted due to a soft error. For example, even if the FAT of one of the partitions gets corrupted, data on the other partitions will still be safe.
    So, if data integrity (as well as disk management) is important to you - consider using multiple partitions. However, this does not mean you should move the paging file to a different partition...

    How Do I Move The Paging File In Windows XP?

    First, open up System Properties, either through the Control Panel or by right-clicking on the My Computer icon and selecting Properties.

    Once in System Properties, click on the Advanced tab. There will be three sections.

    Click on Settings in the Performance section and the Performance Options screen will pop up. Click on the Advanced tab.

    The second section you see is titled Virtual memory. Under it, there's a Change button.

    This is where you manage Windows XP's paging file settings. You can select the logical drive you wish to place the paging file in by clicking on the list of logical drives shown on the screen. Just scroll through the selection of logical drives available. Click on the logical drive that you want to place the paging file. Then set the initial and maximum paging file sizes and click Set.

    To remove the paging file from the default location in the first logical drive, select drive C: and select No paging file. Then click Set.

    After you are done, just click OK and allow Windows XP to reboot your computer. After rebooting, your paging file will be established in the logical drive you selected.

    Registry hacks for Windows XP.
    Just remember to do a back-up of the registry or set a restore point, first...

    DisablePagingExecutive default setting was "set" when RAM was precious and scarce. Portions of system code and device drivers can be paged to disk when the system needs more page frames in RAM. The system slows when it next needs that code or drivers since it must load them from the page file. The system stops while the required code is swapped in or out of RAM dependent on very long hard drive access times. If you have more than sufficient RAM, disabling paging will speed the system overall and reduce the amount of `swapping` on your hard-drive. Don`t turn on this option with less than 512M, at least for W2K and XP Pro. A CPU intensive setting.

    Hive: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager
    Key: Memory Management
    Name: DisablePagingExecutive
    Type: REG_DWORD
    Value: 0 paging allowed
    Value: 1 paging disallowed

    Imprtant: note that each logical drive represents a partition, not a physical drive. So, if you want to move your paging file to a separate hard disk, select a logical drive that resides on that hard disk. Preferably, it should be the first partition in the other hard disk (which should be on its own IDE channel).


    One recent innovation is the i-RAM Hard drive, which can be used to store your pagefile.

    Giga-byte's i-RAM is a PC add-in card with four DDR DRAM (double data rate dynamic RAM memory) slots that's designed to be used as a PC drive. Because the i-RAM uses DRAM rather than a hard disk to store information, data can be retrieved from the drive up to 60 times faster than is possible with a hard drive.

    i-RAM uses solid state storage that is powered through a PCI slot and battery backup so that the volatile memory is not wiped. With no moving parts, speed and reliability is improved tremendously, and at the same time, random accesses are no longer limited by slow and difficult to position read/write heads of conventional magnetic hard drives. By utilizing conventional DDR memory modules, Gigabyte's i-RAM is a lot cheaper to implement than more conventional solid state devices.
    Since the i-RAM behaves just like a regular hard drive, Windows has no problem using it to store your pagefile.

    HDBENCH(Ver3.40 beta6)

      i-RAM HDD
    Read 133,507 50,768
    Write 123,522 59,020
    Random Read 125,953 16,844
    Random Write 61,207 25,396
    The bottom line is that if you can afford a i-RAM then you probably already have fitted more memory to your system.
    (ie. better off with more memory in the system than an i- RAM).

    But if you got both; you may as well make it your pagefile device…

    On memory hogs like web pages with lots of Flash, Photoshop, etc. the system sometimes still resorts to pagefiles; as a consequence the system will run faster, and accessed much quicker off the i-RAM than a mechanical hard disk.
    Note: Adobe Photoshop keeps a scratch disk that is separate from the Windows pagefile.
    But generally, more memory will improve performance in Photoshop, and it won`t access the scratch disk