📄 virtual memory optimization guide rev. 4.0 - final.txt
字号:
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 :-
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
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.
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.
How Do We Create A Contiguous Paging File?
Now that we agree that making the paging file contiguous will greatly improve its performance, let's figure out how to make it contiguous.
Using A Permanent Paging File
Yes, I know. You are all thinking, "Simple! Just make the paging file permanent!"
True, 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 believe it or not, 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.
Using A Dynamic 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 have 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, that limits how big the paging file can expand. Therefore, this method is self-defeating.
What About A Semi-Permanent 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?
Well, 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 Advantages Of A Semi-Permanent Paging File
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 advantage of creating your own semi-permanent paging file, instead of a "permanent" paging file in Windows XP is that you get to avoid 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.
The Disdvantages Of A Semi-Permanent Paging File
Unfortunately, a semi-permanent paging file is a double-edged sword. With a dynamic component, it is inevitable that a dynamic paging file's disadvantages would also be applicable to it.
As mentioned earlier, the dynamic part will use any available space on the hard disk. This inevitably means the dynamic part of the semi-permanent paging file will always be fragmented. Naturally, the performance of the paging file deteriorates whenever the dynamic part comes into action.
But just how bad could be the deterioration be? Let's take a look at the disk map below which shows a semi-permanent paging file with both permanent and dynamic components in brown :-
This shows a semi-permanent 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.
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.
Permanent Or Semi-Permanent?
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.
The only way around this is to ensure that the permanent part of the semi-permanent paging file is 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.
Is Writing And Rewriting To The Same Area Dangerous?
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)?
To obtain a definitive answer to these questions, I contacted IBM and Seagate. Let's see what their technical experts have to say.
Seagate
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.
Regards,
Bob
Seagate Tech Support
IBM
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 remagnetizes (refreshes) the area every time it is written.
To answer your question: Your swap file will not affect the MTBF of your drive.
Don Gardner
IBM Hard Disk Technical Support/SIT Lab
So, Are Multiple Writes To The Same Area Good?
Well, it appears to be so. From what Don Gardner said, I gather that 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.
I guess that pretty much answers our questions. Creating a permanent or semi-permanent paging file won't harm your drive. In fact, it might even be good for your data!
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. Fear not however. This is what guides like this are for.
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 and you'll see the following picture :-
Right at the bottom, you'll see a Virtual Memory... button. Click on it to get the following screen :-
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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -