linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: axboe@kernel.dk
Cc: linux-block@vger.kernel.org, linux-mm@kvack.org
Subject: [PATCH 15/17] block: move a few merge helpers out of <linux/blkdev.h>
Date: Wed, 15 Sep 2021 08:40:42 +0200	[thread overview]
Message-ID: <20210915064044.950534-16-hch@lst.de> (raw)
In-Reply-To: <20210915064044.950534-1-hch@lst.de>

These are lock-layer internal helper, so move them to block/blk.h and
block/blk-mergec.  Also update a comment a bit to use better grammar.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/blk-merge.c      | 24 ++++++++++++++++
 block/blk.h            | 38 +++++++++++++++++++++++++
 include/linux/blkdev.h | 64 ------------------------------------------
 3 files changed, 62 insertions(+), 64 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 7a5c81c02c800..39f210da399a6 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -558,6 +558,23 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq)
 	return queue_max_segments(rq->q);
 }
 
+static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
+						  sector_t offset)
+{
+	struct request_queue *q = rq->q;
+
+	if (blk_rq_is_passthrough(rq))
+		return q->limits.max_hw_sectors;
+
+	if (!q->limits.chunk_sectors ||
+	    req_op(rq) == REQ_OP_DISCARD ||
+	    req_op(rq) == REQ_OP_SECURE_ERASE)
+		return blk_queue_get_max_sectors(q, req_op(rq));
+
+	return min(blk_max_size_offset(q, offset, 0),
+			blk_queue_get_max_sectors(q, req_op(rq)));
+}
+
 static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
 		unsigned int nr_phys_segs)
 {
@@ -718,6 +735,13 @@ static enum elv_merge blk_try_req_merge(struct request *req,
 	return ELEVATOR_NO_MERGE;
 }
 
+static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
+{
+	if (bio_page(a) == bio_page(b) && bio_offset(a) == bio_offset(b))
+		return true;
+	return false;
+}
+
 /*
  * For non-mq, this has to be called with the request spinlock acquired.
  * For mq with scheduling, the appropriate queue wide lock should be held.
diff --git a/block/blk.h b/block/blk.h
index 82ab26add08df..deb8393e34eec 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -94,6 +94,44 @@ static inline bool bvec_gap_to_prev(struct request_queue *q,
 	return __bvec_gap_to_prev(q, bprv, offset);
 }
 
+static inline bool rq_mergeable(struct request *rq)
+{
+	if (blk_rq_is_passthrough(rq))
+		return false;
+
+	if (req_op(rq) == REQ_OP_FLUSH)
+		return false;
+
+	if (req_op(rq) == REQ_OP_WRITE_ZEROES)
+		return false;
+
+	if (req_op(rq) == REQ_OP_ZONE_APPEND)
+		return false;
+
+	if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
+		return false;
+	if (rq->rq_flags & RQF_NOMERGE_FLAGS)
+		return false;
+
+	return true;
+}
+
+/*
+ * There are two different ways to handle DISCARD merges:
+ *  1) If max_discard_segments > 1, the driver treats every bio as a range and
+ *     send the bios to controller together. The ranges don't need to be
+ *     contiguous.
+ *  2) Otherwise, the request will be normal read/write requests.  The ranges
+ *     need to be contiguous.
+ */
+static inline bool blk_discard_mergable(struct request *req)
+{
+	if (req_op(req) == REQ_OP_DISCARD &&
+	    queue_max_discard_segments(req->q) > 1)
+		return true;
+	return false;
+}
+
 #ifdef CONFIG_BLK_DEV_INTEGRITY
 void blk_flush_integrity(void);
 bool __bio_integrity_endio(struct bio *);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 46a703394f7f4..be534040ca9c3 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -745,37 +745,6 @@ static inline bool rq_is_sync(struct request *rq)
 	return op_is_sync(rq->cmd_flags);
 }
 
-static inline bool rq_mergeable(struct request *rq)
-{
-	if (blk_rq_is_passthrough(rq))
-		return false;
-
-	if (req_op(rq) == REQ_OP_FLUSH)
-		return false;
-
-	if (req_op(rq) == REQ_OP_WRITE_ZEROES)
-		return false;
-
-	if (req_op(rq) == REQ_OP_ZONE_APPEND)
-		return false;
-
-	if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
-		return false;
-	if (rq->rq_flags & RQF_NOMERGE_FLAGS)
-		return false;
-
-	return true;
-}
-
-static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
-{
-	if (bio_page(a) == bio_page(b) &&
-	    bio_offset(a) == bio_offset(b))
-		return true;
-
-	return false;
-}
-
 static inline unsigned int blk_queue_depth(struct request_queue *q)
 {
 	if (q->queue_depth)
@@ -1030,23 +999,6 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
 	return min(q->limits.max_sectors, chunk_sectors);
 }
 
