Experience Linux speeding up with Page cache

Just copy this super nice article. https://www.kimullaa.com/entry/2019/12/01/130347

Run as root.

#Make a huge file
 dd if=/dev/zero of=/tmp/large.txt count=100 bs=10M

#Current cache state
 vmstat

#cache deleted
 echo 3 > /proc/sys/vm/drop_caches

#The cache is low
 vmstat

#1st time
time cat /tmp/large.txt > /dev/null

#With cache
 vmstat

#The second time should be faster
time cat /tmp/large.txt > /dev/null

#cleaning
rm -rf /tmp/large.txt

result

It has increased 10 times.

image.png


[root@localhost test]# #Make a huge file
[root@localhost test]#  dd if=/dev/zero of=/tmp/large.txt count=100 bs=10M
100+0 records in
100+0 records out
1048576000 bytes (1.0 GB) copied, 1.29639 s, 809 MB/s
[root@localhost test]#
[root@localhost test]# #Current cache state
[root@localhost test]#  vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0  79216      0 1692164    0    0  1084  2053  166  195  3  2 95  0  0
[root@localhost test]#
[root@localhost test]# #cache deleted
[root@localhost test]#  echo 3 > /proc/sys/vm/drop_caches
[root@localhost test]#
[root@localhost test]# #The cache is low
[root@localhost test]#  vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1592220      0 179268    0    0  1086  2053  166  195  3  2 95  0  0
[root@localhost test]#
[root@localhost test]# #1st time
[root@localhost test]# time cat /tmp/large.txt > /dev/null

real	0m1.455s
user	0m0.008s
sys	0m1.075s
[root@localhost test]#
[root@localhost test]# #With cache
[root@localhost test]#  vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 567092      0 1204456    0    0  1565  2053  170  200  3  2 95  0  0
[root@localhost test]#
[root@localhost test]# #The second time should be faster
[root@localhost test]# time cat /tmp/large.txt > /dev/null

real	0m0.139s
user	0m0.003s
sys	0m0.135s
[root@localhost test]#

Recommended Posts

Experience Linux speeding up with Page cache
[Python] Speeding up processing using cache tools
Page cache in Python + Flask with Flask-Caching
Speeding up numerical calculations with NumPy: Basics
Set up golang with goenv on GNU / Linux
Back up from QNAP to Linux with rsync
Tips for speeding up python code correctly with numba
Set up Docker on Oracle Linux (7.x) with Vagrant
A note on speeding up Python code with Numba
Reading, displaying and speeding up gifs with python [OpenCV]
Linux (Lubuntu) with OneMix3S
linux with termux app
Experience blockchain with BigchainDB
See the power of speeding up with NumPy and SciPy