Linux文件系统缓存文件是否有效? [英] Does the Linux filesystem cache files efficiently?

查看:412
本文介绍了Linux文件系统缓存文件是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个运行在Linux服务器上的Web应用程序。应用程序正在不断地访问一个250K文件 - 它将其加载到内存中,读取它并向用户发回一些信息。由于这个文件总是被读取,所以我的客户端正在建议使用类似于memcache的东西来将其缓存到内存中,这可能是因为它会使读取操作变得更快。



然而,我在考虑Linux文件系统可能已经将文件缓存在内存中,因为它经常被访问。是对的吗?在你看来,memcache会提供一个真正的改进吗?或者它会做同样的事情,Linux已经在做什么?



我不是很熟悉Linux和memcache,所以我会很感激,如果有人可以澄清这一点。

解决方案

是的,如果你每次打开它都不修改文件。 b
Linux将把文件的信息保存在内存中的copy-on-write页面上,并且将文件加载到内存中应该是非常快的(最坏的情况是页表交换)。
$ b

编辑:虽然,正如cdhowie指出的那样,没有linux文件系统。但是,我相信相关的代码是在linux的内存管理中,因此独立于所讨论的文件系统。如果您好奇的话,可以在linux源代码中阅读关于处理linux / mm / mmap.c中的vm_area_struct对象的信息。


I'm creating a web application running on a Linux server. The application is constantly accessing a 250K file - it loads it in memory, reads it and sends back some info to the user. Since this file is read all the time, my client is suggesting to use something like memcache to cache it to memory, presumably because it will make read operations faster.

However, I'm thinking that the Linux filesystem is probably already caching the file in memory since it's accessed frequently. Is that right? In your opinion, would memcache provide a real improvement? Or is it going to do the same thing that Linux is already doing?

I'm not really familiar with neither Linux nor memcache, so I would really appreciate if someone could clarify this.

解决方案

Yes, if you do not modify the file each time you open it.

Linux will hold the file's information in copy-on-write pages in memory, and "loading" the file into memory should be very fast (page table swap at worst).

Edit: Though, as cdhowie points out, there is no 'linux filesystem'. However, I believe the relevant code is in linux's memory management, and is therefore independent of the filesystem in question. If you're curious, you can read in the linux source about handling vm_area_struct objects in linux/mm/mmap.c, mainly.

这篇关于Linux文件系统缓存文件是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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