Linux system read-write Cache

Source: Internet
Author: User

1. Operating system CacheIn the Linux world, all readable and writable devices can be considered as files. The file cache design has a direct impact on file system and disk performance. The most intuitive is the cached column that you see with the free command.

This is the cached column is the operating system cache, the operating system will be free memory to do cache, improve system performance. Of course, the cached here not only caches the file's data. The operating system's cache is managed by page, and the smallest unit of allocation and recycling of the cache from the management system is page. The cache consists of multiple page caches, each of which contains more than one buffer cache. The VF (virtual file system) and the internal slave management system interact with the page cache only, and the specific file system interacts with the buffer cache. 2. Operating system cache read and write modeThe operating system defaults to read and write are cached, if you want to use direct IO, you need to set Direct_io to true. The cache can improve the reading speed of the system, when the first time a file is read, the operating system will read the file from the cache, and then return to the user, the second time the first read from the cache to check, the hit back to the user. operating system IO has both write-through and writeback writes: Write through(pass write) can understand where Io is written through. In this way, when writing the data, write the cache and then write the disk, write the disk after the success of the notification disk controller to inform the operating system this IO success, the operating system to notify the upper application IO success. Write back(Write-back) when the operating system writes the data to the cache, it tells the upper-level application IO to be successful, but does not persist the data to disk media at this time. When to flash the cache into disk by the operating system implementation strategy: such as cache space full, call sync display the cache to the disk, and so on. Note:Unlike write-back and asynchronous writes, asynchronous writes notify the calling layer when write succeeds, and write-back does not notify the calling layer after writing to the disk. Therefore, write-back success only means that the write operating system cache is successful, and the return of the successful return IO can still lose data, while asynchronous write tells the call layer IO success means that the data has been persisted to the storage medium. advantages and disadvantages of pass write and write back: Write throughPros: No data loss risk: Because the success of the return IO means that the persistence succeeds, then the power-down will not lose any data, disadvantage: Write slow: To write memory and disk two copies of data Write backPros: Write fast: Writes to the cache successfully returns a disadvantage: there is a risk of data loss: if the data in the cache is not powered down when the disk is not being brushed, the data in the cache is lost. two ways to use the scenario:Write through general application in the case of high data consistency requirements write back write method is generally used in the requirements of consistency is not high and requires a good read and write performance scenarios Here's an example of the CP command.

A. The initial system cache is 60Mb. Use the DD command to generate a 10M block device, when the Iotest.dat data is cached in the cache and the cache becomes 70Mc. The CP Iotest.dat Iotest.dat.1 reads the Iotest.dat file directly from memory and writes it to the cache.is the cache caching two copies of Iotest.dat data at this time? D. Continue calling CP Iotest.dat Iotest.dat.2,cache into 90M. The cache does not have the content de-iotest.dat when it is written in cache, and it caches 3 files of the same content (Iotest.dat.1 iotest.dat.2). E. Continue to call CP Iotest.dat Iotest.dat.1, the cache is not changed here because Iotest.dat and Iotest.dat.1 are already cached in the cache. (Guess the cache supports file-level de-weight and does not support content-heavy)

Linux system read-write Cache

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.