mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH, RFC] addjust discard request to be aligned with hwsect size to support SSDs with larger sector size
@ 2010-05-13  5:19 Jiaying Zhang
  2010-05-16 13:38 ` Christoph Hellwig
  2010-05-17 18:57 ` Martin K. Petersen
  0 siblings, 2 replies; 7+ messages in thread
From: Jiaying Zhang @ 2010-05-13  5:19 UTC (permalink / raw)
  To: hch, jens.axboe; +Cc: linux-kernel, mrubin

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 =

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

end of thread, other threads:[~2010-05-18  0:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-13  5:19 [PATCH, RFC] addjust discard request to be aligned with hwsect size to support SSDs with larger sector size Jiaying Zhang
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

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®