mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: jiayingz@google.com (Jiaying Zhang)
To: hch@infradead.org, jens.axboe@oracle.com
Cc: linux-kernel@vger.kernel.org, mrubin@google.com
Subject: [PATCH, RFC] addjust discard request to be aligned with hwsect size to support SSDs with larger sector size
Date: Wed, 12 May 2010 22:19:53 -0700 (PDT)	[thread overview]
Message-ID: <20100513051953.532821BC316@ruihe.smo.corp.google.com> (raw)

The currect blkdev_issue_discard() function assumes 512 sector size.
We have seen some problem when using discard on a SSD that has larger
sector size. The following patch adjusts the starting address and size of
a discard request to be aligned with hwsect size.

Signed-off-by: Jiaying Zhang <jiayingz@google.com>

diff --git a/block/blk-barrier.c b/block/blk-barrier.c
index 6d88544..576b7a1 100644
--- a/block/blk-barrier.c
+++ b/block/blk-barrier.c
@@ -376,14 +376,22 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 		DISCARD_BARRIER : DISCARD_NOBARRIER;
 	struct bio *bio;
 	struct page *page;
+	int hwsect_shift = blksize_bits(bdev_logical_block_size(bdev)) - 9;
+	int hwsect_mask = (1 << hwsect_shift) - 1;
+	sector_t end_sector;
 	int ret = 0;
 
 	if (!q)
 		return -ENXIO;
 
-	if (!blk_queue_discard(q))
+	if (!blk_queue_discard(q) || q->limits.max_discard_sectors == 0)
 		return -EOPNOTSUPP;
 
+	if (hwsect_shift > 0) {
+		end_sector = (sector + nr_sects) & ~hwsect_mask;
+		sector = (sector + hwsect_mask) & ~hwsect_mask;
+		nr_sects = end_sector - sector;
+	}
 	while (nr_sects && !ret) {
 		unsigned int sector_size = q->limits.logical_block_size;
 		unsigned int max_discard_sectors =

             reply	other threads:[~2010-05-13  5:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-13  5:19 Jiaying Zhang [this message]
2010-05-16 13:38 ` Christoph Hellwig
2010-05-17 19:27   ` Jiaying Zhang
2010-05-17 18:57 ` Martin K. Petersen
2010-05-17 19:44   ` Jiaying Zhang
2010-05-17 20:00     ` Martin K. Petersen
2010-05-18  0:57       ` Jiaying Zhang

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=20100513051953.532821BC316@ruihe.smo.corp.google.com \
    --to=jiayingz@google.com \
    --cc=hch@infradead.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrubin@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®