如何在Linux中操纵页面缓存? [英] How to manipulate page cache in Linux?
问题描述
我想知道页面缓存中缓存了哪些文件,并希望实用地释放特定文件的缓存空间.如果需要,我可以编写内核模块,甚至修改内核代码.谁能给我一些线索?
I want to know what files are cached in Page Cache, and want to free the cache space of a specific file pragmatically. It is possible for me to write kernel module or even modify the kernel code if needed. Can anyone give me some clues?
推荐答案
首先,内核不维护页面缓存中所有文件的主列表,因为它不需要此类信息.相反,给定一个inode,您可以查找关联的页面缓存页面,反之亦然.
Firstly, the kernel does not maintain a master list of all files in the page cache, because it has no need for such information. Instead, given an inode you can look up the associated page cache pages, and vice-versa.
对于每个页面缓存struct page
,page_mapping()
将返回其所属的struct address_space
. struct address_space
的host
成员标识拥有的struct inode
,然后您可以从中获取inode编号和设备.
For each page cache struct page
, page_mapping()
will return the struct address_space
that it belongs to. The host
member of struct address_space
identifies the owning struct inode
, and from there you can get the inode number and device.
这篇关于如何在Linux中操纵页面缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!