All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: linux-xfs@vger.kernel.org
Cc: michaelcallahan@fb.com
Subject: [PATCH 3/3] xfs: merge discard requests
Date: Mon, 17 Oct 2016 22:22:33 +0200	[thread overview]
Message-ID: <1476735753-5861-4-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1476735753-5861-1-git-send-email-hch@lst.de>

We often have multiple busy extent entries that are adjacent.  Merge them
before calling __blkdev_issue_discard to give the drive larger request.

To allow for better merging the busy extent sort function is also updated
to sort for the full block number and not just the AG number.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_extent_busy.c | 12 ++++++++----
 fs/xfs/xfs_log_cil.c     | 44 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/fs/xfs/xfs_extent_busy.c b/fs/xfs/xfs_extent_busy.c
index 162dc18..50c277e 100644
--- a/fs/xfs/xfs_extent_busy.c
+++ b/fs/xfs/xfs_extent_busy.c
@@ -596,9 +596,13 @@ xfs_extent_busy_clear(
 int
 xfs_extent_busy_ag_cmp(
 	void			*priv,
-	struct list_head	*a,
-	struct list_head	*b)
+	struct list_head	*l1,
+	struct list_head	*l2)
 {
-	return container_of(a, struct xfs_extent_busy, list)->agno -
-		container_of(b, struct xfs_extent_busy, list)->agno;
+	struct xfs_extent_busy	*b1 =
+		container_of(l1, struct xfs_extent_busy, list);
+	struct xfs_extent_busy	*b2 =
+		container_of(l2, struct xfs_extent_busy, list);
+
+	return b1->agno - b2->agno || b1->bno - b2->bno;
 }
diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c
index 82f1cbc..c30b19f 100644
--- a/fs/xfs/xfs_log_cil.c
+++ b/fs/xfs/xfs_log_cil.c
@@ -526,11 +526,14 @@ xlog_discard_busy_extents(
 	struct xfs_mount	*mp,
 	struct xfs_cil_ctx	*ctx)
 {
+	struct block_device	*bdev = mp->m_ddev_targp->bt_bdev;
 	struct list_head	*list = &ctx->busy_extents;
 	struct xfs_extent_busy	*busyp;
 	struct bio		*bio = NULL;
 	struct blk_plug		plug;
 	int			error = 0;
+	bool			have_prev = false;
+	sector_t		bno, len, prev_bno, prev_len;
 
 	ASSERT(mp->m_flags & XFS_MOUNT_DISCARD);
 
@@ -539,18 +542,37 @@ xlog_discard_busy_extents(
 		trace_xfs_discard_extent(mp, busyp->agno, busyp->bno,
 					 busyp->length);
 
-		error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
-				XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno),
-				XFS_FSB_TO_BB(mp, busyp->length),
-				GFP_NOFS, 0, &bio);
-		if (error && error != -EOPNOTSUPP) {
-			xfs_info(mp,
-	 "discard failed for extent [0x%llx,%u], error %d",
-				 (unsigned long long)busyp->bno,
-				 busyp->length,
-				 error);
-			break;
+		bno = XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno);
+		len = XFS_FSB_TO_BB(mp, busyp->length);
+
+		if (have_prev) {
+			if (prev_bno + prev_len == bno) {
+				prev_len += len;
+				continue;
+			}
+
+			error = __blkdev_issue_discard(bdev, prev_bno, prev_len,
+					GFP_NOFS, 0, &bio);
+			if (error && error != -EOPNOTSUPP)
+				goto done;
 		}
+
+		prev_bno = bno;
+		prev_len = len;
+		have_prev = true;
+	}
+
+	if (have_prev) {
+		error = __blkdev_issue_discard(bdev, prev_bno, prev_len,
+				GFP_NOFS, 0, &bio);
+	}
+
+done:
+	if (error && error != -EOPNOTSUPP) {
+		xfs_info(mp,
+			"discard failed for extent [0x%llx,0x%llx], error %d",
+			(unsigned long long)bno, (unsigned long long)len,
+			error);
 	}
 
 	if (bio) {
-- 
2.1.4


  parent reply	other threads:[~2016-10-17 20:22 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-17 20:22 discard improvements Christoph Hellwig
2016-10-17 20:22 ` [PATCH 1/3] xfs: fix the AG loop in xfs_alloc_vextent for busy extents Christoph Hellwig
2016-10-19 13:48   ` Brian Foster
2016-10-21 12:48     ` Christoph Hellwig
2016-10-21 14:41       ` Brian Foster
2016-11-08  6:15   ` Dave Chinner
2016-11-10 19:17     ` Christoph Hellwig
2016-10-17 20:22 ` [PATCH 2/3] xfs: don't block the log commit handler for discards Christoph Hellwig
2016-10-17 23:29   ` Dave Chinner
2016-10-18  5:05     ` Christoph Hellwig
2016-10-19 10:58     ` Christoph Hellwig
2016-10-28 16:16       ` Michael Callahan
2016-10-31 15:16         ` Christoph Hellwig
2016-10-17 20:22 ` Christoph Hellwig [this message]
2016-10-28 10:11 ` discard improvements Avi Kivity
2016-10-31 15:14   ` Christoph Hellwig
2016-11-05 18:18     ` Avi Kivity
2016-11-06 16:36       ` Christoph Hellwig
2016-11-06 23:21         ` Dave Chinner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476735753-5861-4-git-send-email-hch@lst.de \
    --to=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    --cc=michaelcallahan@fb.com \
    --subject='Re: [PATCH 3/3] xfs: merge discard requests' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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.