Caching mechanism of Linux learning

Source: Internet
Author: User

caching mechanisms in Linux

In the Linux system, in order to improve the file system performance, the kernel uses a portion of physical memory to allocate buffers, for caching system operations and data files, when the kernel receives read and write requests, the kernel first go to the buffer to find whether the requested data, there is a direct return, if not through the driver directly manipulate the disk.
Caching mechanism Advantages : Reduce the number of system calls, reduce CPU context switching and disk access frequency.
CPU Context Switching : The CPU gives each process a certain amount of service time, and when the time slice is exhausted, the kernel reclaims the processor from the running process, saves the current running state of the process, and then loads the next task, which is called context switching. is essentially a process switch that terminates the running process and the process to be run.

differentiate between buffers and cache

Buffers

Used to cache metadata and pages, which can be understood as a system cache, for example, vi to open a file.
Cached

is used to cache the file, it can be understood as a block cache, for example, DD If=/dev/zero of=/tmp/test count=1 bs=1g Test Write a file, it will be cached in the buffer, the next time you execute this test command, the write speed will be significantly faster.

How to release the cache

Cleanup Pagecache (page cache)

1 >/proc/sys/vm/drop_caches     or # sysctl-w vm.drop_caches=1

Clean up dentries (directory cache) and Inodes

2 >/proc/sys/vm/drop_caches     or # sysctl-w vm.drop_caches=2

Clean up Pagecache, dentries and Inodes

3 >/proc/sys/vm/drop_caches     or # sysctl-w vm.drop_caches=3

The above three methods are temporary release of the cache, to permanently release the cache, you need to configure in the/etc/sysctl.conf file: VM.DROP_CACHES=1/2/3, and then sysctl-p effective!

You can also use the Sync command to clean up the file system cache, and also clean up Zombie (zombie) objects and the memory they occupy

(It's a good idea to do this before you clean up the cache)

# Sync

Caching mechanism of Linux learning

Related Article

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.