linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* lazytime causing inodes to remain dirty after sync?
@ 2020-03-06  0:45 Eric Biggers
  2020-03-07  2:00 ` [PATCH] writeback: avoid double-writing the inode on a lazytime expiration Theodore Ts'o
  0 siblings, 1 reply; 17+ messages in thread
From: Eric Biggers @ 2020-03-06  0:45 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: linux-ext4, linux-f2fs-devel

While testing my patch "fscrypt: don't evict dirty inodes after removing key"
(https://lkml.kernel.org/r/20200305084138.653498-1-ebiggers@kernel.org), I've
run into an issue where even after the filesystem is sync'ed and no files are
in-use, inodes can remain dirty if the filesystem is mounted with -o lazytime.
Thus, my patch causes some inodes to not be evicted when they should be.

(lazytime is the default on f2fs, but ext4 supports it too.)

This is caused by the following code in __writeback_single_inode() that
redirties the inode if its access time is dirty:

	if (dirty & I_DIRTY_TIME)
		mark_inode_dirty_sync(inode);
	/* Don't write the inode if only I_DIRTY_PAGES was set */
	if (dirty & ~I_DIRTY_PAGES) {
		int err = write_inode(inode, wbc);
		if (ret == 0)
			ret = err;
	}
	trace_writeback_single_inode(inode, wbc, nr_to_write);
	return ret;

Here's a reproducer in the kvm-xfstests test appliance which demonstrates the
problem using sync(), without fscrypt involved at all:

	sysctl vm.dirty_expire_centisecs=500
	umount /vdc
	mkfs.ext4 -F /dev/vdc
	mount /vdc -o lazytime
	echo contents > /vdc/file
	sync
	ino=$(stat -c %i /vdc/file)
	echo 1 | tee /sys/kernel/debug/tracing/events/writeback/writeback_{single_inode_start,mark_inode_dirty,lazytime}/enable
	echo "ino == $ino" | tee /sys/kernel/debug/tracing/events/writeback/writeback_{single_inode_start,mark_inode_dirty,lazytime}/filter
	echo > /sys/kernel/debug/tracing/trace
	cat /vdc/file > /dev/null
	sync
	cat /sys/kernel/debug/tracing/trace_pipe

The tracing shows that the inode for /vdc/file is written during the sync at
7.28s.  But then, still during the sync, it's immediately re-dirtied.  It then
gets written again later in the background, after the sync.

             cat-286   [001] ...1     7.279433: writeback_mark_inode_dirty: bdi 254:32: ino=12 state= flags=I_DIRTY_TIME
    kworker/u8:0-8     [003] ...1     7.282647: writeback_single_inode_start: bdi 254:32: ino=12 state=I_SYNC|I_DIRTY_TIME|I_DIRTY_TIME_EXPIRED dirtied_when=4294879420 age=0 index=1 to_write=9223372036854775807 wrote=0 cgroup_ino=1
    kworker/u8:0-8     [003] ...2     7.282660: writeback_lazytime: dev 254,32 ino 12 dirtied 4294879420 state I_SYNC|I_DIRTY_TIME|I_DIRTY_TIME_EXPIRED mode 0100644
    kworker/u8:0-8     [003] ...1     7.283204: writeback_mark_inode_dirty: bdi 254:32: ino=12 state=I_SYNC flags=I_DIRTY_SYNC
    kworker/u8:0-8     [003] ...1    12.412079: writeback_single_inode_start: bdi 254:32: ino=12 state=I_DIRTY_SYNC|I_SYNC dirtied_when=4294879421 age=5 index=1 to_write=13312 wrote=0 cgroup_ino=1

Is this behavior intentional at all?  It seems like a bug; it seems the inode
should be written just once, during the sync.  

- Eric

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

end of thread, other threads:[~2020-03-25 15:48 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-06  0:45 lazytime causing inodes to remain dirty after sync? Eric Biggers
2020-03-07  2:00 ` [PATCH] writeback: avoid double-writing the inode on a lazytime expiration Theodore Ts'o
2020-03-11  3:20   ` Eric Biggers
2020-03-11 12:57     ` Theodore Y. Ts'o
2020-03-12  0:07       ` Dave Chinner
2020-03-12 14:34         ` Christoph Hellwig
2020-03-12 22:39           ` Dave Chinner
2020-03-20  2:46           ` Theodore Y. Ts'o
2020-03-20  2:52             ` [PATCH 1/2] " Theodore Ts'o
2020-03-20  2:52               ` [PATCH 2/2] writeback, xfs: call dirty_inode() with I_DIRTY_TIME_EXPIRED when appropriate Theodore Ts'o
2020-03-23 17:58                 ` Theodore Y. Ts'o
2020-03-24  8:37                   ` Christoph Hellwig
2020-03-24 18:43                     ` Theodore Y. Ts'o
2020-03-25  9:20               ` [PATCH 1/2] writeback: avoid double-writing the inode on a lazytime expiration Christoph Hellwig
2020-03-25 15:21                 ` Theodore Y. Ts'o
2020-03-25 15:47                   ` Darrick J. Wong
2020-03-11 23:54     ` [PATCH] " Dave Chinner

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