linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Yan <tom.ty89@gmail.com>
To: linux-block@vger.kernel.org, linux-ide@vger.kernel.org,
	linux-scsi@vger.kernel.org
Cc: Tom Yan <tom.ty89@gmail.com>
Subject: [PATCH] block: Avoid fragmented discard splits for ATA drives
Date: Tue, 15 Dec 2020 18:54:15 +0800	[thread overview]
Message-ID: <20201215105415.5219-1-tom.ty89@gmail.com> (raw)

When 0xffffffff >> 9 are splited by 0xffff * 64, there will be a
remainder of 127. Avoid these small fragments by aligning the split
to 128.

Signed-off-by: Tom Yan <tom.ty89@gmail.com>
---
 block/blk.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/blk.h b/block/blk.h
index dfab98465db9..1dc12fc86de8 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -281,8 +281,11 @@ static inline unsigned int bio_allowed_max_sectors(struct request_queue *q)
 static inline unsigned int bio_aligned_discard_max_sectors(
 					struct request_queue *q)
 {
-	return round_down(UINT_MAX, q->limits.discard_granularity) >>
-			SECTOR_SHIFT;
+	unsigned int granularity = q->limits.discard_granularity;
+	/* Avoid fragmented splits for ATA drives */
+	if (128 % granularity == 0)
+		granularity = 128;
+	return round_down(UINT_MAX, granularity) >> SECTOR_SHIFT;
 }
 
 /*
-- 
2.29.2


                 reply	other threads:[~2020-12-15 10:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201215105415.5219-1-tom.ty89@gmail.com \
    --to=tom.ty89@gmail.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).