开源的内存测试工具,可用来测试内存稳定性。
测试项目有:随机值、异或比较、减法、乘法、除法、与或运算等。
可通过配置测试的内存大小和次数,进行测试。
memtester官网和下载地址:http://pyropus.ca/software/memtester/
➜ memtester-4.5.1 ./memtester
memtester version 4.5.1 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).
pagesize is 4096
pagesizemask is 0xfffffffffffff000
need memory argument, in MB
Usage: ./memtester [-p physaddrbase [-d device]] [B|K|M|G] [loops]
➜ memtester-4.5.1 ./memtester 20M
memtester version 4.5.1 (64-bit)
Copyright (C) 2001-2020 Charles Cazabon.
Licensed under the GNU General Public License version 2 (only).
pagesize is 4096
pagesizemask is 0xfffffffffffff000
want 20MB (20971520 bytes)
got 20MB (20971520 bytes), trying mlock ...locked.
Loop 1:
Stuck Address : ok
Random Value : ok
Compare XOR : ok
Compare SUB : ok
Compare MUL : ok
Compare DIV : ok
Compare OR : ok
Compare AND : ok
Sequential Increment: ok
Solid Bits : ok
Block Sequential : ok
Checkerboard : ok
Bit Spread : ok
Bit Flip : ok
Walking Ones : ok
Walking Zeroes : ok
8-bit Writes : ok
16-bit Writes : ok
Loop 2:
Stuck Address : ok
Random Value : ok
Compare XOR : ok
Compare SUB : ok
Compare MUL : ok
Compare DIV : ok
Compare OR : ok
Compare AND : ok
Sequential Increment: ok
Solid Bits : ok
Block Sequential : ok
Checkerboard : ok
Bit Spread : ok
Bit Flip : ok
Walking Ones : ok
Walking Zeroes : ok
8-bit Writes : ok
16-bit Writes : ok
...
# 安装
➜ build yum install stress
➜ build stress --help
`stress' imposes certain types of compute stress on your system
Usage: stress [OPTION [ARG]] ...
-?, --help show this help statement
--version show version statement
-v, --verbose be verbose
-q, --quiet be quiet
-n, --dry-run show what would have been done
-t, --timeout N timeout after N seconds
--backoff N wait factor of N microseconds before work starts
-c, --cpu N spawn N workers spinning on sqrt()
-i, --io N spawn N workers spinning on sync()
-m, --vm N spawn N workers spinning on malloc()/free()
--vm-bytes B malloc B bytes per vm worker (default is 256MB)
--vm-stride B touch a byte every B bytes (default is 4096)
--vm-hang N sleep N secs before free (default none, 0 is inf)
--vm-keep redirty memory instead of freeing and reallocating
-d, --hdd N spawn N workers spinning on write()/unlink()
--hdd-bytes B write B bytes per hdd worker (default is 1GB)
Example: stress --cpu 8 --io 4 --vm 2 --vm-bytes 128M --timeout 10s
Note: Numbers may be suffixed with s,m,h,d,y (time) or B,K,M,G (size).
case1 : 运行 stress 命令,模拟一个 CPU 使用率 100%,运行10分钟的场景
# 一个cpu使用率100%,运行10分钟场景
stress --cpu 1 --timeout 600
case2: 主要测试硬盘,生成文件放到硬盘内
# var下创建测试目录
mkdir -p /var/testdir
# 切换到test目录
cd /var/testdir
# 测试硬盘,生成4096k大小的文件,写到硬盘内
stress -d 1 --hdd-noclean --hdd-bytes 4096k
case3: 提升cpu与cpu使用率的测试 ,生成文件放到硬盘内
# 切换到 /var/testdir
cd /var/testdir
# 增大“c”值提高cpu数;增大“i”值提高CPU的使用率;增大“d”值会减少CPU的使用率,从而增加对硬盘的数据写入量,但是对内存要求不高
stress -c 4 -i 4 -d 1 --hdd-noclean --hdd-bytes 4096k
case4: 提升vm值,测试内存使用率,生成文件放到硬盘内
cd /var/testdir
# 增大“vm”、“--vm-bytes” 或 “—vm-hang” 选项的值都会提高内存的使用率
stress -c 1 -i 1 --vm 6 --vm-bytes 128M -d 2 --hdd-noclean --hdd-bytes 4096k
# 运行过程中,可以通过进入其他终端,执行“df”命令,查看磁盘是否已满(也就是/var/testdir是否已满),如果磁盘已满,则程序“stress”会报错并终止。
# 如果报错终止执行以下操作,清空测试目录,如果有需要;进入到测试目录下(/var/testdir或者别的目录),继续运行“stress”进行测试
# 给/var/testdir赋权限
chmod -R 755 /var/testdir
# 清空目录
rm -R -f /var/testdir/
# 切换目录
cd /var/testdir/
# 接着测试(vm-bytes可以下降点继续测试)
stress -c 1 -i 1 --vm 6 --vm-bytes 128M -d 2 --hdd-noclean --hdd-bytes 4096k