liunx 内存文件 tmpfs

时间:2023-03-09 06:39:18
liunx 内存文件 tmpfs

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+ 的写出
2147483648字节(2.1 GB)已复制,16.4153 秒, 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:
-/+ buffers/cache:
Swap: mount tmpfs /tmp/tmpfs/ -t tmpfs -o size=2G root@ubuntu:/tmp# free -g
total used free shared buffers cached
Mem:
-/+ buffers/cache:
Swap:

5 卸载 unmout

umount /tmp/tmpfs/