linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs
@ 2021-09-23 13:08 Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 01/10] ovl: setup overlayfs' private bdi Chengguang Xu
                   ` (9 more replies)
  0 siblings, 10 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

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().

Chengguang Xu (10):
  ovl: setup overlayfs' private bdi
  ovl: implement ->writepages operation
  ovl: implement overlayfs' ->evict_inode operation
  ovl: mark overlayfs' inode dirty on modification
  ovl: mark overlayfs' inode dirty on shared mmap
  ovl: implement overlayfs' ->write_inode operation
  ovl: cache dirty overlayfs' inode
  fs: export wait_sb_inodes()
  fs: introduce new helper sync_fs_and_blockdev()
  ovl: implement containerized syncfs for overlayfs

 fs/fs-writeback.c         |  3 +-
 fs/overlayfs/file.c       |  6 ++++
 fs/overlayfs/inode.c      | 14 ++++++++
 fs/overlayfs/overlayfs.h  |  4 +++
 fs/overlayfs/super.c      | 69 ++++++++++++++++++++++++++++++++++-----
 fs/overlayfs/util.c       | 21 ++++++++++++
 fs/sync.c                 | 14 +++++---
 include/linux/fs.h        |  1 +
 include/linux/writeback.h |  1 +
 9 files changed, 120 insertions(+), 13 deletions(-)

-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 01/10] ovl: setup overlayfs' private bdi
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 02/10] ovl: implement ->writepages operation Chengguang Xu
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Setup overlayfs' private bdi so that we can collect
overlayfs' own dirty inodes.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/super.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 178daa5e82c9..51886ba6130a 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -1980,6 +1980,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)
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 02/10] ovl: implement ->writepages operation
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 01/10] ovl: setup overlayfs' private bdi Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation Chengguang Xu
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Implement overlayfs' ->writepages operation so that
we can sync dirty data/metadata to upper filesystem.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/inode.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 832b17589733..d854e59a3710 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -659,9 +659,22 @@ static const struct inode_operations ovl_special_inode_operations = {
 	.update_time	= ovl_update_time,
 };
 
+static int ovl_writepages(struct address_space *mapping,
+			  struct writeback_control *wbc)
+{
+	struct inode *inode = mapping->host;
+	struct ovl_fs *ofs = inode->i_sb->s_fs_info;
+	struct inode *upper = ovl_inode_upper(inode);
+
+	if (!ovl_should_sync(ofs))
+		return 0;
+	return filemap_fdatawrite_wbc(upper->i_mapping, wbc);
+}
+
 static const struct address_space_operations ovl_aops = {
 	/* For O_DIRECT dentry_open() checks f_mapping->a_ops->direct_IO */
 	.direct_IO		= noop_direct_IO,
+	.writepages		= ovl_writepages,
 };
 
 /*
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 01/10] ovl: setup overlayfs' private bdi Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 02/10] ovl: implement ->writepages operation Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-10-06 15:33   ` Miklos Szeredi
  2021-09-23 13:08 ` [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification Chengguang Xu
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Implement overlayfs' ->evict_inode operation,
so that we can clear dirty flags of overlayfs inode.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/super.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 51886ba6130a..2ab77adf7256 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -406,11 +406,18 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
 	return ret;
 }
 
+static void ovl_evict_inode(struct inode *inode)
+{
+	inode->i_state &= ~I_DIRTY_ALL;
+	clear_inode(inode);
+}
+
 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,
+	.evict_inode	= ovl_evict_inode,
 	.put_super	= ovl_put_super,
 	.sync_fs	= ovl_sync_fs,
 	.statfs		= ovl_statfs,
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (2 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-10-07 18:43   ` Miklos Szeredi
  2021-09-23 13:08 ` [RFC PATCH v5 05/10] ovl: mark overlayfs' inode dirty on shared mmap Chengguang Xu
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Mark overlayfs' inode dirty on modification so that
we can recognize and collect target inodes for syncfs.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/inode.c     |  1 +
 fs/overlayfs/overlayfs.h |  4 ++++
 fs/overlayfs/util.c      | 21 +++++++++++++++++++++
 3 files changed, 26 insertions(+)

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index d854e59a3710..4a03aceaeedc 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -478,6 +478,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags)
 		if (upperpath.dentry) {
 			touch_atime(&upperpath);
 			inode->i_atime = d_inode(upperpath.dentry)->i_atime;
+			ovl_mark_inode_dirty(inode);
 		}
 	}
 	return 0;
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 3894f3347955..5a016baa06dd 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -276,6 +276,7 @@ static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs)
 
 
 /* util.c */
+void ovl_mark_inode_dirty(struct inode *inode);
 int ovl_want_write(struct dentry *dentry);
 void ovl_drop_write(struct dentry *dentry);
 struct dentry *ovl_workdir(struct dentry *dentry);
@@ -529,6 +530,9 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to)
 	to->i_mtime = from->i_mtime;
 	to->i_ctime = from->i_ctime;
 	i_size_write(to, i_size_read(from));
+
+	if (ovl_inode_upper(to) && from->i_state & I_DIRTY_ALL)
+		ovl_mark_inode_dirty(to);
 }
 
 /* vfs inode flags copied from real to ovl inode */
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index f48284a2a896..5441eae2e345 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -25,7 +25,14 @@ int ovl_want_write(struct dentry *dentry)
 void ovl_drop_write(struct dentry *dentry)
 {
 	struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
+	struct dentry *upper;
+
 	mnt_drop_write(ovl_upper_mnt(ofs));
+	if (d_inode(dentry)) {
+		upper = ovl_dentry_upper(dentry);
+		if (upper && d_inode(upper) && d_inode(upper)->i_state & I_DIRTY_ALL)
+			ovl_mark_inode_dirty(d_inode(dentry));
+	}
 }
 
 struct dentry *ovl_workdir(struct dentry *dentry)
@@ -1060,3 +1067,17 @@ int ovl_sync_status(struct ovl_fs *ofs)
 
 	return errseq_check(&mnt->mnt_sb->s_wb_err, ofs->errseq);
 }
+
+/*
+ * We intentionally add I_DIRTY_SYNC flag regardless dirty flag
+ * of upper inode so that we have chance to invoke ->write_inode
+ * to re-dirty overlayfs' inode during writeback process.
+ */
+void ovl_mark_inode_dirty(struct inode *inode)
+{
+	struct inode *upper = ovl_inode_upper(inode);
+	unsigned long iflag = I_DIRTY_SYNC;
+
+	iflag |= upper->i_state & I_DIRTY_ALL;
+	__mark_inode_dirty(inode, iflag);
+}
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 05/10] ovl: mark overlayfs' inode dirty on shared mmap
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (3 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Chengguang Xu
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Overlayfs cannot be notified when mmapped area gets dirty,
so we need to proactively mark inode dirty in ->mmap operation.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/file.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index d081faa55e83..f9dc5249c183 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -482,6 +482,12 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
 	revert_creds(old_cred);
 	ovl_file_accessed(file);
 
+	if (!ret) {
+		if (ovl_inode_upper(file_inode(file)) &&
+		    vma->vm_flags & VM_SHARED)
+			ovl_mark_inode_dirty(file_inode(file));
+	}
+
 	return ret;
 }
 
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (4 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 05/10] ovl: mark overlayfs' inode dirty on shared mmap Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-10-07  9:01   ` Jan Kara
  2021-10-07  9:23   ` Miklos Szeredi
  2021-09-23 13:08 ` [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode Chengguang Xu
                   ` (3 subsequent siblings)
  9 siblings, 2 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Implement overlayfs' ->write_inode to sync dirty data
and redirty overlayfs' inode if necessary.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 2ab77adf7256..cddae3ca2fa5 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode)
 	clear_inode(inode);
 }
 
+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 = ovl_inode_upper(inode);
+	unsigned long iflag = 0;
+	int ret = 0;
+
+	if (!upper)
+		return 0;
+
+	if (!ovl_should_sync(ofs))
+		return 0;
+
+	if (upper->i_sb->s_op->write_inode)
+		ret = upper->i_sb->s_op->write_inode(inode, wbc);
+
+	if (mapping_writably_mapped(upper->i_mapping) ||
+	    mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK))
+		iflag |= I_DIRTY_PAGES;
+
+	iflag |= upper->i_state & I_DIRTY_ALL;
+
+	if (iflag)
+		ovl_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,
 	.evict_inode	= ovl_evict_inode,
+	.write_inode	= ovl_write_inode,
 	.put_super	= ovl_put_super,
 	.sync_fs	= ovl_sync_fs,
 	.statfs		= ovl_statfs,
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (5 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-10-07 11:09   ` Miklos Szeredi
  2021-09-23 13:08 ` [RFC PATCH v5 08/10] fs: export wait_sb_inodes() Chengguang Xu
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Now drop overlayfs' inode will sync dirty data,
so we change to only drop clean inode.

The purpose of doing this is to keep compatible
behavior with before because without this change
dropping overlayfs inode will not trigger syncing
of underlying dirty inode.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/super.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index cddae3ca2fa5..bf4000eb9be8 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -441,11 +441,25 @@ static int ovl_write_inode(struct inode *inode,
 	return ret;
 }
 
+/*
+ * In iput_final(), clean inode will drop directly and dirty inode will
+ * keep in the cache until write back to sync dirty data then add to lru
+ * list to wait reclaim.
+ */
+static int ovl_drop_inode(struct inode *inode)
+{
+	struct inode *upper = ovl_inode_upper(inode);
+
+	if (!upper || !(inode->i_state & I_DIRTY_ALL))
+		return 1;
+	return generic_drop_inode(inode);
+}
+
 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,
+	.drop_inode	= ovl_drop_inode,
 	.evict_inode	= ovl_evict_inode,
 	.write_inode	= ovl_write_inode,
 	.put_super	= ovl_put_super,
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 08/10] fs: export wait_sb_inodes()
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (6 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 09/10] fs: introduce new helper sync_fs_and_blockdev() Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 10/10] ovl: implement containerized syncfs for overlayfs Chengguang Xu
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

In order to wait syncing upper inodes we need to
call wait_sb_inodes() in overlayfs' ->sync_fs.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/fs-writeback.c         | 3 ++-
 include/linux/writeback.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 81ec192ce067..0438c911241e 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -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)
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index d1f65adf6a26..d7aacd0434cf 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -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)
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 09/10] fs: introduce new helper sync_fs_and_blockdev()
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (7 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 08/10] fs: export wait_sb_inodes() Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  2021-09-23 13:08 ` [RFC PATCH v5 10/10] ovl: implement containerized syncfs for overlayfs Chengguang Xu
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Overlayfs needs to call upper layer's ->sync_fs
and __sync_blockdev() to sync metadata during syncfs(2).

Currently, __sync_blockdev() does not export to module
so introduce new helper sync_fs_and_blockdev() to wrap
those operations.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/sync.c          | 14 ++++++++++----
 include/linux/fs.h |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/sync.c b/fs/sync.c
index 1373a610dc78..36c755e6568a 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -21,6 +21,15 @@
 #define VALID_FLAGS (SYNC_FILE_RANGE_WAIT_BEFORE|SYNC_FILE_RANGE_WRITE| \
 			SYNC_FILE_RANGE_WAIT_AFTER)
 
