implement containerized syncfs for overlayfs
Subsystems (3)
v6 cover implement containerized syncfs for overlayfs
From: Chengguang Xu <[email protected]>
Current syncfs(2) syscall on overlayfs just calls sync_filesystem() on upper_sb to synchronize whole dirty inodes in upper filesystem regardless of the overlay ownership of the inode. In the use case of container, when multiple containers using the same underlying upper filesystem, it has some shortcomings as below.
(1) Performance
Synchronization is probably heavy because it actually syncs unnecessary inodes for target overlayfs.
(2) Interference
Unplanned synchronization will probably impact IO performance of unrelated container processes on the other overlayfs.
This series try to implement containerized syncfs for overlayfs so that only sync target dirty upper inodes which are belong to specific overlayfs instance. By doing this, it is able to reduce cost of synchronization and will not seriously impact IO performance of unrelated processes.
v1->v2:
- Mark overlayfs' inode dirty itself instead of adding notification mechanism to vfs inode.
v2->v3:
- Introduce overlayfs' extra syncfs wait list to wait target upper inodes in ->sync_fs.
v3->v4:
- Using wait_sb_inodes() to wait syncing upper inodes.
- Mark overlay inode dirty only when having upper inode and VM_SHARED flag in ovl_mmap().
- Check upper i_state after checking upper mmap state
in ovl_write_inode.
v4->v5:
- Add underlying inode dirtiness check after mnt_drop_write().
- Handle both wait/no-wait mode of syncfs(2) in overlayfs' ->sync_fs().
v5->v6:
- Rebase to latest overlayfs-next tree.
- Mark oerlay inode dirty when it has upper instead of marking dirty on modification.
- Trigger dirty page writeback in overlayfs' ->write_inode().
- Mark overlay inode 'DONTCACHE' flag.
- Delete overlayfs' ->writepages() and ->evict_inode() operations.
Chengguang Xu (7):
ovl: setup overlayfs' private bdi
ovl: mark overlayfs inode dirty when it has upper
ovl: implement overlayfs' own ->write_inode operation
ovl: set 'DONTCACHE' flag for overlayfs inode
fs: export wait_sb_inodes()
ovl: introduce ovl_sync_upper_blockdev()
ovl: implement containerized syncfs for overlayfs
fs/fs-writeback.c | 3 ++- fs/overlayfs/inode.c | 5 +++- fs/overlayfs/super.c | 49 ++++++++++++++++++++++++++++++++------- fs/overlayfs/util.c | 1 + include/linux/writeback.h | 1 + 5 files changed, 48 insertions(+), 11 deletions(-)
Signature · 1 line
2.27.0
RFC PATCH v6 1/7 ovl: setup overlayfs' private bdi
From: Chengguang Xu <[email protected]>
Setup overlayfs' private bdi so that we can collect overlayfs' own dirty inodes.
--- fs/overlayfs/super.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/overlayfs/super.c +4 -0
@@ -1984,6 +1984,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)if (!ofs) goto out; + err =super_setup_bdi (sb); +if (err) + goto out_err; + err = -ENOMEM ; ofs->creator_cred = cred =prepare_creds ();if (!cred)
Signature · 1 line
2.27.0
Re: [RFC PATCH V6 1/7] ovl: setup overlayfs' private bdi
Quoted 6 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Setup overlayfs' private bdi so that we can collect overlayfs' own dirty inodes.
Signed-off-by Chengguang Xu <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 23 lines
--- fs/overlayfs/super.c | 4 ++++ 1 file changed, 4 insertions(+)fs/overlayfs/super.c +4
-0@@ -1984,6 +1984,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)if (!ofs) goto out; + err =super_setup_bdi (sb); +if (err) + goto out_err; + err = -ENOMEM ; ofs->creator_cred = cred =prepare_creds ();if (!cred)Signature · 1 line
2.27.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 2/7 ovl: mark overlayfs inode dirty when it has upper
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
We simply mark overlayfs inode dirty when it has upper, it's much simpler than mark dirtiness on modification.
--- fs/overlayfs/inode.c | 4 +++- fs/overlayfs/util.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
fs/overlayfs/inode.c +3 -1
@@ -778,8 +778,10 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, {struct inode *realinode; -if (oip->upperdentry) +if (oip->upperdentry) {OVL_I (inode)->__upperdentry = oip->upperdentry; +mark_inode_dirty (inode); + }if (oip->lowerpath && oip->lowerpath->dentry)OVL_I (inode)->lower =igrab (d_inode (oip->lowerpath->dentry));if (oip->lowerdata)
fs/overlayfs/util.c +1 -0
@@ -421,6 +421,7 @@ void ovl_inode_update(struct inode *inode, struct dentry *upperdentry) inode->i_private = upperinode;__insert_inode_hash (inode, (unsigned long ) upperinode); } +mark_inode_dirty (inode); }static void ovl_dir_version_inc (struct dentry *dentry,bool impurity)
Signature · 1 line
2.27.0
Jan Kara
maintainerRe: [RFC PATCH V6 2/7] ovl: mark overlayfs inode dirty when it has upper
Quoted 17 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
We simply mark overlayfs inode dirty when it has upper, it's much simpler than mark dirtiness on modification.
Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/inode.c | 4 +++- fs/overlayfs/util.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)fs/overlayfs/inode.c +0
-0@@ -778,8 +778,10 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, {
fs/overlayfs/inode.c void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, · line 787
Quoted 10 lines
fs/overlayfs/inode.c +3
-1struct inode *realinode; -if (oip->upperdentry) +if (oip->upperdentry) {OVL_I (inode)->__upperdentry = oip->upperdentry; +mark_inode_dirty (inode); + }if (oip->lowerpath && oip->lowerpath->dentry)OVL_I (inode)->lower =igrab (d_inode (oip->lowerpath->dentry));if (oip->lowerdata)
Hum, does this get called only for inodes with upper inode existing? I suppose we do not need to track inodes that were not copied up because they cannot be dirty? I'm sorry, my knowledge of overlayfs is rather limited so I may be missing something basic.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V6 2/7] ovl: mark overlayfs inode dirty when it has upper
---- 在 星期五, 2021-11-26 17:10:07 Jan Kara <[email protected]> 撰写 ----
Quoted 20 lines · Chengguang Xu
Quoted 19 lines
From: Chengguang Xu <[email protected]>
We simply mark overlayfs inode dirty when it has upper, it's much simpler than mark dirtiness on modification.
Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/inode.c | 4 +++- fs/overlayfs/util.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)fs/overlayfs/inode.c +0
-0@@ -778,8 +778,10 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, {struct inode *realinode;
Quoted 14 lines
fs/overlayfs/inode.c void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, · line 787
Quoted 8 lines
fs/overlayfs/inode.c +3
-1-if (oip->upperdentry) +if (oip->upperdentry) {OVL_I (inode)->__upperdentry = oip->upperdentry; +mark_inode_dirty (inode); + }if (oip->lowerpath && oip->lowerpath->dentry)OVL_I (inode)->lower =igrab (d_inode (oip->lowerpath->dentry));if (oip->lowerdata)Hum, does this get called only for inodes with upper inode existing? I suppose we do not need to track inodes that were not copied up because they cannot be dirty? I'm sorry, my knowledge of overlayfs is rather limited so I may be missing something basic.
Well, as long as overly inode has upper it can be modified without copy-up, so we need to track all overlay inodes which have upper inode.
Thanks,
Chengguang
Re: [RFC PATCH V6 2/7] ovl: mark overlayfs inode dirty when it has upper
Quoted 36 lines · Chengguang Xu
---- 在 星期五, 2021-11-26 17:10:07 Jan Kara <[email protected]> 撰写 ----
Quoted 20 lines · Chengguang Xu
Quoted 19 lines
From: Chengguang Xu <[email protected]>
We simply mark overlayfs inode dirty when it has upper, it's much simpler than mark dirtiness on modification.
Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/inode.c | 4 +++- fs/overlayfs/util.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)fs/overlayfs/inode.c +0
-0@@ -778,8 +778,10 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, {struct inode *realinode;Quoted 14 lines
fs/overlayfs/inode.c void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, · line 787
Quoted 8 lines
fs/overlayfs/inode.c +3
-1-if (oip->upperdentry) +if (oip->upperdentry) {OVL_I (inode)->__upperdentry = oip->upperdentry; +mark_inode_dirty (inode); + }if (oip->lowerpath && oip->lowerpath->dentry)OVL_I (inode)->lower =igrab (d_inode (oip->lowerpath->dentry));if (oip->lowerdata)Hum, does this get called only for inodes with upper inode existing? I suppose we do not need to track inodes that were not copied up because they cannot be dirty? I'm sorry, my knowledge of overlayfs is rather limited so I may be missing something basic.
Quoted 2 lines
Well, as long as overly inode has upper it can be modified without copy-up, so we need to track all overlay inodes which have upper inode.
OK, and oip->upperdentry is set only if there's upper inode, now I understand. Thanks for explanation and feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 3/7 ovl: implement overlayfs' own ->write_inode operation
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
Sync dirty data and meta of upper inode in overlayfs' ->write_inode() and redirty overlayfs' inode.
--- fs/overlayfs/super.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
fs/overlayfs/super.c +21 -0
@@ -15,6 +15,7 @@#include <linux/seq_file.h> #include <linux/posix_acl_xattr.h> #include <linux/exportfs.h> +#include <linux/writeback.h> #include "overlayfs.h" MODULE_AUTHOR ("Miklos Szeredi <[email protected]>" );
@@ -406,12 +407,32 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)return ret; } +static int ovl_write_inode (struct inode *inode, +struct writeback_control *wbc) +{ +struct ovl_fs *ofs = inode->i_sb->s_fs_info; +struct inode *upper_inode =ovl_inode_upper (inode); +int ret =0 ; + +if (!upper_inode) +return 0 ; + +if (!ovl_should_sync (ofs)) +return 0 ; + + ret =write_inode_now (upper_inode, wbc->sync_mode ==WB_SYNC_ALL ); +mark_inode_dirty (inode); + +return ret; +} +static const struct super_operations ovl_super_operations = { .alloc_inode = ovl_alloc_inode, .free_inode = ovl_free_inode, .destroy_inode = ovl_destroy_inode, .drop_inode = generic_delete_inode, .put_super = ovl_put_super, + .write_inode = ovl_write_inode, .sync_fs = ovl_sync_fs, .statfs = ovl_statfs, .show_options = ovl_show_options,
Signature · 1 line
2.27.0
Re: [RFC PATCH V6 3/7] ovl: implement overlayfs' own ->write_inode operation
Quoted 6 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Sync dirty data and meta of upper inode in overlayfs' ->write_inode() and redirty overlayfs' inode.
Signed-off-by Chengguang Xu <[email protected]>
Looks good. I'm still not 100% convinced keeping inodes dirty all the time will not fire back in excessive writeback activity (e.g. flush worker will traverse the list of all dirty inodes every 30 seconds and try to write them) but I guess we can start with this and if people complain, dirtiness handling can be improved. So feel free to add:
Honza
Quoted 53 lines
--- fs/overlayfs/super.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)fs/overlayfs/super.c +21
-0@@ -15,6 +15,7 @@#include <linux/seq_file.h> #include <linux/posix_acl_xattr.h> #include <linux/exportfs.h> +#include <linux/writeback.h> #include "overlayfs.h" MODULE_AUTHOR ("Miklos Szeredi <[email protected]>" );@@ -406,12 +407,32 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)return ret; } +static int ovl_write_inode (struct inode *inode, +struct writeback_control *wbc) +{ +struct ovl_fs *ofs = inode->i_sb->s_fs_info; +struct inode *upper_inode =ovl_inode_upper (inode); +int ret =0 ; + +if (!upper_inode) +return 0 ; + +if (!ovl_should_sync (ofs)) +return 0 ; + + ret =write_inode_now (upper_inode, wbc->sync_mode ==WB_SYNC_ALL ); +mark_inode_dirty (inode); + +return ret; +} +static const struct super_operations ovl_super_operations = { .alloc_inode = ovl_alloc_inode, .free_inode = ovl_free_inode, .destroy_inode = ovl_destroy_inode, .drop_inode = generic_delete_inode, .put_super = ovl_put_super, + .write_inode = ovl_write_inode, .sync_fs = ovl_sync_fs, .statfs = ovl_statfs, .show_options = ovl_show_options,Signature · 1 line
2.27.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [RFC PATCH V6 3/7] ovl: implement overlayfs' own ->write_inode operation
---- 在 星期五, 2021-11-26 17:14:30 Jan Kara <[email protected]> 撰写 ----
Quoted 6 lines · Chengguang Xu
Quoted 5 lines
From: Chengguang Xu <[email protected]>
Sync dirty data and meta of upper inode in overlayfs' ->write_inode() and redirty overlayfs' inode.
Quoted 7 lines
Quoted 1 line
Signed-off-by Chengguang Xu <[email protected]>Looks good. I'm still not 100% convinced keeping inodes dirty all the time will not fire back in excessive writeback activity (e.g. flush worker will traverse the list of all dirty inodes every 30 seconds and try to write them) but I guess we can start with this and if people complain, dirtiness handling can be improved.
Hi Jan,
Thanks for the review and suggestion.
Thanks,
Chengguang
Quoted 63 lines
So feel free to add:
Reviewed-by Jan Kara <[email protected]>Honza
Quoted 53 lines
--- fs/overlayfs/super.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)fs/overlayfs/super.c +21
-0@@ -15,6 +15,7 @@#include <linux/seq_file.h> #include <linux/posix_acl_xattr.h> #include <linux/exportfs.h> +#include <linux/writeback.h> #include "overlayfs.h" MODULE_AUTHOR ("Miklos Szeredi <[email protected]>" );@@ -406,12 +407,32 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)return ret; } +static int ovl_write_inode (struct inode *inode, +struct writeback_control *wbc) +{ +struct ovl_fs *ofs = inode->i_sb->s_fs_info; +struct inode *upper_inode =ovl_inode_upper (inode); +int ret =0 ; + +if (!upper_inode) +return 0 ; + +if (!ovl_should_sync (ofs)) +return 0 ; + + ret =write_inode_now (upper_inode, wbc->sync_mode ==WB_SYNC_ALL ); +mark_inode_dirty (inode); + +return ret; +} +static const struct super_operations ovl_super_operations = { .alloc_inode = ovl_alloc_inode, .free_inode = ovl_free_inode, .destroy_inode = ovl_destroy_inode, .drop_inode = generic_delete_inode, .put_super = ovl_put_super, + .write_inode = ovl_write_inode, .sync_fs = ovl_sync_fs, .statfs = ovl_statfs, .show_options = ovl_show_options,Signature · 1 line
2.27.0Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 4/7 ovl: set 'DONTCACHE' flag for overlayfs inode
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
Set 'DONTCACHE' flag to overlayfs inode so that
upper inode to be always synced before eviction.
--- fs/overlayfs/inode.c | 1 + 1 file changed, 1 insertion(+)
fs/overlayfs/inode.c +1 -0
@@ -791,6 +791,7 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,ovl_copyattr (realinode, inode);ovl_copyflags (realinode, inode);ovl_map_ino (inode, ino, fsid); +d_mark_dontcache (inode); }static void ovl_fill_inode (struct inode *inode,umode_t mode,dev_t rdev)
Signature · 1 line
2.27.0
Jan Kara
maintainerRe: [RFC PATCH V6 4/7] ovl: set 'DONTCACHE' flag for overlayfs inode
Quoted 15 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Set 'DONTCACHE' flag to overlayfs inode so that
upper inode to be always synced before eviction.Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/inode.c | 1 + 1 file changed, 1 insertion(+)fs/overlayfs/inode.c +0
-0
fs/overlayfs/inode.c void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip, · line 795
Quoted 5 lines
fs/overlayfs/inode.c +1
-0@@ -791,6 +791,7 @@ void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,ovl_copyattr (realinode, inode);ovl_copyflags (realinode, inode);ovl_map_ino (inode, ino, fsid); +d_mark_dontcache (inode); }
Doesn't this effectively disable dcache for overlayfs dentries? I mean e.g. whenever overlayfs file is closed, we will drop its dentry & inode from the cache. Upper and lower inodes / dentries stay in cache so no disk access should be needed to reconstruct overlayfs dentry & inode but still it may be a bit costly? I guess others more familiar with overlayfs have to judge.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 5/7 fs: export wait_sb_inodes()
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
In order to wait syncing upper inodes we need to
call wait_sb_inodes() in overlayfs' ->sync_fs.
--- fs/fs-writeback.c | 3 ++- include/linux/writeback.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
fs/fs-writeback.c +2 -1
@@ -2505,7 +2505,7 @@ EXPORT_SYMBOL(__mark_inode_dirty);* completed by the time we have gained the lock and waited for all IO that is * in progress regardless of the order callers are granted the lock. */ -static void wait_sb_inodes (struct super_block *sb) +void wait_sb_inodes (struct super_block *sb) {LIST_HEAD (sync_list);
@@ -2589,6 +2589,7 @@ static void wait_sb_inodes(struct super_block *sb)rcu_read_unlock ();mutex_unlock (&sb->s_sync_lock); } +EXPORT_SYMBOL (wait_sb_inodes);static void __writeback_inodes_sb_nr (struct super_block *sb,unsigned long nr,enum wb_reason reason,bool skip_if_busy)
include/linux/writeback.h +1 -0
@@ -198,6 +198,7 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, enum wb_reason reason);void inode_wait_for_writeback (struct inode *inode);void inode_io_list_del (struct inode *inode); +void wait_sb_inodes (struct super_block *sb);/* writeback.h requires fs.h; it, too, is not included from here. */ static inline void wait_on_inode (struct inode *inode)
Signature · 1 line
2.27.0
Re: [RFC PATCH V6 5/7] fs: export wait_sb_inodes()
Quoted 6 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
In order to wait syncing upper inodes we need to
callwait_sb_inodes()in overlayfs' ->sync_fs.Signed-off-by Chengguang Xu <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 42 lines
--- fs/fs-writeback.c | 3 ++- include/linux/writeback.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)fs/fs-writeback.c +2
-1@@ -2505,7 +2505,7 @@ EXPORT_SYMBOL(__mark_inode_dirty);* completed by the time we have gained the lock and waited for all IO that is * in progress regardless of the order callers are granted the lock. */ -static void wait_sb_inodes (struct super_block *sb) +void wait_sb_inodes (struct super_block *sb) {LIST_HEAD (sync_list);@@ -2589,6 +2589,7 @@ static void wait_sb_inodes(struct super_block *sb)rcu_read_unlock ();mutex_unlock (&sb->s_sync_lock); } +EXPORT_SYMBOL (wait_sb_inodes);static void __writeback_inodes_sb_nr (struct super_block *sb,unsigned long nr,enum wb_reason reason,bool skip_if_busy)include/linux/writeback.h +1
-0@@ -198,6 +198,7 @@ void wakeup_flusher_threads_bdi(struct backing_dev_info *bdi, enum wb_reason reason);void inode_wait_for_writeback (struct inode *inode);void inode_io_list_del (struct inode *inode); +void wait_sb_inodes (struct super_block *sb);/* writeback.h requires fs.h; it, too, is not included from here. */ static inline void wait_on_inode (struct inode *inode)Signature · 1 line
2.27.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 6/7 ovl: introduce ovl_sync_upper_blockdev()
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
Introduce new helper ovl_sync_upper_blockdev() to sync upper blockdev.
--- fs/overlayfs/super.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/overlayfs/super.c +10 -0
@@ -258,6 +258,16 @@ static void ovl_put_super(struct super_block *sb)ovl_free_fs (ofs); } +static int ovl_sync_upper_blockdev (struct super_block *sb,int wait) +{ +if (!sb->s_bdev) +return 0 ; + +if (!wait) +return filemap_flush (sb->s_bdev->bd_inode->i_mapping); +return filemap_write_and_wait_range (sb->s_bdev->bd_inode->i_mapping,0 ,LLONG_MAX ); +} +/* Sync real dirty inodes in upper filesystem (if it exists) */ static int ovl_sync_fs (struct super_block *sb,int wait) {
Signature · 1 line
2.27.0
Re: [RFC PATCH V6 6/7] ovl: introduce ovl_sync_upper_blockdev()
Quoted 6 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Introduce new helper
ovl_sync_upper_blockdev()to sync upper blockdev.Signed-off-by Chengguang Xu <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 29 lines
--- fs/overlayfs/super.c | 10 ++++++++++ 1 file changed, 10 insertions(+)fs/overlayfs/super.c +10
-0@@ -258,6 +258,16 @@ static void ovl_put_super(struct super_block *sb)ovl_free_fs (ofs); } +static int ovl_sync_upper_blockdev (struct super_block *sb,int wait) +{ +if (!sb->s_bdev) +return 0 ; + +if (!wait) +return filemap_flush (sb->s_bdev->bd_inode->i_mapping); +return filemap_write_and_wait_range (sb->s_bdev->bd_inode->i_mapping,0 ,LLONG_MAX ); +} +/* Sync real dirty inodes in upper filesystem (if it exists) */ static int ovl_sync_fs (struct super_block *sb,int wait) {Signature · 1 line
2.27.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
RFC PATCH v6 7/7 ovl: implement containerized syncfs for overlayfs
In reply to Chengguang XuFrom: Chengguang Xu <[email protected]>
Now overlayfs can only sync own dirty inodes during syncfs, so remove unnecessary sync_filesystem() on upper file system.
--- fs/overlayfs/super.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
fs/overlayfs/super.c +5 -9
@@ -292,18 +292,14 @@ static int ovl_sync_fs(struct super_block *sb, int wait)/* * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC). * All the super blocks will be iterated, including upper_sb. -* -* If this is a syncfs(2) call, then we do need to call -* sync_filesystem() on upper_sb, but enough if we do it when being -* called with wait == 1. */ -if (!wait) -return 0 ; - upper_sb =ovl_upper_mnt (ofs)->mnt_sb; -down_read (&upper_sb->s_umount); - ret =sync_filesystem (upper_sb); +if (wait) +wait_sb_inodes (upper_sb); +if (upper_sb->s_op->sync_fs) + upper_sb->s_op->sync_fs (upper_sb, wait); + ret =ovl_sync_upper_blockdev (upper_sb, wait);up_read (&upper_sb->s_umount);return ret;
Signature · 1 line
2.27.0
Amir Goldstein
maintainerRe: [RFC PATCH V6 7/7] ovl: implement containerized syncfs for overlayfs
Quoted 26 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Now overlayfs can only sync own dirty inodes during syncfs, so remove unnecessary
sync_filesystem()on upper file system.Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/super.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)fs/overlayfs/super.c +0
-6@@ -292,18 +292,14 @@ static int ovl_sync_fs(struct super_block *sb, int wait)/* * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC). * All the super blocks will be iterated, including upper_sb. -* -* If this is a syncfs(2) call, then we do need to call -* sync_filesystem() on upper_sb, but enough if we do it when being -* called with wait == 1. */ -if (!wait) -return 0 ;
fs/overlayfs/super.c static int ovl_sync_fs(struct super_block *sb, int wait) · line 302
Quoted 10 lines
fs/overlayfs/super.c +5
-3- upper_sb =ovl_upper_mnt (ofs)->mnt_sb; -down_read (&upper_sb->s_umount); - ret =sync_filesystem (upper_sb); +if (wait) +wait_sb_inodes (upper_sb); +if (upper_sb->s_op->sync_fs) + upper_sb->s_op->sync_fs (upper_sb, wait); + ret =ovl_sync_upper_blockdev (upper_sb, wait);
I think it will be cleaner to use a helper ovl_sync_upper_filesystem() with everything from upper_sb = ... and a comment to explain that this is a variant of __sync_filesystem() where all the dirty inodes write have already been started.
Thanks,
Amir.
P.S. I like this "stoopid proof" v6 because I can understand it ;-)
Re: [RFC PATCH V6 7/7] ovl: implement containerized syncfs for overlayfs
---- 在 星期一, 2021-11-22 15:40:59 Amir Goldstein <[email protected]> 撰写 ----
Quoted 34 lines · Chengguang Xu
Quoted 33 lines
From: Chengguang Xu <[email protected]>
Now overlayfs can only sync own dirty inodes during syncfs, so remove unnecessary
sync_filesystem()on upper file system.Signed-off-by Chengguang Xu <[email protected]>--- fs/overlayfs/super.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)fs/overlayfs/super.c +2
-9@@ -292,18 +292,14 @@ static int ovl_sync_fs(struct super_block *sb, int wait)/* * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC). * All the super blocks will be iterated, including upper_sb. -* -* If this is a syncfs(2) call, then we do need to call -* sync_filesystem() on upper_sb, but enough if we do it when being -* called with wait == 1. */ -if (!wait) -return 0 ; - upper_sb =ovl_upper_mnt (ofs)->mnt_sb; -down_read (&upper_sb->s_umount); - ret =sync_filesystem (upper_sb); +if (wait) +wait_sb_inodes (upper_sb);
Quoted 9 lines
fs/overlayfs/super.c static int ovl_sync_fs(struct super_block *sb, int wait) · line 302
Quoted 3 lines
fs/overlayfs/super.c +3
-0+if (upper_sb->s_op->sync_fs) + upper_sb->s_op->sync_fs (upper_sb, wait); + ret =ovl_sync_upper_blockdev (upper_sb, wait);I think it will be cleaner to use a helper
ovl_sync_upper_filesystem()with everything fromupper_sb= ... and a comment to explain that this is a variant of__sync_filesystem()where all the dirty inodes write have already been started.
I agree with you.
Thanks,
Chengguang
Re: [RFC PATCH V6 7/7] ovl: implement containerized syncfs for overlayfs
In reply to Chengguang XuQuoted 6 lines · Chengguang Xu
From: Chengguang Xu <[email protected]>
Now overlayfs can only sync own dirty inodes during syncfs, so remove unnecessary
sync_filesystem()on upper file system.Signed-off-by Chengguang Xu <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 36 lines
--- fs/overlayfs/super.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)fs/overlayfs/super.c +5
-9@@ -292,18 +292,14 @@ static int ovl_sync_fs(struct super_block *sb, int wait)/* * Not called for sync(2) call or an emergency sync (SB_I_SKIP_SYNC). * All the super blocks will be iterated, including upper_sb. -* -* If this is a syncfs(2) call, then we do need to call -* sync_filesystem() on upper_sb, but enough if we do it when being -* called with wait == 1. */ -if (!wait) -return 0 ; - upper_sb =ovl_upper_mnt (ofs)->mnt_sb; -down_read (&upper_sb->s_umount); - ret =sync_filesystem (upper_sb); +if (wait) +wait_sb_inodes (upper_sb); +if (upper_sb->s_op->sync_fs) + upper_sb->s_op->sync_fs (upper_sb, wait); + ret =ovl_sync_upper_blockdev (upper_sb, wait);up_read (&upper_sb->s_umount);return ret;Signature · 1 line
2.27.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
---- 在 星期一, 2021-11-22 11:00:31 Chengguang Xu <[email protected]> 撰写 ----
Quoted 40 lines
From: Chengguang Xu <[email protected]>
Current syncfs(2) syscall on overlayfs just calls
sync_filesystem()onupper_sbto synchronize whole dirty inodes in upper filesystem regardless of the overlay ownership of the inode. In the use case of container, when multiple containers using the same underlying upper filesystem, it has some shortcomings as below.(1) Performance
Synchronization is probably heavy because it actually syncs unnecessary inodes for target overlayfs.(2) Interference
Unplanned synchronization will probably impact IO performance of unrelated container processes on the other overlayfs.This series try to implement containerized syncfs for overlayfs so that only sync target dirty upper inodes which are belong to specific overlayfs instance. By doing this, it is able to reduce cost of synchronization and will not seriously impact IO performance of unrelated processes.
v1->v2:
- Mark overlayfs' inode dirty itself instead of adding notification mechanism to vfs inode.
v2->v3:
- Introduce overlayfs' extra syncfs wait list to wait target upper inodes in ->sync_fs.
v3->v4:
- Usingwait_sb_inodes()to wait syncing upper inodes.
- Mark overlay inode dirty only when having upper inode andVM_SHAREDflag inovl_mmap().
- Check upperi_stateafter checking upper mmap state
inovl_write_inode.
v4->v5:
- Add underlying inode dirtiness check aftermnt_drop_write().
- Handle both wait/no-wait mode of syncfs(2) in overlayfs' ->sync_fs().
Quoted 7 lines
v5->v6:
- Rebase to latest overlayfs-next tree.
- Mark oerlay inode dirty when it has upper instead of marking dirty on modification.
- Trigger dirty page writeback in overlayfs' ->write_inode().
- Mark overlay inode 'DONTCACHE' flag.
- Delete overlayfs' ->writepages() and ->evict_inode() operations.
Hi Miklos,
Have you got time to have a look at this V6 series? I think this version has already fixed the issues in previous feedbacks of you guys and passed fstests (generic/overlay cases).
I did some stress long time tests (tar & syncfs & diff on w/wo copy-up) and found no obvious problem. For syncfs time with 1M clean upper inodes, there was extra 1.3s wasted on waiting scheduling. I guess this 1.3s will not bring significant impact to container instance in most cases, I also agree with Jack that we can start with this approach and do some improvements afterwards if there is complain from any real users.
Thanks,
Chengguang
Quoted 21 lines
Chengguang Xu (7):
ovl: setup overlayfs' private bdi
ovl: mark overlayfs inode dirty when it has upper
ovl: implement overlayfs' own ->write_inode operation
ovl: set 'DONTCACHE' flag for overlayfs inode
fs: exportwait_sb_inodes()
ovl: introduceovl_sync_upper_blockdev()
ovl: implement containerized syncfs for overlayfsfs/fs-writeback.c | 3 ++- fs/overlayfs/inode.c | 5 +++- fs/overlayfs/super.c | 49 ++++++++++++++++++++++++++++++++------- fs/overlayfs/util.c | 1 + include/linux/writeback.h | 1 + 5 files changed, 48 insertions(+), 11 deletions(-)Signature · 1 line
2.27.0