前言
当前项目中发现,产品在长时间使用后,会概率死机,通过log分析,可能和swap 大小太小导致的,需要修改增大swap大小后,压测验证。
如何查看swap大小
cat /proc/swaps
C:\Users\Administrator>adb shell
bengal_515:/ # cat /proc/swaps
Filename Type Size Used Priority
/dev/block/zram0 partition 2097148 342016 32758
cat /proc/meminfo
bengal_515:/ # cat /proc/meminfo
MemTotal: 3734548 kB
MemFree: 181012 kB
MemAvailable: 2441112 kB
Buffers: 27568 kB
Cached: 1777348 kB
SwapCached: 604 kB
Active: 593852 kB
Inactive: 1671384 kB
Active(anon): 140052 kB
Inactive(anon): 340104 kB
Active(file): 453800 kB
Inactive(file): 1331280 kB
Unevictable: 6884 kB
Mlocked: 6880 kB
SwapTotal: 2097148 kB
SwapFree: 1755132 kB
Dirty: 36 kB
Writeback: 0 kB
AnonPages: 466836 kB
Mapped: 753960 kB
Shmem: 14544 kB
KReclaimable: 507788 kB
Slab: 349132 kB
SReclaimable: 137108 kB
SUnreclaim: 212024 kB
KernelStack: 38048 kB
free -h
bengal_515:/ # free -htotal used free shared buffers
Mem: 3.5G 3.3G 177M 14M 27M
-/+ buffers/cache: 3.3G 204M
Swap: 2.0G 334M 1.6G
上面3中方式都可以查看当前swap 大小size
cat /proc/swaps
free -h
除了查看swap 总大小,还可以查看free 大小。
如何当天修改swap大小
adb root
adb remount
adb shell
dd if=/dev/zero of=/data/swap.img bs=512M count=1
mkswap /data/swap.img
swapon /data/swap.img
free -h
当前设备默认swap size为2G,当执行上述操作后,swap size会变为2.5G
bengal_515:/ # dd if=/dev/zero of=/data/swap.img bs=512M count=1
mkswap /data/swap.img
swapon /data/swap.img
1+0 records in
1+0 records out
536870912 bytes (512 M) copied, 2.480473 s, 206 M/s
bengal_515:/ # mkswap /data/swap.img
Swapspace size: 524284k, UUID=5f80195d-6f41-4510-a858-5ee1845fe344
bengal_515:/ # swapon /data/swap.img
bengal_515:/ # free -htotal used free shared buffers
Mem: 3.5G 3.0G 550M 14M 26M
-/+ buffers/cache: 2.9G 576M
Swap: 2.5G 332M 2.1G
cat /proc/meminfo
如何去掉默认zram0
swapoff /dev/block/zram0
free -h