All of lore.kernel.org
 help / color / mirror / Atom feed
* iomap fixes
@ 2018-02-28 17:45 Christoph Hellwig
  2018-02-28 17:45 ` [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christoph Hellwig @ 2018-02-28 17:45 UTC (permalink / raw)
  To: linux-xfs; +Cc: david

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


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

* [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents
  2018-02-28 17:45 iomap fixes Christoph Hellwig
@ 2018-02-28 17:45 ` Christoph Hellwig
  2018-03-01 22:01   ` Dave Chinner
  2018-02-28 17:45 ` [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O Christoph Hellwig
  2018-02-28 17:45 ` [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT Christoph Hellwig
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-02-28 17:45 UTC (permalink / raw)
  To: linux-xfs; +Cc: david

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

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_iomap.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 66e1edbfb2b2..4e771e0f1170 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -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.
-- 
2.14.2


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

* [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O
  2018-02-28 17:45 iomap fixes Christoph Hellwig
  2018-02-28 17:45 ` [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents Christoph Hellwig
@ 2018-02-28 17:45 ` Christoph Hellwig
  2018-03-01 22:02   ` Dave Chinner
  2018-02-28 17:45 ` [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT Christoph Hellwig
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-02-28 17:45 UTC (permalink / raw)
  To: linux-xfs; +Cc: david

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.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_iomap.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 4e771e0f1170..ee01859b77a5 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -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;
 }
 
-- 
2.14.2


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

* [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT
  2018-02-28 17:45 iomap fixes Christoph Hellwig
  2018-02-28 17:45 ` [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents Christoph Hellwig
  2018-02-28 17:45 ` [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O Christoph Hellwig
@ 2018-02-28 17:45 ` Christoph Hellwig
  2018-03-01 22:04   ` Dave Chinner
  2 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-02-28 17:45 UTC (permalink / raw)
  To: linux-xfs; +Cc: david

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

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_iomap.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index ee01859b77a5..046469fcc1b8 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -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);
-- 
2.14.2


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

* Re: [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents
  2018-02-28 17:45 ` [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents Christoph Hellwig
@ 2018-03-01 22:01   ` Dave Chinner
  2018-03-01 22:28     ` Darrick J. Wong
  0 siblings, 1 reply; 8+ messages in thread
From: Dave Chinner @ 2018-03-01 22:01 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Wed, Feb 28, 2018 at 09:45:50AM -0800, Christoph Hellwig wrote:
> The iomap zeroing interface is smart enough to skip zeroing holes or
> unwritten extents.  Don't subvert this logic for reflink files.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks good,

Reviewed-by: Dave Chinner <dchinner@redhat.com>
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O
  2018-02-28 17:45 ` [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O Christoph Hellwig
@ 2018-03-01 22:02   ` Dave Chinner
  0 siblings, 0 replies; 8+ messages in thread
From: Dave Chinner @ 2018-03-01 22:02 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Wed, Feb 28, 2018 at 09:45:51AM -0800, Christoph Hellwig wrote:
> 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.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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

Reviewed-by: Dave Chinner <dchinner@redhat.com>
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT
  2018-02-28 17:45 ` [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT Christoph Hellwig
@ 2018-03-01 22:04   ` Dave Chinner
  0 siblings, 0 replies; 8+ messages in thread
From: Dave Chinner @ 2018-03-01 22:04 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs

On Wed, Feb 28, 2018 at 09:45:52AM -0800, Christoph Hellwig wrote:
> Fix xfs_file_iomap_begin to trylock the ilock if IOMAP_NOWAIT is passed,
> so that we don't block io_submit callers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

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,

Reviewed-by: Dave Chinner <dchinner@redhat.com>
-- 
Dave Chinner
david@fromorbit.com

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

* Re: [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents
  2018-03-01 22:01   ` Dave Chinner
@ 2018-03-01 22:28     ` Darrick J. Wong
  0 siblings, 0 replies; 8+ messages in thread
From: Darrick J. Wong @ 2018-03-01 22:28 UTC (permalink / raw)
  To: Dave Chinner; +Cc: Christoph Hellwig, linux-xfs

On Fri, Mar 02, 2018 at 09:01:20AM +1100, Dave Chinner wrote:
> On Wed, Feb 28, 2018 at 09:45:50AM -0800, Christoph Hellwig wrote:
> > The iomap zeroing interface is smart enough to skip zeroing holes or
> > unwritten extents.  Don't subvert this logic for reflink files.
> > 
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> 
> Looks good,
> 
> Reviewed-by: Dave Chinner <dchinner@redhat.com>

Looks ok, will test.
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

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

> -- 
> Dave Chinner
> david@fromorbit.com
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2018-03-01 22:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 17:45 iomap fixes Christoph Hellwig
2018-02-28 17:45 ` [PATCH 1/3] xfs: don't allocate COW blocks for zeroing holes or unwritten extents Christoph Hellwig
2018-03-01 22:01   ` Dave Chinner
2018-03-01 22:28     ` Darrick J. Wong
2018-02-28 17:45 ` [PATCH 2/3] xfs: don't start out with the exclusive ilock for direct I/O Christoph Hellwig
2018-03-01 22:02   ` Dave Chinner
2018-02-28 17:45 ` [PATCH 3/3] xfs: don't block on the ilock for RWF_NOWAIT Christoph Hellwig
2018-03-01 22:04   ` Dave Chinner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.