+
+int sync_fs_and_blockdev(struct super_block *sb, int wait)
+{
+	if (sb->s_op->sync_fs)
+		sb->s_op->sync_fs(sb, wait);
+	return __sync_blockdev(sb->s_bdev, wait);
+}
+EXPORT_SYMBOL(sync_fs_and_blockdev);
+
 /*
  * Do the filesystem syncing work. For simple filesystems
  * writeback_inodes_sb(sb) just dirties buffers with inodes so we have to
@@ -34,10 +43,7 @@ static int __sync_filesystem(struct super_block *sb, int wait)
 		sync_inodes_sb(sb);
 	else
 		writeback_inodes_sb(sb, WB_REASON_SYNC);
-
-	if (sb->s_op->sync_fs)
-		sb->s_op->sync_fs(sb, wait);
-	return __sync_blockdev(sb->s_bdev, wait);
+	return sync_fs_and_blockdev(sb, wait);
 }
 
 /*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e7a633353fd2..e5ebf126281c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2777,6 +2777,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb)
 
 void emergency_thaw_all(void);
 extern int sync_filesystem(struct super_block *);
+extern int sync_fs_and_blockdev(struct super_block *sb, int wait);
 extern const struct file_operations def_blk_fops;
 extern const struct file_operations def_chr_fops;
 
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [RFC PATCH v5 10/10] ovl: implement containerized syncfs for overlayfs
  2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
                   ` (8 preceding siblings ...)
  2021-09-23 13:08 ` [RFC PATCH v5 09/10] fs: introduce new helper sync_fs_and_blockdev() Chengguang Xu
@ 2021-09-23 13:08 ` Chengguang Xu
  9 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-09-23 13:08 UTC (permalink / raw)
  To: miklos, jack, amir73il
  Cc: linux-fsdevel, linux-unionfs, linux-kernel, Chengguang Xu

Now overlayfs can sync proper dirty inodes during syncfs,
so remove unnecessary sync_filesystem() on upper file
system.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/super.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index bf4000eb9be8..ef998ada6cb9 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -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 <miklos@szeredi.hu>");
@@ -281,18 +282,15 @@ 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);
+
+	ret = sync_fs_and_blockdev(upper_sb, wait);
 	up_read(&upper_sb->s_umount);
 
 	return ret;
-- 
2.27.0



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation
  2021-09-23 13:08 ` [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation Chengguang Xu
@ 2021-10-06 15:33   ` Miklos Szeredi
  2021-10-07  6:08     ` Chengguang Xu
  0 siblings, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-06 15:33 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> Implement overlayfs' ->evict_inode operation,
> so that we can clear dirty flags of overlayfs inode.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
>  fs/overlayfs/super.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index 51886ba6130a..2ab77adf7256 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -406,11 +406,18 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
>         return ret;
>  }
>
> +static void ovl_evict_inode(struct inode *inode)
> +{
> +       inode->i_state &= ~I_DIRTY_ALL;
> +       clear_inode(inode);

clear_inode() should already clear the dirty flags; the default
eviction should work fine without having to define an ->evict_inode.
What am I missing?

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation
  2021-10-06 15:33   ` Miklos Szeredi
@ 2021-10-07  6:08     ` Chengguang Xu
  2021-10-07  7:43       ` Miklos Szeredi
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07  6:08 UTC (permalink / raw)
  To: Miklos Szeredi, Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

在 2021/10/6 23:33, Miklos Szeredi 写道:
> On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>> Implement overlayfs' ->evict_inode operation,
>> so that we can clear dirty flags of overlayfs inode.
>>
>> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
>> ---
>>   fs/overlayfs/super.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
>> index 51886ba6130a..2ab77adf7256 100644
>> --- a/fs/overlayfs/super.c
>> +++ b/fs/overlayfs/super.c
>> @@ -406,11 +406,18 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
>>          return ret;
>>   }
>>
>> +static void ovl_evict_inode(struct inode *inode)
>> +{
>> +       inode->i_state &= ~I_DIRTY_ALL;
>> +       clear_inode(inode);
> clear_inode() should already clear the dirty flags; the default
> eviction should work fine without having to define an ->evict_inode.
> What am I missing?

Yeah, you are right, we don't need overlayfs' own ->evict_inode anymore

because we wait all writeback upper inodes in overlayfs' ->sync_fs.


Thanks,

Chengguang



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation
  2021-10-07  6:08     ` Chengguang Xu
@ 2021-10-07  7:43       ` Miklos Szeredi
  0 siblings, 0 replies; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07  7:43 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Chengguang Xu, Jan Kara, Amir Goldstein, linux-fsdevel,
	overlayfs, linux-kernel

On Thu, 7 Oct 2021 at 08:08, Chengguang Xu <cgxu519@139.com> wrote:
>
> 在 2021/10/6 23:33, Miklos Szeredi 写道:
> > On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
> >> Implement overlayfs' ->evict_inode operation,
> >> so that we can clear dirty flags of overlayfs inode.
> >>
> >> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> >> ---
> >>   fs/overlayfs/super.c | 7 +++++++
> >>   1 file changed, 7 insertions(+)
> >>
> >> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> >> index 51886ba6130a..2ab77adf7256 100644
> >> --- a/fs/overlayfs/super.c
> >> +++ b/fs/overlayfs/super.c
> >> @@ -406,11 +406,18 @@ static int ovl_remount(struct super_block *sb, int *flags, char *data)
> >>          return ret;
> >>   }
> >>
> >> +static void ovl_evict_inode(struct inode *inode)
> >> +{
> >> +       inode->i_state &= ~I_DIRTY_ALL;
> >> +       clear_inode(inode);
> > clear_inode() should already clear the dirty flags; the default
> > eviction should work fine without having to define an ->evict_inode.
> > What am I missing?
>
> Yeah, you are right, we don't need overlayfs' own ->evict_inode anymore
>
> because we wait all writeback upper inodes in overlayfs' ->sync_fs.

Okay, I dropped this patch then.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-09-23 13:08 ` [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Chengguang Xu
@ 2021-10-07  9:01   ` Jan Kara
  2021-10-07 12:26     ` Chengguang Xu
  2021-10-07  9:23   ` Miklos Szeredi
  1 sibling, 1 reply; 31+ messages in thread
From: Jan Kara @ 2021-10-07  9:01 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: miklos, jack, amir73il, linux-fsdevel, linux-unionfs, linux-kernel

On Thu 23-09-21 21:08:10, Chengguang Xu wrote:
> Implement overlayfs' ->write_inode to sync dirty data
> and redirty overlayfs' inode if necessary.
> 
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>

...

> +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 = ovl_inode_upper(inode);
> +	unsigned long iflag = 0;
> +	int ret = 0;
> +
> +	if (!upper)
> +		return 0;
> +
> +	if (!ovl_should_sync(ofs))
> +		return 0;
> +
> +	if (upper->i_sb->s_op->write_inode)
> +		ret = upper->i_sb->s_op->write_inode(inode, wbc);
> +

I'm somewhat confused here. 'inode' is overlayfs inode AFAIU, so how is it
correct to pass it to ->write_inode function of upper filesystem? Shouldn't
you pass 'upper' there instead?

> +	if (mapping_writably_mapped(upper->i_mapping) ||
> +	    mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK))
> +		iflag |= I_DIRTY_PAGES;
> +
> +	iflag |= upper->i_state & I_DIRTY_ALL;

Also since you call ->write_inode directly upper->i_state won't be updated
to reflect that inode has been written out (I_DIRTY flags get cleared in
__writeback_single_inode()). So it seems to me overlayfs will keep writing
out upper inode until flush worker on upper filesystem also writes the
inode and clears the dirty flags? So you rather need to call something like
write_inode_now() that will handle the flag clearing and do writeback list
handling for you?

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-09-23 13:08 ` [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Chengguang Xu
  2021-10-07  9:01   ` Jan Kara
@ 2021-10-07  9:23   ` Miklos Szeredi
  2021-10-07 12:28     ` Chengguang Xu
  1 sibling, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07  9:23 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> Implement overlayfs' ->write_inode to sync dirty data
> and redirty overlayfs' inode if necessary.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
>  fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index 2ab77adf7256..cddae3ca2fa5 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode)
>         clear_inode(inode);
>  }
>
> +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 = ovl_inode_upper(inode);
> +       unsigned long iflag = 0;
> +       int ret = 0;
> +
> +       if (!upper)
> +               return 0;
> +
> +       if (!ovl_should_sync(ofs))
> +               return 0;
> +
> +       if (upper->i_sb->s_op->write_inode)
> +               ret = upper->i_sb->s_op->write_inode(inode, wbc);

Where is page writeback on upper inode triggered?

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode
  2021-09-23 13:08 ` [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode Chengguang Xu
@ 2021-10-07 11:09   ` Miklos Szeredi
  2021-10-07 12:04     ` Chengguang Xu
  0 siblings, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 11:09 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> Now drop overlayfs' inode will sync dirty data,
> so we change to only drop clean inode.
>
> The purpose of doing this is to keep compatible
> behavior with before because without this change
> dropping overlayfs inode will not trigger syncing
> of underlying dirty inode.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
>  fs/overlayfs/super.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> index cddae3ca2fa5..bf4000eb9be8 100644
> --- a/fs/overlayfs/super.c
> +++ b/fs/overlayfs/super.c
> @@ -441,11 +441,25 @@ static int ovl_write_inode(struct inode *inode,
>         return ret;
>  }
>
> +/*
> + * In iput_final(), clean inode will drop directly and dirty inode will
> + * keep in the cache until write back to sync dirty data then add to lru
> + * list to wait reclaim.
> + */
> +static int ovl_drop_inode(struct inode *inode)
> +{
> +       struct inode *upper = ovl_inode_upper(inode);
> +
> +       if (!upper || !(inode->i_state & I_DIRTY_ALL))

Could we check upper dirtyness here? That would give a more precise result.

Alternatively don't set .drop_inode (i.e. use generic_drop_inode())
and set I_DONTCACHE on overlay inodes.  That would cause the upper
inode to be always written back before eviction.

The latter would result in simpler logic, and I think performance-wise
it wouldn't matter.   But I may be missing something.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode
  2021-10-07 11:09   ` Miklos Szeredi
@ 2021-10-07 12:04     ` Chengguang Xu
  2021-10-07 12:27       ` Miklos Szeredi
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 12:04 UTC (permalink / raw)
  To: Miklos Szeredi, Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

在 2021/10/7 19:09, Miklos Szeredi 写道:
> On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>> Now drop overlayfs' inode will sync dirty data,
>> so we change to only drop clean inode.
>>
>> The purpose of doing this is to keep compatible
>> behavior with before because without this change
>> dropping overlayfs inode will not trigger syncing
>> of underlying dirty inode.
>>
>> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
>> ---
>>   fs/overlayfs/super.c | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
>> index cddae3ca2fa5..bf4000eb9be8 100644
>> --- a/fs/overlayfs/super.c
>> +++ b/fs/overlayfs/super.c
>> @@ -441,11 +441,25 @@ static int ovl_write_inode(struct inode *inode,
>>          return ret;
>>   }
>>
>> +/*
>> + * In iput_final(), clean inode will drop directly and dirty inode will
>> + * keep in the cache until write back to sync dirty data then add to lru
>> + * list to wait reclaim.
>> + */
>> +static int ovl_drop_inode(struct inode *inode)
>> +{
>> +       struct inode *upper = ovl_inode_upper(inode);
>> +
>> +       if (!upper || !(inode->i_state & I_DIRTY_ALL))
> Could we check upper dirtyness here? That would give a more precise result.

We keep tracking mmapped-file(shared mode) by explicitely marking 
overlay inode dirty,

so if we drop overlay inode by checking upper dirtyness, we may lose 
control on those mmapped upper inodes.

>
> Alternatively don't set .drop_inode (i.e. use generic_drop_inode())
> and set I_DONTCACHE on overlay inodes.  That would cause the upper
> inode to be always written back before eviction.
>
> The latter would result in simpler logic, and I think performance-wise
> it wouldn't matter.  But I may be missing something.

I think we may seperate mmapped-file(shared) inode and other inode by

clear/set I_DONTCACHE flag on overlay inode if you prefer this approach.


Thanks,

Chengguang






^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07  9:01   ` Jan Kara
@ 2021-10-07 12:26     ` Chengguang Xu
  2021-10-07 14:41       ` Jan Kara
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 12:26 UTC (permalink / raw)
  To: Jan Kara; +Cc: miklos, amir73il, linux-fsdevel, linux-unionfs, linux-kernel

 ---- 在 星期四, 2021-10-07 17:01:57 Jan Kara <jack@suse.cz> 撰写 ----
 > On Thu 23-09-21 21:08:10, Chengguang Xu wrote:
 > > Implement overlayfs' ->write_inode to sync dirty data
 > > and redirty overlayfs' inode if necessary.
 > > 
 > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
 > 
 > ...
 > 
 > > +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 = ovl_inode_upper(inode);
 > > +    unsigned long iflag = 0;
 > > +    int ret = 0;
 > > +
 > > +    if (!upper)
 > > +        return 0;
 > > +
 > > +    if (!ovl_should_sync(ofs))
 > > +        return 0;
 > > +
 > > +    if (upper->i_sb->s_op->write_inode)
 > > +        ret = upper->i_sb->s_op->write_inode(inode, wbc);
 > > +
 > 
 > I'm somewhat confused here. 'inode' is overlayfs inode AFAIU, so how is it
 > correct to pass it to ->write_inode function of upper filesystem? Shouldn't
 > you pass 'upper' there instead?

That's right!

 > 
 > > +    if (mapping_writably_mapped(upper->i_mapping) ||
 > > +        mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK))
 > > +        iflag |= I_DIRTY_PAGES;
 > > +
 > > +    iflag |= upper->i_state & I_DIRTY_ALL;
 > 
 > Also since you call ->write_inode directly upper->i_state won't be updated
 > to reflect that inode has been written out (I_DIRTY flags get cleared in
 > __writeback_single_inode()). So it seems to me overlayfs will keep writing
 > out upper inode until flush worker on upper filesystem also writes the
 > inode and clears the dirty flags? So you rather need to call something like
 > write_inode_now() that will handle the flag clearing and do writeback list
 > handling for you?
 > 

