fs/drop_caches: skip filesystems without fs writeback
PATCH 1/1 fs/drop_caches: skip filesystems without fs writeback
Filesystems backed by the noop backing device (procfs, sysfs, kernfs, tmpfs, ramfs, etc.) have no fs page-cache writeback. Skip them in drop_pagecache_sb() instead of walking their inode lists.
This also skips tmpfs/ramfs. tmpfs has clean folios which are zero-filled pages from reading holes, which are trivially recreatable.
---
The RFC mails:
https://lore.kernel.org/all/[email protected]/
--- fs/drop_caches.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/drop_caches.c +4 -0
@@ -7,6 +7,7 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/backing-dev.h> #include <linux/writeback.h> #include <linux/sysctl.h> #include <linux/gfp.h>
@@ -20,6 +21,9 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) {struct inode *inode, *toput_inode =NULL ; +if (sb->s_bdi == &noop_backing_dev_info) +return ; +spin_lock (&sb->s_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);
Signature · 1 line
2.53.0
Quoted 9 lines · Huang Shijie
Filesystems backed by the noop backing device (procfs, sysfs, kernfs, tmpfs, ramfs, etc.) have no fs page-cache writeback. Skip them in
drop_pagecache_sb()instead of walking their inode lists.This also skips tmpfs/ramfs. tmpfs has clean folios which are zero-filled pages from reading holes, which are trivially recreatable.
Suggested-by Christoph Hellwig <[email protected]>Signed-off-by Huang Shijie <[email protected]>
This looks indeed nice & simple. I'm slightly wondering if there isn't some exotic read-only fs somewhere which doesn't set sb->s_bdi but so far I'm not aware of anything (even MTD filesystems do properly setup bdi) so feel free to add:
Honza
Quoted 33 lines
---
The RFC mails:
https://lore.kernel.org/all/[email protected]/--- fs/drop_caches.c | 4 ++++ 1 file changed, 4 insertions(+)fs/drop_caches.c +4
-0@@ -7,6 +7,7 @@#include <linux/kernel.h> #include <linux/mm.h> #include <linux/fs.h> +#include <linux/backing-dev.h> #include <linux/writeback.h> #include <linux/sysctl.h> #include <linux/gfp.h> @@ -20,6 +21,9 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) {struct inode *inode, *toput_inode =NULL ; +if (sb->s_bdi == &noop_backing_dev_info) +return ; +spin_lock (&sb->s_inode_list_lock);list_for_each_entry (inode, &sb->s_inodes, i_sb_list) {spin_lock (&inode->i_lock);Signature · 1 line
2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Looks good: