What is the use of Win7 system virtual memory?

  

What is the use of Win7 virtual memory? Where is its use?

First, virtual memory should never be turned off:

Even if your memory is large enough, it is unrecoverable. At the point of the drug, the virtual memory should not be shut down, because in addition to the traditional RAM "backup" function, Windows will also use virtual memory to perform some specific operations. In addition, the opening of virtual memory also helps to improve the memory hit rate and ensure the stability of the system. Individual software (such as Photoshop, 3Dmark, etc.) will also need virtual memory at runtime.

Second, the rumor finalization process

1. Virtual memory is not "physical memory second".

What we mean here is "virtual memory", which should be called "paged file" in strict sense, because from the official documentation of Microsoft, "virtual memory" is equal to “ Physical memory & rdquo; + & ldquo; paging file & rdquo; sum. Popularly speaking, the paging file refers to a huge file on our hard disk, named “PageFile.sys” (visible after setting the resource manager to display system + hidden files).

Early computer memory (RAM) is generally low, in order to solve the problem of low efficiency of software operation (if the memory is not enough, you need to change pages frequently, move the temporarily unused program out of the memory, and transfer the upcoming operation into it. ), Windows has opened up an area on the hard disk, as "virtual RAM" used. Once the physical memory cannot meet the current needs, the paging file will automatically act as a memory to implement part of the physical memory function. This is known as the use of paging files to expand the memory function.

"Virtual Memory"; Strictly speaking, it should be called "Paging File"

So when the physical memory basically meets the requirements, what will happen to the above situation? For example, there is a library with 10,000 books. Let's take it as the total hard disk capacity of the computer; then you can place a small bookshelf at the door, with a capacity of 50, which is equivalent to the paging file size of Windows. The next step is the borrowing limit per person, which is 5, which is equivalent to the physical memory.

Every time you read 5 of your hand, you can continue to pick it up in the small bookshelf or the library. Of course, I don't say that everyone knows that it is much faster to find 10,000 books from 50 books, so the second major role of the paging file comes out —— speed up data access.

As you can see from the above example, the paging file has the effect of helping physical memory improve the "hit rate" and "stability", so even if your physical memory is large (such as one can borrow 10 or 20 books), and there will be a day when the book is finished. At this time, if you look for a book again, you will still encounter the previous question. Is it quick to find it from 50 books or go directly to 10,000 books? So from this point of view, the physical memory size is actually not related to the ban on paging files.

2. What is the impact of paging files on performance?

To illustrate how much impact paging data can have on data access efficiency, we have designed a small experiment to illustrate. The testing process is very simple, that is, a benchmark score is calculated for Windows through PCMark7 simulation daily application, the background is standard Windows and Windows after closing the paging file.

Note: The test item selects the default <;PCMARK suite”.

PCMARK7 Professional

Comparison of results before and after closing paging files

In the test, we chose a "PCMARK suite" that many users are familiar with, including video playback. , video transcoding, image processing, web browsing, web page decryption, image import, 3D games and other sub-items can be said to be a microcosm of the user's daily work.

It can be seen that after the paging file is closed, the system score has dropped significantly, indicating that many applications have experienced different degrees of slowdown after closing the paging file. Since our test machine uses 4GB of memory (64bit system), it does not cause the physical memory to be completely exhausted under normal circumstances, so the whole test can basically be regarded as the impact of paging files on system performance.

3. When the physical memory is sufficient, the paging file works?

Although the measured results show that the paging file still has the performance improvement effect for the current large memory system, I dare say that many netizens definitely There is another doubt —— paging file and physical memory is awkward relationship? Frequent hard disk read and write really does not drag the system to run?

AIDA64 detection map

To answer this The problem is actually very simple, just use a third-party software ——AIDA64. The above picture is the hardware detection software AIDA64 detection of the author's computer, you can see that the current computer storage system is composed of 4GB physical memory, 4GB paging file, where the sum of physical memory + paging files is called exchange area by AIDA64 (Windows “Virtual Memory”). So when a program starts, will it use physical memory first? Or will it be used synchronously according to the concept of virtual memory?

It should be noted that Microsoft's definition of virtual memory is different from AIDA64. It treats the physical memory + paging file as a virtual memory (equivalent to the "exchange area" in AIDA64), while AIDA64 treats the physical memory + swap area as virtual memory. To be honest, this division of AIDA64 is puzzling because it is not practical to combine a real value (physical memory) with a virtual value (exchange area). Therefore, we mainly rely on the definition of Microsoft here.

The final answer is very obvious, that is, when the physical memory is exhausted, Windows will enable the paging file. If you don't believe it, you can open AIDA64 like me (the software supports real-time update, you can see the changes of each value very intuitively), then start several programs at will and observe the value changes of the "page file". You will find that as the program starts, the physical memory and swap area values ​​are constantly changing, but the page file is always 0MB.

In other words, when physical memory can meet current needs, Windows does not deprecate high-speed memory and chooses slower hard disk files (paged files), so we don't have to worry about opening paging files. The overall performance of the system, unless it is your physical memory really can not meet the system needs.

