首页 技术 正文
技术 2022年11月11日
0 收藏 844 点赞 2,237 浏览 1856 个字

简介

ramfs和tmpfs是在内存上建立的文件系统(Filesystem)。其优点是读写速度很快,但存在掉电丢失的风险。如果一个进程的性能瓶颈是硬盘的读写,那么可以考虑在ramfs或tmpfs上进行大文件的读写操作。

ramfs和tmpfs之间的区别:

ramfs和tmpfs的区别
特性  tmpfs ramfs
 达到空间上限时继续写入 提示错误信息并终止  可以继续写尚未分配的空间
是否固定大小
 是否使用swap
 具有易失性  是

查看

通过下面的方法可以查看系统中的tmpfs和ramfs:

not@linux-numy:~> mount | grep -E "(tmpfs|ramfs)"
devtmpfs on /dev type devtmpfs (rw,relatime,size=1945280k,nr_inodes=,mode=)
tmpfs on /dev/shm type tmpfs (rw,relatime)
tmpfs on /run type tmpfs (rw,nosuid,nodev,relatime,mode=)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=)
tmpfs on /var/lock type tmpfs (rw,nosuid,nodev,relatime,mode=)
tmpfs on /var/run type tmpfs (rw,nosuid,nodev,relatime,mode=)

或者:

not@linux-numy:~> df -h | grep -E "(tmpfs|ramfs)"
devtmpfs .9G 16K .9G % /dev
tmpfs .9G 27M .9G % /dev/shm
tmpfs .9G 4.3M .9G % /run
tmpfs .9G .9G % /sys/fs/cgroup
tmpfs .9G 4.3M .9G % /var/lock
tmpfs .9G 4.3M .9G % /var/run

我的系统(openSUSE 13.1 “Bottle”, kernel version: 3.11.10-21)中,使用的都是tmpfs。我想原因可能是,当存在写溢出时,tmpfs比ramfs更加安全,因为前者会给出错误提示并禁止写操作。

创建

创建tmpfs:

linux-numy:~ # mkdir -p /mnt/tmp
linux-numy:~ # mount -t tmpfs -o size=20m tmpfs /mnt/tmp/
linux-numy:~ # df -h | grep "/mnt/tmp"
tmpfs 20M 20M % /mnt/tmp

创建ramfs:

linux-numy:~ # mkdir -p /mnt/ram
linux-numy:~ # mount -t ramfs -o size=20m ramfs /mnt/ram/
linux-numy:~ # df -ah | grep "/mnt/ram"
ramfs - /mnt/ram

这里df只使用h选项是无法显示ramfs的内容的。

df无法显示ramfs信息的原因(无-a选项)

根据superuser.com上的问答《Have I successfully created an ramfs drive?》,Sachin Divekar给出了一段资料引用:

For a ramfs filesystem, the newer kernels report nothing back using “df”. There is meant to be a patch for this (to allow for accounting in a ramfs). Philosophically, ramfs is mean to be as simple as possible, apparently, hence the lack of accounting. So data can be stored and used on the ramfs disk, but no accounting of it is possible, other than a loss of memory shown with “free”. For this reason the tmpfs is better, since it does keep accounting and “df” shows what’s going on.

即,tmpfs会对内存进行accounting(统计内存的使用情况),而ramfs被设计为尽可能的简单,所以不会进行accounting。因此,针对ramfs,在较新的内核中,使用df不会返回ramfs的信息。

参考资料

Overview of RAMFS and TMPFS on Linux

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731