All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Yan <tom.ty89@gmail.com>
To: axboe@kernel.dk, linux-block@vger.kernel.org
Cc: Tom Yan <tom.ty89@gmail.com>
Subject: [PATCH] block: avoid fragmented discard splits
Date: Tue, 29 Dec 2020 23:27:13 +0800	[thread overview]
Message-ID: <20201229152713.7269-1-tom.ty89@gmail.com> (raw)

Make bio_aligned_discard max_sectors() return value that is divisible by
the max_discard_sectors queue limit to avoid fragmented discard splits.

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

diff --git a/block/blk.h b/block/blk.h
index 7550364c326c..e87324a227c6 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -268,8 +268,12 @@ 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 badms = round_down(UINT_MAX,
+					q->limits.discard_granularity) >>
+				SECTOR_SHIFT;
+	if (badms > q->limits.max_discard_sectors)
+		badms = round_down(badms, q->limits.max_discard_sectors);
+	return badms;
 }
 
 /*
-- 
2.29.2


                 reply	other threads:[~2020-12-29 15:28 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=20201229152713.7269-1-tom.ty89@gmail.com \
    --to=tom.ty89@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@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 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.