Calling ->write_inode directly upper->i_state won't be updated, 
however, I don't think overlayfs will keep writing out upper inode since ->write_inode
will be called when only overlay inode itself marked dirty.  Am I missing something?


Thanks,
Chengguang



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode
  2021-10-07 12:04     ` Chengguang Xu
@ 2021-10-07 12:27       ` Miklos Szeredi
  0 siblings, 0 replies; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 12:27 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Chengguang Xu, Jan Kara, Amir Goldstein, linux-fsdevel,
	overlayfs, linux-kernel

On Thu, 7 Oct 2021 at 14:04, Chengguang Xu <cgxu519@139.com> wrote:
>
> 在 2021/10/7 19:09, Miklos Szeredi 写道:
> > On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
> >> Now drop overlayfs' inode will sync dirty data,
> >> so we change to only drop clean inode.
> >>
> >> The purpose of doing this is to keep compatible
> >> behavior with before because without this change
> >> dropping overlayfs inode will not trigger syncing
> >> of underlying dirty inode.
> >>
> >> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> >> ---
> >>   fs/overlayfs/super.c | 16 +++++++++++++++-
> >>   1 file changed, 15 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
> >> index cddae3ca2fa5..bf4000eb9be8 100644
> >> --- a/fs/overlayfs/super.c
> >> +++ b/fs/overlayfs/super.c
> >> @@ -441,11 +441,25 @@ static int ovl_write_inode(struct inode *inode,
> >>          return ret;
> >>   }
> >>
> >> +/*
> >> + * In iput_final(), clean inode will drop directly and dirty inode will
> >> + * keep in the cache until write back to sync dirty data then add to lru
> >> + * list to wait reclaim.
> >> + */
> >> +static int ovl_drop_inode(struct inode *inode)
> >> +{
> >> +       struct inode *upper = ovl_inode_upper(inode);
> >> +
> >> +       if (!upper || !(inode->i_state & I_DIRTY_ALL))
> > Could we check upper dirtyness here? That would give a more precise result.
>
> We keep tracking mmapped-file(shared mode) by explicitely marking
> overlay inode dirty,
>
> so if we drop overlay inode by checking upper dirtyness, we may lose
> control on those mmapped upper inodes.

That's fine, since there are no more mmaps at this point.

> >
> > Alternatively don't set .drop_inode (i.e. use generic_drop_inode())
> > and set I_DONTCACHE on overlay inodes.  That would cause the upper
> > inode to be always written back before eviction.
> >
> > The latter would result in simpler logic, and I think performance-wise
> > it wouldn't matter.  But I may be missing something.
>
> I think we may seperate mmapped-file(shared) inode and other inode by
>
> clear/set I_DONTCACHE flag on overlay inode if you prefer this approach.

Same reasoning here: after upper inode is written out, the dirtyness
in the overlay inode doesn't matter since there cannot be any active
mmaps.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07  9:23   ` Miklos Szeredi
@ 2021-10-07 12:28     ` Chengguang Xu
  2021-10-07 12:45       ` Miklos Szeredi
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 12:28 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

 ---- 在 星期四, 2021-10-07 17:23:06 Miklos Szeredi <miklos@szeredi.hu> 撰写 ----
 > On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
 > >
 > > Implement overlayfs' ->write_inode to sync dirty data
 > > and redirty overlayfs' inode if necessary.
 > >
 > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
 > > ---
 > >  fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++
 > >  1 file changed, 30 insertions(+)
 > >
 > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
 > > index 2ab77adf7256..cddae3ca2fa5 100644
 > > --- a/fs/overlayfs/super.c
 > > +++ b/fs/overlayfs/super.c
 > > @@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode)
 > >         clear_inode(inode);
 > >  }
 > >
 > > +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 = ovl_inode_upper(inode);
 > > +       unsigned long iflag = 0;
 > > +       int ret = 0;
 > > +
 > > +       if (!upper)
 > > +               return 0;
 > > +
 > > +       if (!ovl_should_sync(ofs))
 > > +               return 0;
 > > +
 > > +       if (upper->i_sb->s_op->write_inode)
 > > +               ret = upper->i_sb->s_op->write_inode(inode, wbc);
 > 
 > Where is page writeback on upper inode triggered?
 > 

Should pass upper inode instead of overlay inode here.

Thanks,
Chengguang



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 12:28     ` Chengguang Xu
@ 2021-10-07 12:45       ` Miklos Szeredi
  2021-10-07 13:09         ` Chengguang Xu
  0 siblings, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 12:45 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 7 Oct 2021 at 14:28, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
>  ---- 在 星期四, 2021-10-07 17:23:06 Miklos Szeredi <miklos@szeredi.hu> 撰写 ----
>  > On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>  > >
>  > > Implement overlayfs' ->write_inode to sync dirty data
>  > > and redirty overlayfs' inode if necessary.
>  > >
>  > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
>  > > ---
>  > >  fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++
>  > >  1 file changed, 30 insertions(+)
>  > >
>  > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
>  > > index 2ab77adf7256..cddae3ca2fa5 100644
>  > > --- a/fs/overlayfs/super.c
>  > > +++ b/fs/overlayfs/super.c
>  > > @@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode)
>  > >         clear_inode(inode);
>  > >  }
>  > >
>  > > +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 = ovl_inode_upper(inode);
>  > > +       unsigned long iflag = 0;
>  > > +       int ret = 0;
>  > > +
>  > > +       if (!upper)
>  > > +               return 0;
>  > > +
>  > > +       if (!ovl_should_sync(ofs))
>  > > +               return 0;
>  > > +
>  > > +       if (upper->i_sb->s_op->write_inode)
>  > > +               ret = upper->i_sb->s_op->write_inode(inode, wbc);
>  >
>  > Where is page writeback on upper inode triggered?
>  >
>
> Should pass upper inode instead of overlay inode here.

