What's the difference between Buffer cache and page cache?

Source: Internet
Author: User
Tags file copy file system memory usage linux

What's the difference between Page cache and buffer cache? Most of the time we do not know the system in the IO operation is to walk the page cache or buffer cache? In fact, the buffer cache and page cache are two simpler concepts in Linux, which is summarized here.

Page cache is the cache of the VFS file system layer, for example, for a ext3 file system, each file will have a cached page of the Radix tree management file, which is called page cache. So, page cache is for file systems. For example, the page cache of the Ext3 file system is the pages buffer. Buffer cache is for devices, each device will have a radix tree management data cache block, these cache blocks are called buffer cache. Typically, the page cache size is 4KB for the ext3 file system, so the block size for each operation ext3 is an integer multiple of 4KB. Buffer cache buffer block size is usually determined by the size of the block device, the value range between 512B~4KB, take the size of the block device GCD. Specifically on the buffer cache block size problem can be seen in my another blog post "Linux buffer cache performance problem."

Here we can observe the difference between buffer cache and page cache by a small experiment. Running the top command, we can see the current memory usage of the experimental machine:

You can see that the total memory capacity of about 16GB, page cache with nearly 10GB (10209072k-303796k), buffer cache with 300MB (303796K), the rest of the 6GB (6255076K) idle remaining. In this case, if you dm0 the device to a bare disk write operation, run the following command:

DD If=/dev/zero OF=/DEV/DM0 count=4096

So, I can be found by the top command, buffer cache capacity is more and more, less free memory, a considerable part of memory by buffer cache footprint, and in the process of IO operations found BDI (flush-254 : 176 thread in the busy data brush operation.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/database/storage/

After a period of time, approximately 6GB (6401432KB) of memory is occupied by buffer cache, 89MB (89312KB) memory is idle, the remaining approximately 10GB (16374836KB-6401432KB) of memory is occupied by page cache. Through this experiment, it can be explained that the read and write operation of the bare disk will occupy the buffer cache, and when the read and write operation is completed, these buffer cache will be returned to the system. In order to verify the occupancy of page cache, I did a file system level read and write operation, run the following command for file system write operations:

Cp/dev/zero./test_file

This is a file copy operation, so the file data is cached using page cache. With the top tool we can see that in the process of copying data, page cache is more and more capacity, the amount of free memory drops dramatically, and the buffer cache remains unchanged.

After a certain period of time, the free memory will be 1.9GB (1959468KB), the File system page cache will grow to be nearly 14.5GB (14504680KB–235108KB), the buffer cache to maintain around 235MB (235108KB).

From this we can conclude that page cache and buffer cache the biggest difference is: page cache is the cache of file data; Buffer cache is the caching of device data. Both in the implementation of the difference is not very large, are the use of radix tree management.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.