A comprehensive understanding and optimization of "cache"

  

  understanding the cache

The task of the operating system is to rationally allocate various resources of the system, provide an environment for the operation of various programs, it can Think of it as a medium between hardware and application software. The management of memory is the most important responsibility of the system. How to make limited memory for the blade, how to ensure the memory required by the system itself (to prevent crashes, this has been done very well in win2000 and winxp). ), how to overcome the bottleneck of various hardware connections.

This article mainly discusses some of the bottlenecks of this hardware connection. Everyone knows that the speed of the computer's main hardware, hard disk, memory and processor is not the same, where the speed of the processor is very fast, the memory is second, and the speed of the hard disk is very slow (relative to the processor) Said), the processing of a task through the instructions given by the processor, the relevant data is transferred from the hard disk, to the memory, there will be a lot of data transfer between the memory and the processor, the memory itself can not process the data, To be processed by the processor, when they work together, because the processor and memory work fast, they often do things and do nothing, wait for the hard disk, which greatly reduces the overall performance of the system, can not play The performance of all hardware. In order to solve this problem, an excellent operating system must have a "cache" as an intermediate station between these hardware to alleviate this contradiction, thereby improving the performance of the system to a certain extent, the better the "cache" processing, The better the performance of the system is. So studying "cache" has its meaning.

After reading the above content, friends who have not known about "cache" should understand it. The place to apply immediately after understanding is when you purchase a compatible machine. You don't have to go after the trend, buy a P4 processor, but should buy a faster hard drive, such as buying a 7200 rpm (or faster) to reduce the bottleneck. Processor, buy Celeron is good, generally no problem, the processor is idle most of the time, sometimes when dealing with many large tasks may be a little nervous, pay attention to avoid it.

In a way, the memory itself is a cache between the hard disk and the processor, its role is to ease the sharp contradiction between the hard disk and the processor. When it is used as a fixed component, it itself becomes an object that needs to be cached to alleviate bottlenecks. It is the only way for the processor and the hard disk to be sandwiched. The relationship between the hard disk and the processor becomes a double relationship between the hard disk and the memory and the memory and the processor. So the handling of the bottleneck mentioned above comes down to the optimization of memory, that is, how to handle the cache between the hard disk and the memory is the cache between the processor and the memory.

For a person who wants to understand the operating system, it is an indispensable lesson to be able to understand the "cache" to properly optimize it. In addition, the concept of caching is very broad, here specifically refers to the memory cache.

                                           

1, the most "famous" cached page file is, not that the remission rate, but the ease capacity, in terms of speed, hard disk memory is better, but on the capacity of the memory is not possible than with hard disk When you run a program that requires a lot of data and takes up a lot of memory, the memory will be filled. What should I do? Put those temporarily unused on the hard disk, because the processor always only calls the data needed to process a task, and other prepared data (that is, those that may be used, but not used for the time being) can be placed first. If you can't store it, you have to put it on your hard drive. But there is a price to do this. When the data put into memory is used again, you have to wait a long time for the system to adjust the data on the hard disk. In fact, you can feel these actions of the system. For example, if you open IE or Office, the first time you open it is very slow, but it will be much faster after you close it. This is because the data has not been "please" by the system. Memory, the system directly obtains data directly from memory. In another case, when you open a large software such as photoshop, it is slower to open Office than usual. This is because the memory was originally occupied by photoshop. To transfer the data of Office to the memory, you must "please" the photoshop data out of the memory. If you have more of this process, it will be slower to open.
Optimize the page file, you can do a few:

1) Put the page file outside the system disk, this is mainly to maintain the continuity of the page file, the hard disk reads the data is based on the head When the data is "read" on the magnetic material, the page file is placed in different physical areas, and the magnetic head is jumped and jumped, which is not conducive to efficiency. There are many system disk files, and the page files are almost certainly not continuous. So move it to another disk. To remind you that when you move the page file, you need to delete the original file and the system will not delete it automatically.

2) If there are two hard disks, put the page file on the one with the fast speed, the reason has been mentioned many times.

3) The principle of setting the maximum and minimum page files. There are a lot of people who suggest setting these two values ​​to be equal. I don't know if they are the basis for them. In fact, this setting is unreasonable. We must first understand the meaning of their two values. Under normal circumstances, the memory is not really "filled", it will automatically put a part of the temporarily unused data to the hard disk when the internal storage reaches a certain level, the minimum page file is the specific proportion of the "a certain degree" Decisive factor, the minimum page file is large, the ratio is low, and vice versa; the maximum page file is the limit value. Sometimes you open a lot of programs, the memory and the minimum page file are full, and it will automatically overflow to the maximum page file. Therefore, it is unreasonable to set the two to be the same size. The minimum page file should be smaller, so that you can store as much data as possible in the memory, the efficiency is high, and the maximum page file is larger, so as to avoid the situation of "full".

4) winxp now supports 4G memory, even if you have 5,6 M memory, you do not need the page file, then you can disable the page file. Go to the registry editor HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession Manager Memory Management and find DisablePagingExecutive with a value of 1.

  5) There is a ClearPageFileAtShutdown in the same registry editor location (clear the page file when shutting down), the "clear" page file (ie virtual memory) mentioned here does not mean from the hard disk The pagefile.sys file is completely deleted, but it is "cleaned" and tidyed up to prepare for better use of virtual memory for the next time Win2K is started. This is also good for security. The residual data on the page file can be read with special tools that you may not want to know. The cost of doing this is that the system time will be lengthened. Set its value to 1.

6) Friends who have learned C should have a concept of operating memory. After a task is completed, the free function is used to release the memory, but there are many softwares that are not designed at all. In doing so, this will cause useless data to occupy memory. In this case, some memory optimization software can be used to let the software complete the action of releasing the memory.

2, described below, and do not optimize some well-known cache:

1) through memory read data to a hard disk cache system (system cache), it is the position of a specific region in memory It is used to ease the speed imbalance between the hard disk and the memory. It sacrifices memory resources in exchange for the speed of reading data from the hard disk. With this cache, the system can pre-read the required data from the hard disk and reduce the waiting time of the system. If your memory is very large, such as 5,6 hundred M, then in addition to the above method of closing the page file, you can also use the system cache. To do this, go to the Registry Editor: HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession Manager Memory Management, find LargeSystemCache (enable large system cache), set its value to 1.

After this setting, systemcache is increased from 4M to 8M, then win2000 and winxp, this value is dynamic, if the memory is insufficient, the space occupied by systemcache can be adjusted accordingly.

2) What is the cache for the processor to read data from memory? It is a secondary data cache (buffer), and it also takes up a space in memory, so it is best to set this value after having large memory. Also need to be set in the registry, as follows: Enter HKEY_LOCAL_MACHINESystemCurrentControlSetControlSession Manager Memory Management, find SecondLevelDataCache, the default is 256, the large memory is set to 512.

Well, after the above description, I think the most important gains for friends who is to deepen the understanding of the cache and the operating system, as optimized method, I have to admit is not usually a friend It’s also very interesting to play it.


Copyright © Windows knowledge All Rights Reserved