读取时间测试

为防止内存catche中已缓存文件, 影响读取速度判别

sudo -i
查看内存使用情况
free -m
同步
sync
清理缓存
bash -c "echo 3 > /proc/sys/vm/drop_caches"
重新查看内存使用情况
free -m


关于drop_caches文件:系统默认为0
参考:https://www.lmlphp.com/user/16595/article/item/501563/
https://blog.youkuaiyun.com/a772304419/article/details/125777549
在Documentation/sysctl/vm.txt中有如下描述:

drop_caches

Writing to this will cause the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free.

To free pagecache:仅清除页面缓存(PageCache)
 echo 1 > /proc/sys/vm/drop_caches

To free dentries and inodes:清除目录项和inode
 echo 2 > /proc/sys/vm/drop_caches

To free pagecache, dentries and inodes:清除页面缓存,目录项和inode
 echo 3 > /proc/sys/vm/drop_caches

As this is a non-destructive operation and dirty objects are not freeable, the user should run `sync' first.


直接运行echo 3 > /proc/sys/vm/drop_caches会提示权限不足
错误原因:bash ,提示权限不够,是因为重定向符号 “>” 也是 bash 的命令。sudo 只是让 echo 命令具有了 root 权限,但是并没有让 “>” 命令也具有root 权限,所以 bash 会认为这个命令没有写入信息的权限。
使用chmod也无法生效:正在更改 'drop_caches' 的权限: 不允许的操作
所以使用bash -c "" 为命令添加权限
https://blog.youkuaiyun.com/weixin_44663188/article/details/121944241


room401@room401-System-Product-Name:~/ramdisk/read_test/build$ ./readTimeCount ../2022-09-01-11-09-24_120.bag 
argv[1]: ../2022-09-01-11-09-24_120.bag
-------

total read time: 14.6586
room401@room401-System-Product-Name:~/ramdisk/read_test/build$ ./readTimeCount /mnt/ramdisk_test/2022-09-01-11-09-24_120.bag 
argv[1]: /mnt/ramdisk_test/2022-09-01-11-09-24_120.bag
-------

total read time: 0.916799
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值