Skip to contentSkip to conversation

iomap fixes

PATCH In review Christoph Hellwig 3 participants 8 messages Feb 28, 2018 – Mar 1, 2018 XFS filesystem

lore
Share & tools
lore
#0 lore raw

A few iomap fixes for 4.16-rc and -stable:

- don't allocate blocks for zeroing holes or unwritten extents on files with the reflink bit set
- don't take the exlusive ilock when no needed in iomap_begin
- don't block on the ilock for RWF_NOWAIT

#1 lore raw

PATCH 1/3 xfs: don't allocate COW blocks for zeroing holes or unwritten extents

The iomap zeroing interface is smart enough to skip zeroing holes or unwritten extents. Don't subvert this logic for reflink files.

---
 fs/xfs/xfs_iomap.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
fs/xfs/xfs_iomap.c +10 -1
index 66e1edbfb2b2..4e771e0f1170 100644
@@ -955,6 +955,13 @@ static inline bool imap_needs_alloc(struct inode *inode,
 		(IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN);
 }
 
+static inline bool needs_cow_for_zeroing(struct xfs_bmbt_irec *imap, int nimaps)
+{
+	return nimaps &&
+		imap->br_startblock != HOLESTARTBLOCK &&
+		imap->br_state != XFS_EXT_UNWRITTEN;
+}
+
 static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
 {
 	/*
@@ -1024,7 +1031,9 @@ xfs_file_iomap_begin(
 			goto out_unlock;
 	}
 
-	if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
+	if (xfs_is_reflink_inode(ip) &&
+	    ((flags & IOMAP_WRITE) ||
+	     ((flags & IOMAP_ZERO) && needs_cow_for_zeroing(&imap, nimaps)))) {
 		if (flags & IOMAP_DIRECT) {
 			/*
 			 * A reflinked inode will result in CoW alloc.
Signature · 1 line
2.14.2
Reviewed-by
#3 lore raw

Re: [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents

Quoted 9 lines · Dave Chinner
Quoted 4 lines · Christoph Hellwig

The iomap zeroing interface is smart enough to skip zeroing holes or unwritten extents. Don't subvert this logic for reflink files.

Looks good,

Looks ok, will test.

Oracle mail and vger are having some sort of idiotic slapfest, which means I haven't received any list traffic in 2 days. Please cc me on patches so that review isn't delayed. :)

--D

Quoted 8 lines
Signature · 6 lines
Dave Chinner
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

PATCH 2/3 xfs: don't start out with the exclusive ilock for direct I/O

In reply to Christoph Hellwig

There is no reason to take the ilock exclusively at the start of xfs_file_iomap_begin for direct I/O, given that it will be demoted just before calling xfs_iomap_write_direct anyway.

---
 fs/xfs/xfs_iomap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/xfs_iomap.c +2 -4
index 4e771e0f1170..ee01859b77a5 100644
@@ -965,13 +965,11 @@ static inline bool needs_cow_for_zeroing(struct xfs_bmbt_irec *imap, int nimaps)
 static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
 {
 	/*
-	 * COW writes will allocate delalloc space, so we need to make sure
-	 * to take the lock exclusively here.
+	 * COW writes may allocate delalloc space or convert unwritten COW
+	 * extents, so we need to make sure to take the lock exclusively here.
 	 */
 	if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO)))
 		return true;
-	if ((flags & IOMAP_DIRECT) && (flags & IOMAP_WRITE))
-		return true;
 	return false;
 }
 
Signature · 1 line
2.14.2
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O

Quoted 5 lines · Christoph Hellwig

There is no reason to take the ilock exclusively at the start of xfs_file_iomap_begin for direct I/O, given that it will be demoted just before calling xfs_iomap_write_direct anyway.

Seems to work fine, and reverts us back to the per-iomap behaviour.

Signature · 2 lines
Dave Chinner
[email protected]
#6 lore raw

PATCH 3/3 xfs: don't block on the ilock for RWF_NOWAIT

In reply to Christoph Hellwig

Fix xfs_file_iomap_begin to trylock the ilock if IOMAP_NOWAIT is passed, so that we don't block io_submit callers.

---
 fs/xfs/xfs_iomap.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
fs/xfs/xfs_iomap.c +19 -8
index ee01859b77a5..046469fcc1b8 100644
@@ -970,6 +970,15 @@ static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
 	 */
 	if (xfs_is_reflink_inode(ip) && (flags & (IOMAP_WRITE | IOMAP_ZERO)))
 		return true;
+
+	/*
+	 * Extents not yet cached requires exclusive access, don't block.
+	 * This is an opencoded xfs_ilock_data_map_shared() to cater for the
+	 * non-blocking behaviour.
+	 */
+	if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE &&
+	    !(ip->i_df.if_flags & XFS_IFEXTENTS))
+		return true;
 	return false;
 }
 
@@ -998,16 +1007,18 @@ xfs_file_iomap_begin(
 		return xfs_file_iomap_begin_delay(inode, offset, length, iomap);
 	}
 
-	if (need_excl_ilock(ip, flags)) {
+	if (need_excl_ilock(ip, flags))
 		lockmode = XFS_ILOCK_EXCL;
-		xfs_ilock(ip, XFS_ILOCK_EXCL);
-	} else {
-		lockmode = xfs_ilock_data_map_shared(ip);
-	}
+	else
+		lockmode = XFS_ILOCK_SHARED;
 
-	if ((flags & IOMAP_NOWAIT) && !(ip->i_df.if_flags & XFS_IFEXTENTS)) {
-		error = -EAGAIN;
-		goto out_unlock;
+	if (flags & IOMAP_NOWAIT) {
+		if (!(ip->i_df.if_flags & XFS_IFEXTENTS))
+			return -EAGAIN;
+		if (!xfs_ilock_nowait(ip, lockmode))
+			return -EAGAIN;
+	} else {
+		xfs_ilock(ip, lockmode);
 	}
 
 	ASSERT(offset <= mp->m_super->s_maxbytes);
Signature · 1 line
2.14.2
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT

Quoted 4 lines · Christoph Hellwig

Fix xfs_file_iomap_begin to trylock the ilock if IOMAP_NOWAIT is passed, so that we don't block io_submit callers.

I'm not really happy with the locking mess we've created, but I have patches on top of this to clean it up a bit. SO as a stepping stone,

Signature · 2 lines
Dave Chinner
[email protected]