That's true and it does seem to indicate lack of thorough testing.

However that wasn't what I was asking about.  AFAICS ->write_inode()
won't start write back for dirty pages.   Maybe I'm missing something,
but there it looks as if nothing will actually trigger writeback for
dirty pages in upper inode.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 12:45       ` Miklos Szeredi
@ 2021-10-07 13:09         ` Chengguang Xu
  2021-10-07 13:34           ` Miklos Szeredi
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 13:09 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

 ---- 在 星期四, 2021-10-07 20:45:20 Miklos Szeredi <miklos@szeredi.hu> 撰写 ----
 > On Thu, 7 Oct 2021 at 14:28, Chengguang Xu <cgxu519@mykernel.net> wrote:
 > >
 > >  ---- 在 星期四, 2021-10-07 17:23:06 Miklos Szeredi <miklos@szeredi.hu> 撰写 ----
 > >  > On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
 > >  > >
 > >  > > Implement overlayfs' ->write_inode to sync dirty data
 > >  > > and redirty overlayfs' inode if necessary.
 > >  > >
 > >  > > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
 > >  > > ---
 > >  > >  fs/overlayfs/super.c | 30 ++++++++++++++++++++++++++++++
 > >  > >  1 file changed, 30 insertions(+)
 > >  > >
 > >  > > diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
 > >  > > index 2ab77adf7256..cddae3ca2fa5 100644
 > >  > > --- a/fs/overlayfs/super.c
 > >  > > +++ b/fs/overlayfs/super.c
 > >  > > @@ -412,12 +412,42 @@ static void ovl_evict_inode(struct inode *inode)
 > >  > >         clear_inode(inode);
 > >  > >  }
 > >  > >
 > >  > > +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 = ovl_inode_upper(inode);
 > >  > > +       unsigned long iflag = 0;
 > >  > > +       int ret = 0;
 > >  > > +
 > >  > > +       if (!upper)
 > >  > > +               return 0;
 > >  > > +
 > >  > > +       if (!ovl_should_sync(ofs))
 > >  > > +               return 0;
 > >  > > +
 > >  > > +       if (upper->i_sb->s_op->write_inode)
 > >  > > +               ret = upper->i_sb->s_op->write_inode(inode, wbc);
 > >  >
 > >  > Where is page writeback on upper inode triggered?
 > >  >
 > >
 > > Should pass upper inode instead of overlay inode here.
 > 
 > That's true and it does seem to indicate lack of thorough testing.

It's a little bit weird this passed all overlay cases and generic/474(syncfs) without errors in xfstests.
Please let me do more diagnosis on this and strengthen the test case.


 > 
 > However that wasn't what I was asking about.  AFAICS ->write_inode()
 > won't start write back for dirty pages.   Maybe I'm missing something,
 > but there it looks as if nothing will actually trigger writeback for
 > dirty pages in upper inode.
 > 

Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).

Thanks,
Chengguang




^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 13:09         ` Chengguang Xu
@ 2021-10-07 13:34           ` Miklos Szeredi
  2021-10-07 14:46             ` Jan Kara
  0 siblings, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 13:34 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 7 Oct 2021 at 15:10, Chengguang Xu <cgxu519@mykernel.net> wrote:
