The introduction
Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”
Yesterday we talked about Buffer and Cache. If you remember, we concluded that Buffer is used to write data to disk, and Cache is used to read file Cache. Today, let’s learn about it in action.
Disk and file write
First, to eliminate caching, we use the command echo 3 > /proc/sys/vm-/ drop_caches, which is then free to view the overall memory, as shown below:
This command sets the value of the file to 3, which means delete.
Then we run cat /proc/meminfo to look at the cache, as shown below:
Then we run the vmstat 1 command to print once a second:
- Buffs and cache correspond to Buffers and cache, respectively, in KB.
- Bi and BO represent the read and write sizes of the block device, in blocks per second. Since the block size in Linux is 1KB, this unit is equivalent to KB per second.
Dd if=/dev/urandom of=/ TMP /file bs=1M count=500
Then we run the vmstat 1 command to print once a second:
We see that the buff is basically unchanged, and the cache is exploding. Why did I write that it’s still going up? It’s too late. I’m going to bed.