在Linux中无需磁盘缓存即可读取文件 [英] Read file without disk caching in Linux

查看:186
本文介绍了在Linux中无需磁盘缓存即可读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C程序,该程序仅每周运行一次,并且仅一次读取一次文件.由于Linux还缓存了读取的所有内容,因此它们会不必要地填满缓存,除非系统具有SSD驱动器,否则这会大大降低系统的速度.

I have a C program that runs only weekly, and reads a large amount of files only once. Since Linux also caches everything that's read, they fill up the cache needlessly and this slows down the system a lot unless it has an SSD drive.

那么如何在不填满磁盘缓存的情况下打开和读取文件?

So how do I open and read from a file without filling up the disk cache?

注意:

通过磁盘缓存,我的意思是当您两次读取文件时,第二次从RAM而不是从磁盘读取文件. IE.从磁盘读取的数据一旦被保留在RAM中,因此以后对同一文件的读取将不需要从磁盘重新读取数据.

By disk caching I mean that when you read a file twice, the second time it's read from RAM, not from disk. I.e. data once read from the disk is left in RAM, so subsequent reads of the same file will not need to reread the data from disk.

推荐答案

您可以使用

You can use posix_fadvise() with the POSIX_FADV_DONTNEED advice to request that the system free the pages you've already read.

这篇关于在Linux中无需磁盘缓存即可读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