>  > However that wasn't what I was asking about.  AFAICS ->write_inode()
>  > won't start write back for dirty pages.   Maybe I'm missing something,
>  > but there it looks as if nothing will actually trigger writeback for
>  > dirty pages in upper inode.
>  >
>
> Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
> overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).

Right.

But wouldn't it be simpler to do this from ->write_inode()?

I.e. call write_inode_now() as suggested by Jan.

Also could just call mark_inode_dirty() on the overlay inode
regardless of the dirty flags on the upper inode since it shouldn't
matter and results in simpler logic.

Thanks,
Miklos


>
> Thanks,
> Chengguang
>
>
>

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 12:26     ` Chengguang Xu
@ 2021-10-07 14:41       ` Jan Kara
  2021-10-07 14:54         ` Chengguang Xu
  0 siblings, 1 reply; 31+ messages in thread
From: Jan Kara @ 2021-10-07 14:41 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, miklos, amir73il, linux-fsdevel, linux-unionfs, linux-kernel

On Thu 07-10-21 20:26:36, Chengguang Xu wrote:
>  ---- 在 星期四, 2021-10-07 17:01:57 Jan Kara <jack@suse.cz> 撰写 ----
>  > 
>  > > +    if (mapping_writably_mapped(upper->i_mapping) ||
>  > > +        mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK))
>  > > +        iflag |= I_DIRTY_PAGES;
>  > > +
>  > > +    iflag |= upper->i_state & I_DIRTY_ALL;
>  > 
>  > Also since you call ->write_inode directly upper->i_state won't be updated
>  > to reflect that inode has been written out (I_DIRTY flags get cleared in
>  > __writeback_single_inode()). So it seems to me overlayfs will keep writing
>  > out upper inode until flush worker on upper filesystem also writes the
>  > inode and clears the dirty flags? So you rather need to call something like
>  > write_inode_now() that will handle the flag clearing and do writeback list
>  > handling for you?
>  > 
> 
> Calling ->write_inode directly upper->i_state won't be updated, however,
> I don't think overlayfs will keep writing out upper inode since
> ->write_inode will be called when only overlay inode itself marked dirty.
> Am I missing something?

Well, if upper->i_state is not updated, you are more or less guaranteed
upper->i_state & I_DIRTY_ALL != 0 and thus even overlay inode stays dirty.
And thus next time writeback runs you will see dirty overlay inode and
writeback the upper inode again although it is not necessary.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 13:34           ` Miklos Szeredi
@ 2021-10-07 14:46             ` Jan Kara
  2021-10-07 14:53               ` Chengguang Xu
  0 siblings, 1 reply; 31+ messages in thread
