All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Mike Snitzer <snitzer@redhat.com>,
	Christoph Hellwig <hch@infradead.org>,
	dm-devel@redhat.com, "Alasdair G. Kergon" <agk@redhat.com>,
	linux-block@vger.kernel.org
Subject: [PATCH 1/4] brd: handle misaligned discard
Date: Wed, 26 Oct 2016 16:26:15 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.1610261625580.12287@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1610261624100.12287@file01.intranet.prod.int.rdu2.redhat.com>

The brd driver refuses misaligned discard requests with an error. However,
this is suboptimal, misaligned requests could be handled by discarding a
part of the request that is aligned on a page boundary. This patch changes
the code so that it handles misaligned requests.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/block/brd.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Index: linux-2.6/drivers/block/brd.c
===================================================================
--- linux-2.6.orig/drivers/block/brd.c
+++ linux-2.6/drivers/block/brd.c
@@ -213,9 +213,14 @@ static int copy_to_brd_setup(struct brd_
 }
 
 static void discard_from_brd(struct brd_device *brd,
-			sector_t sector, size_t n)
+			sector_t sector, unsigned n_sectors)
 {
-	while (n >= PAGE_SIZE) {
+	unsigned boundary = -sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1);
+	if (unlikely(boundary >= n_sectors))
+		return;
+	sector += boundary;
+	n_sectors -= boundary;
+	while (n_sectors >= PAGE_SIZE >> SECTOR_SHIFT) {
 		/*
 		 * Don't want to actually discard pages here because
 		 * re-allocating the pages can result in writeback
@@ -226,7 +231,7 @@ static void discard_from_brd(struct brd_
 		else
 			brd_zero_page(brd, sector);
 		sector += PAGE_SIZE >> SECTOR_SHIFT;
-		n -= PAGE_SIZE;
+		n_sectors -= PAGE_SIZE >> SECTOR_SHIFT;
 	}
 }
 
@@ -339,10 +344,7 @@ static blk_qc_t brd_make_request(struct
 		goto io_error;
 
 	if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) {
-		if (sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1) ||
-		    bio->bi_iter.bi_size & ~PAGE_MASK)
-			goto io_error;
-		discard_from_brd(brd, sector, bio->bi_iter.bi_size);
+		discard_from_brd(brd, sector, bio->bi_iter.bi_size >> SECTOR_SHIFT);
 		goto out;
 	}
 

  reply	other threads:[~2016-10-26 20:26 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21 18:33 device mapper and the BLKFLSBUF ioctl Mikulas Patocka
2016-10-21 20:00 ` Mike Snitzer
2016-10-21 20:18   ` Mikulas Patocka
2016-10-24 15:57     ` Mike Snitzer
2016-10-25 13:07       ` Christoph Hellwig
2016-10-25 14:37         ` [PATCH] brd: remove support for BLKFLSBUF Mike Snitzer
2016-10-25 14:46           ` Jens Axboe
2016-10-26 20:25             ` [PATCH 0/4] brd: support discard Mikulas Patocka
2016-10-26 20:26               ` Mikulas Patocka [this message]
2016-10-26 20:38                 ` [dm-devel] [PATCH 1/4] brd: handle misaligned discard Bart Van Assche
2016-10-26 20:38                   ` Bart Van Assche
2016-10-26 21:46                   ` Mikulas Patocka
2016-10-26 21:50                     ` REQ_OP for zeroing, was " Christoph Hellwig
2016-10-28 11:43                       ` Mikulas Patocka
2016-10-28 13:14                         ` Christoph Hellwig
2016-10-31 16:36                           ` Mikulas Patocka
2016-10-26 21:57                     ` Bart Van Assche
2016-10-26 21:57                       ` Bart Van Assche
2016-10-28 11:39                       ` Mikulas Patocka
2016-10-28 15:55                         ` Bart Van Assche
2016-10-28 15:55                           ` Bart Van Assche
2016-10-31 16:31                           ` Mikulas Patocka
2016-10-26 20:26               ` [PATCH 2/4] brd: extend rcu read sections Mikulas Patocka
2016-10-26 20:27               ` [PATCH 3/4] brd: implement discard Mikulas Patocka
2016-10-26 20:27               ` [PATCH 4/4] brd: remove unused brd_zero_page Mikulas Patocka

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=alpine.LRH.2.02.1610261625580.12287@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=agk@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=snitzer@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.