Skip to the content.

fscache

基本代码结构

config FSCACHE
	bool "General filesystem local caching manager"
	depends on NETFS_SUPPORT
	help
	  This option enables a generic filesystem caching manager that can be
	  used by various network and other filesystems to cache data locally.
	  Different sorts of caches can be plugged in, depending on the
	  resources available.

	  See Documentation/filesystems/caching/fscache.rst for more information.

依赖 fscache 的文件系统

他们都是有 CONFIG_NFS_FSCACHE 的代码

但是 coda fs 也是一个文件系统,但是不依赖于 fscache

/proc

🧀  l /proc/fs/
Permissions Size User Date Modified Name
dr-xr-xr-x     - root 22 Jan 17:05   ext4
lrwxrwxrwx     - root 22 Jan 17:05   fscache -> netfs
dr-xr-xr-x     - root 22 Jan 17:05   jbd2
dr-xr-xr-x     - root 22 Jan 17:05   lockd
dr-xr-xr-x     - root 22 Jan 17:05   netfs
dr-xr-xr-x     - root 22 Jan 17:05   nfsd
dr-xr-xr-x     - root 22 Jan 17:05   nfsfs

为什么建立这个软链接啊,这么说,其实 /proc/ 是有其他的实现的吗?

fs/netfs/fscache_proc.c:fscache_proc_init 中的

	if (!proc_symlink("fs/fscache", NULL, "netfs"))
		goto error_sym;

看来在这一次重构中: commit 7eb5b3e3a0a5 (“netfs, fscache: Move /proc/fs/fscache to /proc/fs/netfs and put in a symlink”)

关键重构内容

netfs

fs/netfs/

🧀  tree /proc/fs/netfs
/proc/fs/netfs
├── caches
├── cookies
├── requests
├── stats
└── volumes

基本结构

例如 fs/9p/vfs_file.c 会调用到 v9fs_file_write_iter

这个就是 netfs cache 吗?

[   48.833775] netfs: FS-Cache loaded

看看文档再说

关键问题

  1. 先实际上触发一些,然后测试一下效果吧
    sudo bpftrace -e 'kprobe:nfs_fscache_open_file { @[kstack(bpftrace)] = count(); }'
    
  2. 可以写一个基于 netfs 的文件系统吗?

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。