From: Jan Kara @ 2021-10-07 14:46 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Chengguang Xu, Jan Kara, Amir Goldstein, linux-fsdevel,
	overlayfs, linux-kernel

On Thu 07-10-21 15:34:19, Miklos Szeredi wrote:
> On Thu, 7 Oct 2021 at 15:10, Chengguang Xu <cgxu519@mykernel.net> wrote:
> >  > However that wasn't what I was asking about.  AFAICS ->write_inode()
> >  > won't start write back for dirty pages.   Maybe I'm missing something,
> >  > but there it looks as if nothing will actually trigger writeback for
> >  > dirty pages in upper inode.
> >  >
> >
> > Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
> > overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).
> 
> Right.
> 
> But wouldn't it be simpler to do this from ->write_inode()?

You could but then you'd have to make sure you have I_DIRTY_SYNC always set
when I_DIRTY_PAGES is set on the upper inode so that your ->write_inode()
callback gets called. Overall I agree the logic would be probably simpler.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 14:46             ` Jan Kara
@ 2021-10-07 14:53               ` Chengguang Xu
  2021-10-07 18:51                 ` Miklos Szeredi
  0 siblings, 1 reply; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 14:53 UTC (permalink / raw)
  To: Jan Kara, Miklos Szeredi
  Cc: Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

 ---- 在 星期四, 2021-10-07 22:46:46 Jan Kara <jack@suse.cz> 撰写 ----
 > On Thu 07-10-21 15:34:19, Miklos Szeredi wrote:
 > > On Thu, 7 Oct 2021 at 15:10, Chengguang Xu <cgxu519@mykernel.net> wrote:
 > > >  > However that wasn't what I was asking about.  AFAICS ->write_inode()
 > > >  > won't start write back for dirty pages.   Maybe I'm missing something,
 > > >  > but there it looks as if nothing will actually trigger writeback for
 > > >  > dirty pages in upper inode.
 > > >  >
 > > >
 > > > Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
 > > > overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).
 > > 
 > > Right.
 > > 
 > > But wouldn't it be simpler to do this from ->write_inode()?
 > 
 > You could but then you'd have to make sure you have I_DIRTY_SYNC always set
 > when I_DIRTY_PAGES is set on the upper inode so that your ->write_inode()
 > callback gets called. Overall I agree the logic would be probably simpler.
 > 

Hi Jan, Miklos

Thnaks for your suggestions. Let me have a try in next version.


Thanks,
Chengguang

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 14:41       ` Jan Kara
@ 2021-10-07 14:54         ` Chengguang Xu
  0 siblings, 0 replies; 31+ messages in thread
From: Chengguang Xu @ 2021-10-07 14:54 UTC (permalink / raw)
  To: Jan Kara; +Cc: miklos, amir73il, linux-fsdevel, linux-unionfs, linux-kernel


 ---- 在 星期四, 2021-10-07 22:41:56 Jan Kara <jack@suse.cz> 撰写 ----
 > On Thu 07-10-21 20:26:36, Chengguang Xu wrote:
 > >  ---- 在 星期四, 2021-10-07 17:01:57 Jan Kara <jack@suse.cz> 撰写 ----
 > >  > 
 > >  > > +    if (mapping_writably_mapped(upper->i_mapping) ||
 > >  > > +        mapping_tagged(upper->i_mapping, PAGECACHE_TAG_WRITEBACK))
 > >  > > +        iflag |= I_DIRTY_PAGES;
 > >  > > +
 > >  > > +    iflag |= upper->i_state & I_DIRTY_ALL;
 > >  > 
 > >  > Also since you call ->write_inode directly upper->i_state won't be updated
 > >  > to reflect that inode has been written out (I_DIRTY flags get cleared in
 > >  > __writeback_single_inode()). So it seems to me overlayfs will keep writing
 > >  > out upper inode until flush worker on upper filesystem also writes the
 > >  > inode and clears the dirty flags? So you rather need to call something like
 > >  > write_inode_now() that will handle the flag clearing and do writeback list
 > >  > handling for you?
 > >  > 
 > > 
 > > Calling ->write_inode directly upper->i_state won't be updated, however,
 > > I don't think overlayfs will keep writing out upper inode since
 > > ->write_inode will be called when only overlay inode itself marked dirty.
 > > Am I missing something?
 > 
 > Well, if upper->i_state is not updated, you are more or less guaranteed
 > upper->i_state & I_DIRTY_ALL != 0 and thus even overlay inode stays dirty.
 > And thus next time writeback runs you will see dirty overlay inode and
 > writeback the upper inode again although it is not necessary.
 > 

Hi Jan,

Yes, I get the point now. Thanks for the explanation.


Thanks,
Chengguang





^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification
  2021-09-23 13:08 ` [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification Chengguang Xu
@ 2021-10-07 18:43   ` Miklos Szeredi
  0 siblings, 0 replies; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 18:43 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 23 Sept 2021 at 15:08, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> Mark overlayfs' inode dirty on modification so that
> we can recognize and collect target inodes for syncfs.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
>  fs/overlayfs/inode.c     |  1 +
>  fs/overlayfs/overlayfs.h |  4 ++++
>  fs/overlayfs/util.c      | 21 +++++++++++++++++++++
>  3 files changed, 26 insertions(+)
>
> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> index d854e59a3710..4a03aceaeedc 100644
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -478,6 +478,7 @@ int ovl_update_time(struct inode *inode, struct timespec64 *ts, int flags)
>                 if (upperpath.dentry) {
>                         touch_atime(&upperpath);
>                         inode->i_atime = d_inode(upperpath.dentry)->i_atime;
> +                       ovl_mark_inode_dirty(inode);
>                 }
>         }
>         return 0;
> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
> index 3894f3347955..5a016baa06dd 100644
> --- a/fs/overlayfs/overlayfs.h
> +++ b/fs/overlayfs/overlayfs.h
> @@ -276,6 +276,7 @@ static inline bool ovl_allow_offline_changes(struct ovl_fs *ofs)
>
>
>  /* util.c */
> +void ovl_mark_inode_dirty(struct inode *inode);
>  int ovl_want_write(struct dentry *dentry);
>  void ovl_drop_write(struct dentry *dentry);
>  struct dentry *ovl_workdir(struct dentry *dentry);
> @@ -529,6 +530,9 @@ static inline void ovl_copyattr(struct inode *from, struct inode *to)
>         to->i_mtime = from->i_mtime;
>         to->i_ctime = from->i_ctime;
>         i_size_write(to, i_size_read(from));
> +
> +       if (ovl_inode_upper(to) && from->i_state & I_DIRTY_ALL)
> +               ovl_mark_inode_dirty(to);

I'd be more comfortable with calling ovl_mark_inode_dirty() unconditionally.

Checking if there's an upper seems to make no sense, since we should
only be copying the attributes if something was changed, and then it
is an upper inode.

Checking dirty flags on upper inode actually makes this racy:

  - upper inode dirtied through overlayfs
  - inode writeback starts (e.g. background writeback) on upper inode
  - dirty flags are cleared
  - check for dirty flags in upper inode above indicates not dirty,
ovl inode not dirtied
  - syncfs called, misses this inode
  - inode writeback completed after syncfs

>  }
>
>  /* vfs inode flags copied from real to ovl inode */
> diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
> index f48284a2a896..5441eae2e345 100644
> --- a/fs/overlayfs/util.c
> +++ b/fs/overlayfs/util.c
> @@ -25,7 +25,14 @@ int ovl_want_write(struct dentry *dentry)
>  void ovl_drop_write(struct dentry *dentry)
>  {
>         struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
> +       struct dentry *upper;
> +
>         mnt_drop_write(ovl_upper_mnt(ofs));
> +       if (d_inode(dentry)) {
> +               upper = ovl_dentry_upper(dentry);
> +               if (upper && d_inode(upper) && d_inode(upper)->i_state & I_DIRTY_ALL)
> +                       ovl_mark_inode_dirty(d_inode(dentry));

ovl_want_write/ovl_drop_write means modification of the upper
filesystem.  It may or may not be the given dentry, so this is not the
right place to clall ovl_mark_inode_dirty IMO.  Better check all
instances of these and see if there are cases where ovl_copyattr()
doesn't handle inode dirtying, and do it explicitly there.


> +       }
>  }
>
>  struct dentry *ovl_workdir(struct dentry *dentry)
> @@ -1060,3 +1067,17 @@ int ovl_sync_status(struct ovl_fs *ofs)
>
>         return errseq_check(&mnt->mnt_sb->s_wb_err, ofs->errseq);
>  }
> +
> +/*
> + * We intentionally add I_DIRTY_SYNC flag regardless dirty flag
> + * of upper inode so that we have chance to invoke ->write_inode
> + * to re-dirty overlayfs' inode during writeback process.
> + */
> +void ovl_mark_inode_dirty(struct inode *inode)
> +{
> +       struct inode *upper = ovl_inode_upper(inode);
> +       unsigned long iflag = I_DIRTY_SYNC;
> +
> +       iflag |= upper->i_state & I_DIRTY_ALL;
> +       __mark_inode_dirty(inode, iflag);
> +}

I think ovl_mark_inode_dirty()  can just call mark_inode_dirty().
And so that can go in "overlayfs.h" file as static inline.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 14:53               ` Chengguang Xu
@ 2021-10-07 18:51                 ` Miklos Szeredi
  2021-10-08 13:13                   ` Jan Kara
  0 siblings, 1 reply; 31+ messages in thread
From: Miklos Szeredi @ 2021-10-07 18:51 UTC (permalink / raw)
  To: Chengguang Xu
  Cc: Jan Kara, Amir Goldstein, linux-fsdevel, overlayfs, linux-kernel

On Thu, 7 Oct 2021 at 16:53, Chengguang Xu <cgxu519@mykernel.net> wrote:
>
>  ---- 在 星期四, 2021-10-07 22:46:46 Jan Kara <jack@suse.cz> 撰写 ----
>  > On Thu 07-10-21 15:34:19, Miklos Szeredi wrote:
>  > > On Thu, 7 Oct 2021 at 15:10, Chengguang Xu <cgxu519@mykernel.net> wrote:
>  > > >  > However that wasn't what I was asking about.  AFAICS ->write_inode()
>  > > >  > won't start write back for dirty pages.   Maybe I'm missing something,
>  > > >  > but there it looks as if nothing will actually trigger writeback for
>  > > >  > dirty pages in upper inode.
>  > > >  >
>  > > >
>  > > > Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
>  > > > overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).
>  > >
>  > > Right.
>  > >
>  > > But wouldn't it be simpler to do this from ->write_inode()?
>  >
>  > You could but then you'd have to make sure you have I_DIRTY_SYNC always set
>  > when I_DIRTY_PAGES is set on the upper inode so that your ->write_inode()
>  > callback gets called. Overall I agree the logic would be probably simpler.
>  >
>

