tmpfs是Linux/Unix系统上的一种基于内存的文件系统。tmpfs可以使用您的内存或swap分区来存储文件
tmpfs默认情况下会mount到/dev/shm目录下
1 创建将被挂载的文件
mkdir /tmp/tmpfs/
2 写入测试文件内容。大小2G
dd if=/dev/zero of=/tmp/tmpfs/testfile bs=1G count=2 记录了2+0 的读入 记录了2+0 的写出 2147483648字节(2.1 GB)已复制,16.4153 秒,131 MB/秒
3 挂载测试目录,限制大小为2G ,注意挂载的是文件目录
mount tmpfs /tmp/tmpfs/ -t tmpfs -o size=2G
4 挂载前后对比
root@ubuntu:/tmp# free -g total used free shared buffers cached Mem: 15 11 4 2 0 2 -/+ buffers/cache: 8 7 Swap: 7 0 7 mount tmpfs /tmp/tmpfs/ -t tmpfs -o size=2G root@ubuntu:/tmp# free -g total used free shared buffers cached Mem: 15 9 6 0 0 0 -/+ buffers/cache: 8 7 Swap: 7 0 7
5 卸载 unmout
umount /tmp/tmpfs/