History

fs: factor out a sync_lazytime helper

Centralize how we synchronize a lazytime update into the actual on-disk timestamp into a single helper.

Christoph Hellwig committed 10 months ago

Commit 188344c1 parent 76147525 files · +20 −20Browse files

Unified · Split

5 files
  1. fs/fs-writeback.c +15 −7
  2. fs/inode.c +1 −4
  3. fs/internal.h +2 −1
  4. fs/sync.c +2 −2
  5. include/trace/events/writeback.h +0 −6
fs/fs-writeback.c+15−7
@@ -1711,6 +1711,16 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb, · 1710 unmodified lines
17111711 }
17121712 }
17131713
1714+bool sync_lazytime(struct inode *inode)
1715+{
1716+ if (!(inode_state_read_once(inode) & I_DIRTY_TIME))
1717+ return false;
1718+
1719+ trace_writeback_lazytime(inode);
1720+ mark_inode_dirty_sync(inode);
1721+ return true;
1722+}
1723+
17141724 /*
17151725 * Write out an inode and its dirty pages (or some of its dirty pages, depending
17161726 * on @wbc->nr_to_write), and clear the relevant dirty flags from i_state.
@@ -1750,17 +1760,15 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc) · 33 unmodified lines
17501760 }
17511761
17521762 /*
1753− * If the inode has dirty timestamps and we need to write them, call
1754− * mark_inode_dirty_sync() to notify the filesystem about it and to
1755− * change I_DIRTY_TIME into I_DIRTY_SYNC.
1763+ * For data integrity writeback, or when the dirty interval expired,
1764+ * ask the file system to propagata lazy timestamp updates into real
1765+ * dirty state.
17561766 */
17571767 if ((inode_state_read_once(inode) & I_DIRTY_TIME) &&
17581768 (wbc->sync_mode == WB_SYNC_ALL ||
17591769 time_after(jiffies, inode->dirtied_time_when +
1760− dirtytime_expire_interval * HZ))) {
1761− trace_writeback_lazytime(inode);
1762− mark_inode_dirty_sync(inode);
1763− }
1770+ dirtytime_expire_interval * HZ)))
1771+ sync_lazytime(inode);
17641772
17651773 /*
17661774 * Get and clear the dirty flags from i_state. This needs to be done
fs/inode.c+1−4
@@ -1979,11 +1979,8 @@ retry: · 1978 unmodified lines
19791979 if (atomic_add_unless(&inode->i_count, -1, 1))
19801980 return;
19811981
1982− if ((inode_state_read_once(inode) & I_DIRTY_TIME) && inode->i_nlink) {
1983− trace_writeback_lazytime_iput(inode);
1984− mark_inode_dirty_sync(inode);
1982+ if (inode->i_nlink && sync_lazytime(inode))
19851983 goto retry;
1986− }
19871984
19881985 spin_lock(&inode->i_lock);
19891986 if (unlikely((inode_state_read(inode) & I_DIRTY_TIME) && inode->i_nlink)) {
fs/internal.h+2−1
@@ -214,7 +214,8 @@ bool in_group_or_capable(struct mnt_idmap *idmap, · 213 unmodified lines
214214 /*
215215 * fs-writeback.c
216216 */
217−extern long get_nr_dirty_inodes(void);
217+long get_nr_dirty_inodes(void);
218+bool sync_lazytime(struct inode *inode);
218219
219220 /*
220221 * dcache.c
fs/sync.c+2−2
@@ -183,8 +183,8 @@ int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync) · 182 unmodified lines
183183
184184 if (!file->f_op->fsync)
185185 return -EINVAL;
186− if (!datasync && (inode_state_read_once(inode) & I_DIRTY_TIME))
187− mark_inode_dirty_sync(inode);
186+ if (!datasync)
187+ sync_lazytime(inode);
188188 return file->f_op->fsync(file, start, end, datasync);
189189 }
190190 EXPORT_SYMBOL(vfs_fsync_range);
include/trace/events/writeback.h+0−6
@@ -856,12 +856,6 @@ DEFINE_EVENT(writeback_inode_template, writeback_lazytime, · 855 unmodified lines
856856 TP_ARGS(inode)
857857 );
858858
859−DEFINE_EVENT(writeback_inode_template, writeback_lazytime_iput,
860− TP_PROTO(struct inode *inode),
861−
862− TP_ARGS(inode)
863−);
864−
865859 DEFINE_EVENT(writeback_inode_template, writeback_dirty_inode_enqueue,
866860
867861 TP_PROTO(struct inode *inode),