And it's not just for simplicity.  The I_SYNC logic in
writeback_single_inode() is actually necessary to prevent races
between instances on a specific inode.  I.e. if inode writeback is
started by background wb then syncfs needs to synchronize with that
otherwise it will miss the inode, or worse, mess things up by calling
->write_inode() multiple times in parallel.  So going throught
writeback_single_inode() is actually a must AFAICS.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation
  2021-10-07 18:51                 ` Miklos Szeredi
@ 2021-10-08 13:13                   ` Jan Kara
  0 siblings, 0 replies; 31+ messages in thread
From: Jan Kara @ 2021-10-08 13:13 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: Chengguang Xu, Jan Kara, Amir Goldstein, linux-fsdevel,
	overlayfs, linux-kernel

On Thu 07-10-21 20:51:47, Miklos Szeredi wrote:
> On Thu, 7 Oct 2021 at 16:53, Chengguang Xu <cgxu519@mykernel.net> wrote:
> >
> >  ---- 在 星期四, 2021-10-07 22:46:46 Jan Kara <jack@suse.cz> 撰写 ----
> >  > On Thu 07-10-21 15:34:19, Miklos Szeredi wrote:
> >  > > On Thu, 7 Oct 2021 at 15:10, Chengguang Xu <cgxu519@mykernel.net> wrote:
> >  > > >  > However that wasn't what I was asking about.  AFAICS ->write_inode()
> >  > > >  > won't start write back for dirty pages.   Maybe I'm missing something,
> >  > > >  > but there it looks as if nothing will actually trigger writeback for
> >  > > >  > dirty pages in upper inode.
> >  > > >  >
> >  > > >
> >  > > > Actually, page writeback on upper inode will be triggered by overlayfs ->writepages and
> >  > > > overlayfs' ->writepages will be called by vfs writeback function (i.e writeback_sb_inodes).
> >  > >
> >  > > Right.
> >  > >
> >  > > But wouldn't it be simpler to do this from ->write_inode()?
> >  >
> >  > You could but then you'd have to make sure you have I_DIRTY_SYNC always set
> >  > when I_DIRTY_PAGES is set on the upper inode so that your ->write_inode()
> >  > callback gets called. Overall I agree the logic would be probably simpler.
> >  >
> >
> 
> And it's not just for simplicity.  The I_SYNC logic in
> writeback_single_inode() is actually necessary to prevent races
> between instances on a specific inode.  I.e. if inode writeback is
> started by background wb then syncfs needs to synchronize with that
> otherwise it will miss the inode, or worse, mess things up by calling
> ->write_inode() multiple times in parallel.  So going throught
> writeback_single_inode() is actually a must AFAICS.

