Linux Device Mapper development
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@kernel.org>
To: dm-devel@redhat.com
Cc: axboe@kernel.dk, hch@lst.de, ming.lei@redhat.com
Subject: [dm-devel] [dm-5.19 PATCH 19/21] dm: put all polled dm_io instances into a single list
Date: Sun, 17 Apr 2022 22:27:31 -0400	[thread overview]
Message-ID: <20220418022733.56168-20-snitzer@kernel.org> (raw)
In-Reply-To: <20220418022733.56168-1-snitzer@kernel.org>

[-- Attachment #1: Type: application/octet-stream, Size: 5068 bytes --]

From: Ming Lei <ming.lei@redhat.com>

Now that bio_split() isn't used by DM's bio splitting, it is a bit
overkill to link dm_io into an hlist given there is only single dm_io
in the list.

Convert to using a single list for holding all dm_io instances
associated with this bio.

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
 drivers/md/dm-core.h |  2 +-
 drivers/md/dm.c      | 52 +++++++++++++++++++++++++++-------------------------
 2 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/drivers/md/dm-core.h b/drivers/md/dm-core.h
index d2d188c9b632..f3cfc7affd12 100644
--- a/drivers/md/dm-core.h
+++ b/drivers/md/dm-core.h
@@ -259,7 +259,7 @@ struct dm_io {
 	spinlock_t lock;
 	unsigned long start_time;
 	void *data;
-	struct hlist_node node;
+	struct dm_io *next;
 	struct task_struct *map_task;
 	struct dm_stats_aux stats_aux;
 
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 9b5cdd4b734d..c5a79712de1d 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1560,7 +1560,7 @@ static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
 }
 
 /*
- * Reuse ->bi_private as hlist head for storing all dm_io instances
+ * Reuse ->bi_private as dm_io list head for storing all dm_io instances
  * associated with this bio, and this bio's bi_private needs to be
  * stored in dm_io->data before the reuse.
  *
@@ -1568,36 +1568,37 @@ static bool __process_abnormal_io(struct clone_info *ci, struct dm_target *ti,
  * touch it after splitting. Meantime it won't be changed by anyone after
  * bio is submitted. So this reuse is safe.
  */
-static inline struct hlist_head *dm_get_bio_hlist_head(struct bio *bio)
+static inline struct dm_io **dm_poll_list_head(struct bio *bio)
 {
-	return (struct hlist_head *)&bio->bi_private;
+	return (struct dm_io **)&bio->bi_private;
 }
 
 static void dm_queue_poll_io(struct bio *bio, struct dm_io *io)
 {
-	struct hlist_head *head = dm_get_bio_hlist_head(bio);
+	struct dm_io **head = dm_poll_list_head(bio);
 
 	if (!(bio->bi_opf & REQ_DM_POLL_LIST)) {
 		bio->bi_opf |= REQ_DM_POLL_LIST;
 		/*
 		 * Save .bi_private into dm_io, so that we can reuse
-		 * .bi_private as hlist head for storing dm_io list
+		 * .bi_private as dm_io list head for storing dm_io list
 		 */
 		io->data = bio->bi_private;
 
-		INIT_HLIST_HEAD(head);
-
 		/* tell block layer to poll for completion */
 		bio->bi_cookie = ~BLK_QC_T_NONE;
+
+		io->next = NULL;
 	} else {
 		/*
 		 * bio recursed due to split, reuse original poll list,
 		 * and save bio->bi_private too.
 		 */
-		io->data = hlist_entry(head->first, struct dm_io, node)->data;
+		io->data = (*head)->data;
+		io->next = *head;
 	}
 
-	hlist_add_head(&io->node, head);
+	*head = io;
 }
 
 /*
@@ -1686,8 +1687,8 @@ static void dm_split_and_process_bio(struct mapped_device *md,
 	 * Drop the extra reference count for non-POLLED bio, and hold one
 	 * reference for POLLED bio, which will be released in dm_poll_bio
 	 *
-	 * Add every dm_io instance into the hlist_head which is stored in
-	 * bio->bi_private, so that dm_poll_bio can poll them all.
+	 * Add every dm_io instance into the dm_io list head which is stored
+	 * in bio->bi_private, so that dm_poll_bio can poll them all.
 	 */
 	if (error || !ci.submit_as_polled) {
 		/*
@@ -1749,18 +1750,16 @@ static bool dm_poll_dm_io(struct dm_io *io, struct io_comp_batch *iob,
 static int dm_poll_bio(struct bio *bio, struct io_comp_batch *iob,
 		       unsigned int flags)
 {
-	struct hlist_head *head = dm_get_bio_hlist_head(bio);
-	struct hlist_head tmp = HLIST_HEAD_INIT;
-	struct hlist_node *next;
-	struct dm_io *io;
+	struct dm_io **head = dm_poll_list_head(bio);
+	struct dm_io *list = *head;
+	struct dm_io *tmp = NULL;
+	struct dm_io *curr, *next;
 
 	/* Only poll normal bio which was marked as REQ_DM_POLL_LIST */
 	if (!(bio->bi_opf & REQ_DM_POLL_LIST))
 		return 0;
 
-	WARN_ON_ONCE(hlist_empty(head));
-
-	hlist_move_list(head, &tmp);
+	WARN_ON_ONCE(!list);
 
 	/*
 	 * Restore .bi_private before possibly completing dm_io.
@@ -1771,24 +1770,27 @@ static int dm_poll_bio(struct bio *bio, struct io_comp_batch *iob,
 	 * clearing REQ_DM_POLL_LIST here.
 	 */
 	bio->bi_opf &= ~REQ_DM_POLL_LIST;
-	bio->bi_private = hlist_entry(tmp.first, struct dm_io, node)->data;
+	bio->bi_private = list->data;
 
-	hlist_for_each_entry_safe(io, next, &tmp, node) {
-		if (dm_poll_dm_io(io, iob, flags)) {
-			hlist_del_init(&io->node);
+	for (curr = list, next = curr->next; curr; curr = next, next =
+			curr ? curr->next : NULL) {
+		if (dm_poll_dm_io(curr, iob, flags)) {
 			/*
 			 * clone_endio() has already occurred, so no
 			 * error handling is needed here.
 			 */
-			__dm_io_dec_pending(io);
+			__dm_io_dec_pending(curr);
+		} else {
+			curr->next = tmp;
+			tmp = curr;
 		}
 	}
 
 	/* Not done? */
-	if (!hlist_empty(&tmp)) {
+	if (tmp) {
 		bio->bi_opf |= REQ_DM_POLL_LIST;
 		/* Reset bio->bi_private to dm_io list head */
-		hlist_move_list(&tmp, head);
+		*head = tmp;
 		return 0;
 	}
 	return 1;
-- 
2.15.0


[-- Attachment #2: Type: text/plain, Size: 98 bytes --]

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

  parent reply	other threads:[~2022-04-18  2:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-18  2:27 [dm-devel] [dm-5.19 PATCH 00/21] dm: changes staged for 5.19 Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 01/21] block: change exported IO accounting interface from gendisk to bdev Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 02/21] dm: conditionally enable BIOSET_PERCPU_CACHE for dm_io bioset Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 03/21] dm: factor out dm_io_set_error and __dm_io_dec_pending Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 04/21] dm: simplify dm_io access in dm_split_and_process_bio Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 05/21] dm: simplify dm_start_io_acct Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 06/21] dm: mark various branches unlikely Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 07/21] dm: add local variables to clone_endio and __map_bio Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 08/21] dm: move hot dm_io members to same cacheline as dm_target_io Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 09/21] dm: introduce dm_{get, put}_live_table_bio called from dm_submit_bio Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 10/21] dm: conditionally enable branching for less used features Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 11/21] dm: simplify basic targets Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 12/21] dm: use bio_sectors in dm_aceept_partial_bio Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 13/21] dm: don't pass bio to __dm_start_io_acct and dm_end_io_acct Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 14/21] dm: pass dm_io instance to dm_io_acct directly Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 15/21] dm: switch to bdev based IO accounting interfaces Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 16/21] dm: improve bio splitting and associated IO accounting Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 17/21] dm: don't grab target io reference in dm_zone_map_bio Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 18/21] dm: improve dm_io reference counting Mike Snitzer
2022-04-18  2:27 ` Mike Snitzer [this message]
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 20/21] dm: simplify bio-based IO accounting further Mike Snitzer
2022-04-18  2:27 ` [dm-devel] [dm-5.19 PATCH 21/21] dm: improve abnormal bio processing Mike Snitzer
2022-04-21  4:06   ` Shinichiro Kawasaki
2022-04-22 13:13     ` Mike Snitzer
2022-04-22 13:26       ` Mike Snitzer
2022-04-25 23:57         ` Shinichiro Kawasaki
2022-04-18  3:00 ` [dm-devel] [dm-5.19 PATCH 00/21] dm: changes staged for 5.19 Damien Le Moal
2022-04-18  3:16   ` Mike Snitzer
2022-04-18 12:49     ` Jens Axboe
2022-04-18 12:51 ` [dm-devel] (subset) " Jens Axboe

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=20220418022733.56168-20-snitzer@kernel.org \
    --to=snitzer@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=dm-devel@redhat.com \
    --cc=hch@lst.de \
    --cc=ming.lei@redhat.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