很重要的一节。
实验目的:让大家认识到 Buffer 是对磁盘数据的缓冲,Cache是对文件数据的缓存。它们既会被用在读中,也会被用在写中。
1 2 3 4 5 6 7
| ykg@perf:~$ ps aux|grep sshd root 1320 0.0 0.0 72296 1984 ? Ss 02:26 0:00 /usr/sbin/sshd -D root 2236 0.0 0.0 107984 4120 ? Ss 02:27 0:00 sshd: ykg [priv] ykg 2404 0.0 0.0 108352 3804 ? S 02:27 0:02 sshd: ykg@pts/0 ykg 25017 0.0 0.0 14856 1016 pts/0 S+ 08:14 0:00 grep --color=auto sshd ykg@perf:~$ cat /proc/1320/oom_adj -17
|
1 2 3
| # 清理文件页、目录项、Inodes 等各种缓存 $ echo 3 > /proc/sys/vm/drop_caches $ dd if=/dev/urandom of=/tmp/file bs=1M count=500
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| $ vmstat -w 1 procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu-------- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 7648816 3880 100132 0 0 0 4 34 154 0 0 100 0 0 0 2 0 7648816 3888 100124 0 0 0 160 45 150 0 0 90 10 0 0 0 0 7648792 3888 100132 0 0 0 60 49 200 0 1 98 1 0 1 0 0 7593380 3892 154608 0 0 84 4 28 227 0 18 82 1 0 1 0 0 7434188 3892 313696 0 0 0 0 21 128 0 50 50 0 0 1 0 0 7275612 3892 472292 0 0 0 0 25 158 1 50 50 0 0 0 0 0 7122916 3892 625944 0 0 0 4 24 326 0 50 49 0 0 0 0 0 7122872 3892 626076 0 0 0 4112 36 161 0 0 98 2 0 0 0 0 7122872 3892 626076 0 0 0 0 7 57 0 0 100 0 0 0 0 0 7122872 3892 626076 0 0 0 4 22 103 1 0 100 0 0 0 0 0 7122872 3892 626076 0 0 0 0 11 52 0 0 100 0 0 0 0 0 7122872 3892 626076 0 0 0 0 11 48 0 0 100 0 0 0 1 0 7122832 3896 626084 0 0 4 28676 55 264 1 1 43 56 0 0 1 0 7122488 3900 626088 0 0 4 114688 23 149 0 1 52 47 0 0 1 0 7122488 3900 626088 0 0 0 0 10 91 0 0 50 50 0 0 2 0 7122488 3900 626088 0 0 0 4 18 115 1 0 42 58 0 0 2 0 7122680 3900 626088 0 0 0 0 7 74 0 0 0 100 0 0 1 0 7122824 3908 626080 0 0 8 34816 47 225 1 0 44 56 0 0 1 0 7122424 3912 626116 0 0 4 104448 36 175 1 1 49 49 0 0 1 0 7122440 3912 626120 0 0 0 0 13 91 0 1 50 50 0 0 2 0 7122536 3912 626120 0 0 0 4 22 102 0 0 17 84 0 0 2 0 7122632 3912 626120 0 0 0 0 10 77 1 0 0 100 0 0 1 0 7122792 3912 626120 0 0 0 47104 51 209 0 1 40 59 0 0 1 0 7122424 3916 626124 0 0 4 75776 11 72 0 0 50 50 0 0 1 0 7122552 3916 626124 0 0 0 0 10 91 0 0 50 50 0 0 2 0 7122728 3916 626124 0 0 0 4 20 114 0 0 21 79 0 0 1 0 7122728 3920 626120 0 0 0 4096 18 100 0 0 7 92 0 0 0 0 7122720 3924 626140 0 0 4 98304 52 228 0 1 74 25 0 0 0 0 7122760 3924 626140 0 0 0 0 13 88 0 0 100 0 0 procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu-------- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 7122824 3924 626140 0 0 0 4 20 119 0 0 100 0 0 0 0 0 7122824 3924 626140 0 0 0 0 6 76 0 0 100 0 0 0 0 0 7122824 3924 626140 0 0 0 0 13 75 0 0 100 0 0 0 1 0 7122808 3932 626132 0 0 0 84 46 187 1 0 97 3 0 0 1 0 7122700 3932 626144 0 0 0 0 13 76 0 0 50 50 0 0 1 0 7122700 3932 626144 0 0 0 0 11 72 0 0 50 50 0 0 1 0 7122700 3932 626144 0 0 0 4 25 111 0 1 50 50 0 0 1 0 7122700 3932 626144 0 0 0 0 15 76 0 0 50 50 0 0 1 0 7122700 3932 626144 0 0 0 0 35 163 0 1 50 50 0 0 1 0 7122816 3932 626144 0 0 0 4 12 78 0 0 50 50 0 0 1 0 7122824 3932 626144 0 0 0 0 10 69 0 0 50 50 0
|
跳过直接dd到另一块磁盘
1 2 3 4
| # 首先清理缓存 $ echo 3 > /proc/sys/vm/drop_caches # 运行 dd 命令读取文件数据 $ dd if=/tmp/file of=/dev/null
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| 0 0 0 7653312 1940 97628 0 0 0 0 12 59 0 0 100 0 0 0 0 0 7653304 1940 97628 0 0 0 0 36 140 0 1 100 0 0 0 0 0 7652596 1948 98240 0 0 620 4 41 216 0 0 100 0 0 0 0 0 7652596 1948 98240 0 0 0 0 10 58 0 0 100 0 0 0 0 0 7652596 1948 98240 0 0 0 0 11 69 0 0 100 0 0 0 0 0 7652596 1948 98240 0 0 0 4 21 108 1 0 100 0 0 0 1 0 7630948 4032 109200 0 0 13044 0 265 1768 3 4 79 13 0 0 0 0 7628856 4044 119672 0 0 10484 0 113 628 1 1 81 17 0 0 0 0 7628856 4044 119672 0 0 0 4 19 100 1 0 100 0 0 0 0 0 7628856 4044 119672 0 0 0 0 10 51 0 0 100 0 0 0 0 0 7628856 4044 119672 0 0 0 0 15 68 0 0 100 0 0 0 0 0 7629108 4044 119672 0 0 0 4 47 180 1 1 99 0 0 0 0 0 7629108 4044 119672 0 0 0 0 20 97 0 0 100 0 0 0 1 0 7612740 4052 136348 0 0 16708 0 22 227 1 1 73 25 0 0 1 0 7585576 4052 163636 0 0 27264 4 20 312 3 2 50 46 0 0 1 0 7558172 4052 191068 0 0 27392 0 18 307 2 2 51 45 0 procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu-------- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 1 0 7530520 4052 218296 0 0 27264 0 30 347 3 3 50 45 0 0 1 0 7503116 4060 245684 0 0 27392 40 24 349 2 3 50 46 0 0 1 0 7475836 4060 272988 0 0 27264 0 12 262 2 2 51 46 0 0 1 0 7448556 4060 300212 0 0 27264 0 15 252 2 3 51 45 0 0 1 0 7421152 4060 327604 0 0 27392 12 17 304 2 3 50 45 0 0 1 0 7393872 4060 354868 0 0 27264 4 49 392 2 3 50 46 0 0 1 0 7366404 4060 382324 0 0 27392 0 17 271 2 2 51 46 0 0 1 0 7339060 4060 409652 0 0 27264 0 15 260 2 1 51 46 0 0 1 0 7311716 4060 437108 0 0 27392 4 14 312 2 3 50 45 0 0 1 0 7284528 4060 464404 0 0 27264 0 86 268 2 2 76 21 0 0 1 0 7256976 4060 491796 0 0 27392 0 153 382 2 3 79 16 0 0 1 0 7229720 4060 519100 0 0 27264 4 132 346 2 2 83 14 0 0 1 0 7202440 4060 546276 0 0 27264 0 113 250 3 3 89 6 0 0 1 0 7175036 4060 573716 0 0 27392 0 114 270 3 2 83 13 0 0 2 0 7147724 4064 601012 0 0 27268 4 53 308 2 2 62 34 0 0 1 0 7120256 4068 628472 0 0 27396 0 39 370 1 3 50 46 0 0 0 0 7116668 4068 632076 0 0 3600 0 19 109 1 0 93 6 0 0 0 0 7116668 4068 632076 0 0 0 4 17 96 1 0 100 0 0 0 0 0 7116668 4068 632076 0 0 0 0 10 49 0 0 100 0 0 0 0 0 7116668 4068 632076 0 0 0 0 11 45 0 0 100 0 0 0 0 0 7116620 4068 632076 0 0 0 4 50 199 0 1 100 0 0 0 0 0 7116628 4068 632076 0 0 0 0 17 79 0 0 100 0 0 0 0 0 7116628 4068 632076 0 0 0 0 19 77 0 0 100 0 0
|