Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of page buffer cache in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you the example analysis of page buffer cache in linux, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

Page cache and buffer cache have always been two concepts that are easy to confuse. There are also many people on the Internet arguing and guessing what the difference between these two caches is. In the end, there has been no unified and correct conclusion. During this period of time when I worked, the concepts of page cache and buffer cache have troubled me, but after careful analysis, these two concepts are actually very clear. If we can understand the nature of these two caches, then we may be more handy when analyzing io problems.

Page cache is actually for file system, is the cache of files, data at the file level will be cached to page cache. The logical layer of the file needs to be mapped to the actual physical disk, and this mapping is done by the file system. When the page cache data needs to be refreshed, the data in the page cache is handed over to the buffer cache, but this processing has become very simple since the 2.6 kernel, and there is no real cache operation.

Buffer cache is a cache for disk blocks, that is, in the absence of a file system, data directly operated on the disk will be cached in buffer cache, for example, metadata of the file system will be cached in buffer cache.

Simply put, page cache is used to cache file data, buffer cache is used to cache disk data. In the case of a file system, if you operate on files, the data will be cached in the page cache. If you directly use dd and other tools to read and write to the disk, the data will be cached in the buffer cache.

In addition, at the file system level, each device will be assigned a def_blk_ops file operation method, which is the operation method of the device. There will be a radix tree under the inode of each device, and the page page of cached data will be placed under this radix tree. The number of pages will be displayed in the buffer column of the top program. If the device has a file system, an inode will be generated. This inode will assign operation methods such as ext3_ops. These methods are file system methods. There is also a radix tree under this inode, where the page pages of the file will be cached. The number of cached pages is counted in the cache column of the top program. From the above analysis, it can be seen that buffer cache and page cache in the 2.6 kernel are consistent in processing, but there are conceptual differences. Page cache is a cache for files, buffer is a cache for disk block data, and that's it.

Difference between buffer and cache

A buffer is something that has yet to be "written" to disk. A cache is something that has been "read" from the disk and stored for later use.

Difference Between Buffer and Cache

Shared memory is mainly used to share data between different processes in UNIX environment. It is a method of inter-process communication. General applications will not apply for shared memory. The author has not verified the impact of shared memory on the above equation. What is Shared Memory?

Difference between cache and buffer:

Cache: Cache is a small but fast memory located between CPU and main memory. Because the CPU speed is much higher than the main memory, CPU directly accesses data from memory to wait for a certain period of time, Cache stores a part of data that CPU has just used or recycled, when CPU uses this part of data again, it can be directly called from Cache, thus reducing CPU waiting time and improving system efficiency. Cache is also divided into Level 1 Cache (L1 Cache) and Level 2 Cache (L2 Cache). L1 Cache is integrated into the CPU. L2 Cache is usually soldered on the motherboard in the early days and is now integrated into the CPU. The common capacity is 256KB or 512KB L2 Cache.

Buffer: buffer, an area used to store data transmitted between devices with different speeds or priorities. Buffers make it possible for processes to wait less for each other, so that when data is read from a slower device, there is no interruption in the operation of a faster device.

Buffer and cache in Free: (they both occupy memory):

buffer: memory as buffer cache, read and write buffer of block device

cache: memory as page cache, cache for file system

If the cache value is large, it means that the cache holds a large number of files. If frequently accessed files can be cached, the read IO of the disk must be very small.

The above is "linux page buffer cache sample analysis" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report