diff options
author | Chunwei Chen <[email protected]> | 2016-03-31 16:52:03 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2017-02-03 11:58:19 -0800 |
commit | 1ad7f89628ebb4efff7f9fbc34ef509ae18a753b (patch) | |
tree | ecbf00b0c1a7f8153499eed8cf86109ee3d7572d /module/zfs/zfs_vnops.c | |
parent | 5137c95dec57988e84e11313b4a541f7000f2e4c (diff) |
Enable lazytime semantic for atime
Linux 4.0 introduces lazytime. The idea is that when we update the atime, we
delay writing it to disk for as long as it is reasonably possible.
When lazytime is enabled, dirty_inode will be called with only I_DIRTY_TIME
flag whenever i_atime is updated. So under such condition, we will set
z_atime_dirty. We will only write it to disk if file is closed, inode is
evicted or setattr is called. Ideally, we should also write it whenever SA
is going to be updated, but it is left for future improvement.
There's one thing that we should take care of now that we allow i_atime to be
dirty. In original implementation, whenever SA is modified, zfs_inode_update
will be called to overwrite every thing in inode. This will cause dirty
i_atime to be discarded. We fix this by don't overwrite i_atime in
zfs_inode_update. We only overwrite i_atime when allocating new inode or doing
zfs_rezget with zfs_inode_update_new.
Signed-off-by: Chunwei Chen <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #4482
Diffstat (limited to 'module/zfs/zfs_vnops.c')
-rw-r--r-- | module/zfs/zfs_vnops.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c index 68dc65c73..384a37fea 100644 --- a/module/zfs/zfs_vnops.c +++ b/module/zfs/zfs_vnops.c @@ -2934,8 +2934,9 @@ top: } - if (mask & ATTR_ATIME) { - ZFS_TIME_ENCODE(&vap->va_atime, atime); + if ((mask & ATTR_ATIME) || zp->z_atime_dirty) { + zp->z_atime_dirty = 0; + ZFS_TIME_ENCODE(&ip->i_atime, atime); SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zsb), NULL, &atime, sizeof (atime)); } @@ -4048,7 +4049,7 @@ zfs_dirty_inode(struct inode *ip, int flags) dmu_tx_t *tx; uint64_t mode, atime[2], mtime[2], ctime[2]; sa_bulk_attr_t bulk[4]; - int error; + int error = 0; int cnt = 0; if (zfs_is_readonly(zsb) || dmu_objset_is_snapshot(zsb->z_os)) @@ -4057,6 +4058,20 @@ zfs_dirty_inode(struct inode *ip, int flags) ZFS_ENTER(zsb); ZFS_VERIFY_ZP(zp); +#ifdef I_DIRTY_TIME + /* + * This is the lazytime semantic indroduced in Linux 4.0 + * This flag will only be called from update_time when lazytime is set. + * (Note, I_DIRTY_SYNC will also set if not lazytime) + * Fortunately mtime and ctime are managed within ZFS itself, so we + * only need to dirty atime. + */ + if (flags == I_DIRTY_TIME) { + zp->z_atime_dirty = 1; + goto out; + } +#endif + tx = dmu_tx_create(zsb->z_os); dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE); @@ -4069,6 +4084,8 @@ zfs_dirty_inode(struct inode *ip, int flags) } mutex_enter(&zp->z_lock); + zp->z_atime_dirty = 0; + SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MODE(zsb), NULL, &mode, 8); SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_ATIME(zsb), NULL, &atime, 16); SA_ADD_BULK_ATTR(bulk, cnt, SA_ZPL_MTIME(zsb), NULL, &mtime, 16); |