Yes, you are correct.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-10-08 13:13 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 13:08 [RFC PATCH v5 00/10] implement containerized syncfs for overlayfs Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 01/10] ovl: setup overlayfs' private bdi Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 02/10] ovl: implement ->writepages operation Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 03/10] ovl: implement overlayfs' ->evict_inode operation Chengguang Xu
2021-10-06 15:33   ` Miklos Szeredi
2021-10-07  6:08     ` Chengguang Xu
2021-10-07  7:43       ` Miklos Szeredi
2021-09-23 13:08 ` [RFC PATCH v5 04/10] ovl: mark overlayfs' inode dirty on modification Chengguang Xu
2021-10-07 18:43   ` Miklos Szeredi
2021-09-23 13:08 ` [RFC PATCH v5 05/10] ovl: mark overlayfs' inode dirty on shared mmap Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 06/10] ovl: implement overlayfs' ->write_inode operation Chengguang Xu
2021-10-07  9:01   ` Jan Kara
2021-10-07 12:26     ` Chengguang Xu
2021-10-07 14:41       ` Jan Kara
2021-10-07 14:54         ` Chengguang Xu
2021-10-07  9:23   ` Miklos Szeredi
2021-10-07 12:28     ` Chengguang Xu
2021-10-07 12:45       ` Miklos Szeredi
2021-10-07 13:09         ` Chengguang Xu
2021-10-07 13:34           ` Miklos Szeredi
2021-10-07 14:46             ` Jan Kara
2021-10-07 14:53               ` Chengguang Xu
2021-10-07 18:51                 ` Miklos Szeredi
2021-10-08 13:13                   ` Jan Kara
2021-09-23 13:08 ` [RFC PATCH v5 07/10] ovl: cache dirty overlayfs' inode Chengguang Xu
2021-10-07 11:09   ` Miklos Szeredi
2021-10-07 12:04     ` Chengguang Xu
2021-10-07 12:27       ` Miklos Szeredi
2021-09-23 13:08 ` [RFC PATCH v5 08/10] fs: export wait_sb_inodes() Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 09/10] fs: introduce new helper sync_fs_and_blockdev() Chengguang Xu
2021-09-23 13:08 ` [RFC PATCH v5 10/10] ovl: implement containerized syncfs for overlayfs Chengguang Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).