/dev/shm 是内存虚拟的硬盘
首先在/dev/shm建个tmp文件夹,然后与实际/tmp绑定
mkdir /dev/shm/tmp
chmod 1777 /dev/shm/tmp
mount –bind /dev/shm/tmp /tmp
临时修改/dev/shm大小
#mount -o size=1500M -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm
mount -t tmpfs -o size=20m tmpfs /tmp 临时挂载使用
开机自动挂载
方法1
建立 mount_tmp.sh,并加入到rc.local
vim /etc/rc.d/rc.local
mount_tmp.sh
方法2
开机启用的配置
可以在/etc/fstab 中定义其大小
tmpfs /dev/shm tmpfs,defaults,size=512m 0 0
tmpfs /tmp tmpfs defaults,size=25M 0 0
修改后执行mount -o remoount /dev/shm 后生效
io测速
1.普通硬盘写入速度
# time dd if=/dev/zero of=/test.dbf bs=8k count=3000
3000+0 records in
3000+0 records out
24576000 bytes (25 MB) copied, 0.370205 s, 66.4 MB/s
2.绑定内存后的/tmp读写速度
# time dd if=/dev/zero of=/tmp/test.dbf bs=8k count=3000
3000+0 records in
3000+0 records out
24576000 bytes (25 MB) copied, 0.0145738 s, 1.7 GB/s
可以看到,普通硬盘是66.4MB/s 而内存/tmp速度是 1.7GB/s,不是一个级别的。