-static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
-						  sector_t offset)
-{
-	struct request_queue *q = rq->q;
-
-	if (blk_rq_is_passthrough(rq))
-		return q->limits.max_hw_sectors;
-
-	if (!q->limits.chunk_sectors ||
-	    req_op(rq) == REQ_OP_DISCARD ||
-	    req_op(rq) == REQ_OP_SECURE_ERASE)
-		return blk_queue_get_max_sectors(q, req_op(rq));
-
-	return min(blk_max_size_offset(q, offset, 0),
-			blk_queue_get_max_sectors(q, req_op(rq)));
-}
-
 static inline unsigned int blk_rq_count_bios(struct request *rq)
 {
 	unsigned int nr_bios = 0;
@@ -1490,22 +1442,6 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
 	return offset << SECTOR_SHIFT;
 }
 
-/*
- * Two cases of handling DISCARD merge:
- * If max_discard_segments > 1, the driver takes every bio
- * as a range and send them to controller together. The ranges
- * needn't to be contiguous.
- * Otherwise, the bios/requests will be handled as same as
- * others which should be contiguous.
- */
-static inline bool blk_discard_mergable(struct request *req)
-{
-	if (req_op(req) == REQ_OP_DISCARD &&
-	    queue_max_discard_segments(req->q) > 1)
-		return true;
-	return false;
-}
-
 static inline int bdev_discard_alignment(struct block_device *bdev)
 {
 	struct request_queue *q = bdev_get_queue(bdev);
-- 
2.30.2


  parent reply	other threads:[~2021-09-15  6:54 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15  6:40 untangle the block headers Christoph Hellwig
2021-09-15  6:40 ` [PATCH 01/17] mm: don't include <linux/blk-cgroup.h> in <linux/writeback.h> Christoph Hellwig
2021-09-15  8:45   ` Johannes Thumshirn
2021-09-15  8:49     ` Christoph Hellwig
2021-09-15  8:51       ` Johannes Thumshirn
2021-09-15  6:40 ` [PATCH 02/17] mm: don't include <linux/blk-cgroup.h> in <linux/backing-dev.h> Christoph Hellwig
2021-09-15  9:11   ` Johannes Thumshirn
2021-09-15  6:40 ` [PATCH 03/17] mm: don't include <linux/blkdev.h> " Christoph Hellwig
2021-09-15  6:40 ` [PATCH 04/17] mm: remove spurious blkdev.h includes Christoph Hellwig
2021-09-15  8:51   ` Johannes Thumshirn
2021-09-15  6:40 ` [PATCH 05/17] arch: " Christoph Hellwig
2021-09-15  6:40 ` [PATCH 06/17] kernel: " Christoph Hellwig
2021-09-15  6:40 ` [PATCH 07/17] sched: move the <linux/blkdev.h> include out of kernel/sched/sched.h Christoph Hellwig
2021-09-15  6:40 ` [PATCH 08/17] block: remove the unused rq_end_sector macro Christoph Hellwig
2021-09-15  6:40 ` [PATCH 09/17] block: remove the unused blk_queue_state enum Christoph Hellwig
2021-09-15  6:40 ` [PATCH 10/17] block: remove the cmd_size field from struct request_queue Christoph Hellwig
2021-09-15  6:40 ` [PATCH 11/17] block: remove the struct blk_queue_ctx forward declaration Christoph Hellwig
2021-09-15  6:40 ` [PATCH 12/17] block: move elevator.h to block/ Christoph Hellwig
2021-09-15  6:40 ` [PATCH 13/17] block: drop unused includes in <linux/blkdev.h> Christoph Hellwig
2021-09-15  6:40 ` [PATCH 14/17] block: drop unused includes in <linux/genhd.h> Christoph Hellwig
2021-09-15  6:40 ` Christoph Hellwig [this message]
2021-09-15  9:15   ` [PATCH 15/17] block: move a few merge helpers out of <linux/blkdev.h> Johannes Thumshirn
2021-09-15  6:40 ` [PATCH 16/17] block: move integrity handling " Christoph Hellwig
2021-09-15  6:40 ` [PATCH 17/17] block: move struct request to blk-mq.h Christoph Hellwig
2021-09-15  9:19   ` Johannes Thumshirn
2021-09-20 12:33 untangle the block headers v2 Christoph Hellwig
2021-09-20 12:33 ` [PATCH 15/17] block: move a few merge helpers out of <linux/blkdev.h> Christoph Hellwig

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=20210915064044.950534-16-hch@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-mm@kvack.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).