每天学五分钟 Liunx 0001 | 存储篇:swap
swap
swap 构建
[root@test test]# fdisk /dev/sdb
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
No free sectors available
[root@test test]# lvdisplay | grep test
LV Path /dev/lianhuasheng/test
LV Name test
[root@test test]# free
total used free shared buff/cache available
Mem: 65692228 56611752 631264 56492 8449212 7650528
Swap: 0 0 0
[root@test test]# mkswap /dev/lianhuasheng/test
mkswap: /dev/lianhuasheng/test: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 204796 KiB
no label, UUID=2ed9b70d-b267-4c26-9159-1bfb273c7d7c
[root@test test]# free
total used free shared buff/cache available
Mem: 65692228 56359176 1139968 56492 8193084 7902468
Swap: 0 0 0
[root@test test]# free -h
total used free shared buff/cache available
Mem: 62G 54G 511M 55M 7.9G 7.0G
Swap: 0B 0B 0B
[root@test test]# swapon /dev/lianhuasheng/test
[root@test test]# free -h
total used free shared buff/cache available
Mem: 62G 54G 941M 55M 7.7G 7.2G
Swap: 199M 0B 199M
[root@test lianhuasheng]# dd if=/dev/zero of=/root/lianhuasheng/swap/lianhuasheng.swap bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 0.356955 s, 1.5 GB/s
[root@test swap]# ll -h lianhuasheng.swap
-rw-r--r--. 1 root root 512M Apr 1 00:12 lianhuasheng.swap
[root@test swap]# mkswap lianhuasheng.swap
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=510ba316-c6e5-4993-b616-e72969cd6322
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 53G 663M 47M 8.0G 7.3G
Swap: 199M 199M 16K
[root@test swap]# swapon lianhuasheng.swap
swapon: /root/lianhuasheng/swap/lianhuasheng.swap: insecure permissions 0644, 0600 suggested.
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 54G 304M 47M 8.1G 7.1G
Swap: 711M 200M 511M
[root@test swap]# swapoff /dev/lianhuashengl/test
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 53G 761M 54M 8.0G 7.4G
Swap: 511M 511M 60K
[root@test swap]# swapoff lianhuasheng.swap
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 54G 888M 55M 7.6G 7.1G
Swap: 0B 0B 0B
磁盘性能
[root@test lianhuasheng]# dd if=/dev/zero of=/root/lianhuasheng/swap/lianhuasheng.swap bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 0.356955 s, 1.5 GB/s
[root@test swap]# dd if=lianhuasheng.swap of=/dev/null bs=1M
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 1.07563 s, 499 MB/s
[root@test swap]# dd if=/dev/sda2 of=disk bs=1K
^C2729809+0 records in
2729808+0 records out
2795323392 bytes (2.8 GB) copied, 11.4058 s, 245 MB/s
[root@test swap]# dd if=lianhuasheng.swap of=/dev/null bs=1M iflag=direct
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 1.7492 s, 307 MB/s
[root@test swap]# dd if=/dev/zero of=lianhuasheng.swap bs=1M count=1024 oflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 2.5872 s, 415 MB/s
[root@test swap]# dd if=/dev/sda2 of=disk bs=1K iflag=direct oflag=direct
^C328136+0 records in
328135+0 records out
336010240 bytes (336 MB) copied, 93.313 s, 3.6 MB/s
sync && echo 3 > /proc/sys/vm/drop_caches
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 56G 1.0G 55M 5.0G 4.8G
Swap: 0B 0B 0B
[root@test swap]# sync && echo 3 > /proc/sys/vm/drop_caches
[root@test swap]# free -h
total used free shared buff/cache available
Mem: 62G 54G 7.3G 55M 901M 7.2G
Swap: 0B 0B 0B
[root@test swap]# dd if=lianhuasheng.swap of=/dev/null bs=1M iflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 3.54052 s, 303 MB/s
[root@test swap]# dd if=lianhuasheng.swap of=/dev/null bs=1M iflag=direct
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 3.49309 s, 307 MB/s
[root@test test]# hdparm -t /dev/sda2
/dev/sda2:
Timing buffered disk reads: 1334 MB in 3.00 seconds = 444.43 MB/sec
[root@test test]# hdparm -T /dev/sda2
/dev/sda2:
Timing cached reads: 17748 MB in 2.00 seconds = 8888.37 MB/sec
内存和磁盘 | buffer cache 和 page cache
[root@test test]# free -wh
total used free shared buffers cache available
Mem: 31G 8.9G 10G 1.6G 326M 11G 20G
Swap: 511M 371M 140M
buffers
Memory used by kernel buffers (Buffers in /proc/meminfo)
cache
Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)