4. How to set the paging file is reasonable

Then another question comes. If the paging file is still good or bad in today's Windows, then we should let Windows do it. Management, or set a specific value for it?

I have talked with a Microsoft engineer about this problem. The focus of both parties is that the paging file is a very old setting, originally Set it to a variable, the official recommendation is 1.5 times the physical memory (that is, the recommended value you see in the system → paging file settings box).

But it's important to note that this rule was designed in the context of a few decades ago when memory was only a few tens of megabytes (the server is no different). But nowadays, when physical memory has entered the GB era, even individual users have used more than 16GB of large memory, and it is obviously not suitable to go to the previous standard.

Is the system hosting really reasonable?

It is still an example of a library at the beginning. The current situation can be changed to the collection capacity has not changed (10,000 copies), but each person can borrow each time. The number is upgraded to 15 (that is, the physical memory becomes larger), and the number of books in the corresponding small bookcase is also increased to 500 (the paging file is scaled up). So the question is, if the 50 bookshelf can help us improve efficiency, what is the time spent on the 500 bookshelf? If it happens that the 500 books still do not have what you want, you need to re-enter the library ( If you continue to search in 10,000 copies, the system efficiency is not slow.

Back to the real version, the surge in the size of the small bookshelf is actually equivalent to the expansion of paging files (such as 16GB memory is 16GB~24GB according to Microsoft standard), then at the reading speed of the current mechanical hard disk (The difference between random read and linear read is not considered here. If you want to traverse the time of 16GB or 24GB space, I am afraid it is quite large. In other words, instead of improving system performance, the paging file will actually become a drag on system performance!

In order to better illustrate the results, we still conducted a benchmark test through PCMark 7. A little different from the previous test, this time is mainly to adjust the size of the paging file, according to the test machine memory is divided into "system hosting (measured as 4GB)", "512MB", "2GB"; “4GB” Several files, of course, did not forget to add a large capacity “12GB”.

The final result is clear at a glance. As the paging file grows, the system score begins to increase proportionally. When it reaches 4GB, it almost shows the best result of this evaluation. However, when the author artificially raised it to 12GB, the overall score has dropped significantly, which finally proves our previous speculation.

Although the above tests have generally derived a page size, we do not recommend that all users adopt this setting. The reason is that each person's hardware configuration is different, and the big pot and rice setting is not necessarily suitable for everyone. Considering the impact of paging file size on performance, we recommend that you choose to be self-hosted by Windows if the user memory does not exceed 4GB, and when the user memory is higher than 4GB, you should use the manual setting method to limit the paging file. Within a range (recommended not to exceed 6GB), this will ensure the normal throughput of the system, and will not drag down the system speed due to excessive paging files!

In addition, for users with strong hands-on ability, You can also use the “Performance Monitor” (perfmon.msc) to add a “Paging File Usage” to calculate the actual utilization of the paging file on your computer, so as to accurately calculate how large the paging file is for your computer. . Just considering that this step is more cumbersome, it is not covered here.

Written in the end

In fact, like many components in Windows, virtual memory is not as simple as you think, except for the well-known complementary memory features (actually for this purpose now) It has rarely been used), it also plays a role in improving physical memory hit rate and stability. Even some of the core features of Windows use virtual memory (such as SuperPrefetch, memory dump, etc.).

In addition, some third-party software (such as Photoshop, 3Dmax, etc.) is also a loyal supporter of virtual memory, and forcible shutdown is likely to cause operational errors or crashes. Of course, considering the hard disk overhead and overall performance, users should limit the size of the paging file according to their own conditions, and try not to make the paging file too large. In short, there is no certain rule on this issue, and more needs to be handled flexibly by users.

This tip is really not a flickering

Attachment: A few small questions:

1. Can paging files be moved to other partitions to improve performance? Br>

According to Microsoft's design, the operating system allows multiple paging files to be created at the same time, and Windows intelligently picks the highest performance for reading. But note that this design is only for multiple hard drives. For example, if your Windows is installed on hard disk 1 and the paging file is set on hard disk 2, then the operating system can read data from two hard disks at the same time (a read operation) The system, a piece of read paging file), the end result is the efficiency of Windows. However, if the user has only one hard disk, the paging file will be transferred from the C disk to other partitions. In theory, there will be no obvious improvement unless the space of your C disk is too tight!

2. Can the fixed size be reduced? Hard disk fragmentation?

Some people think that the default variable size of Windows is often the main cause of fragmentation of paging files. We need to consider this issue from another perspective. As you know, an important feature of paging files is that they are used as a supplement to memory (although this is currently rare, but not excluded), so when you accidentally encounter a memory-intensive program, it is still possible Explode virtual memory and cause a final crash. Then if you use the default variable memory at this time, it is equivalent to give Windows a chance to make a move, maybe the crash will not happen.

Of course, the special thing to say here is that if your virtual memory size is reasonable, it will not cause Windows to adjust the size of the paging file in general, and the chance of disk fragmentation is not a lot. It is.

Copyright © Windows knowledge All Rights Reserved