Skip to contentSkip to conversation

dm: bio list helpers

PATCH In review Alasdair G Kergon 6 participants 10 messages May 8, 2007 – May 10, 2007 Device mapper

lore
Share & tools
lore

Alasdair G Kergon

author maintainer
#0 lore raw

PATCH 22/26 dm: bio list helpers

From: Heinz Mauelshagen <[email protected]>

More bio_list helper functions for new targets (including dm-delay and dm-loop) to manipulate lists of bios.

---

 drivers/md/dm-bio-list.h |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+)
drivers/md/dm-bio-list.h +26 -0
Index: linux-2.6.21/drivers/md/dm-bio-list.h
===================================================================
@@ -8,17 +8,43 @@
 #define DM_BIO_LIST_H
 
 #include <linux/bio.h>
+#include <linux/prefetch.h>
 
 struct bio_list {
 	struct bio *head;
 	struct bio *tail;
 };
 
+static inline int bio_list_empty(const struct bio_list *bl)
+{
+	return bl->head == NULL;
+}
+
+#define BIO_LIST_INIT { .head = NULL, .tail = NULL }
+
+#define BIO_LIST(bl) \
+	struct bio_list bl = BIO_LIST_INIT
+
 static inline void bio_list_init(struct bio_list *bl)
 {
 	bl->head = bl->tail = NULL;
 }
 
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+
+static inline unsigned bio_list_size(const struct bio_list *bl)
+{
+	unsigned sz = 0;
+	struct bio *bio;
+
+	bio_list_for_each(bio, bl)
+		sz++;
+
+	return sz;
+}
+
 static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
 {
 	bio->bi_next = NULL;
#1 lore raw

drivers/md/dm-bio-list.h line 26

Quoted 4 lines · On Tue, 8 May 2007 20:48:45 +0100 Alasdair G Kergon <[email protected]> wrote:
drivers/md/dm-bio-list.h +4 -0
+#define BIO_LIST_INIT { .head = NULL, .tail = NULL }
+
+#define BIO_LIST(bl) \
+	struct bio_list bl = BIO_LIST_INIT

BIO_LIST is a strange name for something which initialises storage.

drivers/md/dm-bio-list.h line 36

Quoted 9 lines

static inline void bio_list_init(struct bio_list *bl) {

drivers/md/dm-bio-list.h +4 -0
 	bl->head = bl->tail = NULL;
 }
 
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+

I have this vague memory from a long time ago that one particular CPU type wants to go oops when prefetching from an invalid address.

Maybe that went away for some reason - we'd have hit it again if it was real.

#2 lore raw
Quoted 13 lines · Andrew Morton

drivers/md/dm-bio-list.h line 36

Quoted 9 lines

static inline void bio_list_init(struct bio_list *bl) {

drivers/md/dm-bio-list.h +4 -0
 	bl->head = bl->tail = NULL;
 }
 
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+

I have this vague memory from a long time ago that one particular CPU type wants to go oops when prefetching from an invalid address.

Quoted 2 lines

Maybe that went away for some reason - we'd have hit it again if it was real.

Besides, manual prefetching is very rarely a win. I dabbled with some benchmarks a few weeks back (with the doubly linked lists), and in most cases it was actually a loss. So I'd vote for just removing the prefetch() above.

Signature · 1 line
Jens Axboe
author maintainer
#3 lore raw
Quoted 4 lines · Jens Axboe

Besides, manual prefetching is very rarely a win. I dabbled with some benchmarks a few weeks back (with the doubly linked lists), and in most cases it was actually a loss. So I'd vote for just removing the prefetch() above.

OK.

Alasdair

Signature · 1 line
[email protected]
#4 lore raw
In reply to Jens Axboe
Quoted 10 lines · Jens Axboe
Quoted 4 lines · Andrew Morton

drivers/md/dm-bio-list.h line 36

Quoted 4 lines
drivers/md/dm-bio-list.h +4 -0
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+

Besides, manual prefetching is very rarely a win. I dabbled with some benchmarks a few weeks back (with the doubly linked lists), and in most cases it was actually a loss. So I'd vote for just removing the prefetch() above.

So is the prefetching in the basic ADTs (e.g. linux/list.h) a loss too?

Jan

#5 lore raw
Quoted 13 lines · On Thu, 10 May 2007 16:17:57 +0200 (MEST) Jan Engelhardt…
Quoted 10 lines · Jens Axboe
Quoted 4 lines · Andrew Morton

drivers/md/dm-bio-list.h line 36

Quoted 4 lines
drivers/md/dm-bio-list.h +4 -0
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+

Besides, manual prefetching is very rarely a win. I dabbled with some benchmarks a few weeks back (with the doubly linked lists), and in most cases it was actually a loss. So I'd vote for just removing the prefetch() above.

Quoted 1 line

So is the prefetching in the basic ADTs (e.g. linux/list.h) a loss too?

Depends on the box it seems. On the newest systems the processor prefetching seems to be very much smarter. On a "classic" AMD Athlon the prefetching made the scheduler about 1.5% faster...

Alan

#6 lore raw
Quoted 16 lines · Alan Cox
Quoted 13 lines · On Thu, 10 May 2007 16:17:57 +0200 (MEST) Jan Engelhardt…
Quoted 10 lines · Jens Axboe
Quoted 4 lines · Andrew Morton

drivers/md/dm-bio-list.h line 36

Quoted 4 lines
drivers/md/dm-bio-list.h +4 -0
+#define bio_list_for_each(bio, bl) \
+	for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
+	     bio = bio->bi_next)
+

Besides, manual prefetching is very rarely a win. I dabbled with some benchmarks a few weeks back (with the doubly linked lists), and in most cases it was actually a loss. So I'd vote for just removing the prefetch() above.

Quoted 5 lines
Quoted 1 line

So is the prefetching in the basic ADTs (e.g. linux/list.h) a loss too?

Depends on the box it seems. On the newest systems the processor prefetching seems to be very much smarter. On a "classic" AMD Athlon the prefetching made the scheduler about 1.5% faster...

It very much depends on the box, indeed. The ones I tested on were _slower_ with the prefetching, perhaps the dumber CPU's will benefit. In the long run, I don't think the manual prefetching is a good idea.

Signature · 1 line
Jens Axboe
author maintainer
#7 lore raw
In reply to Andrew Morton
Quoted 6 lines · Andrew Morton

drivers/md/dm-bio-list.h line 26

Quoted 2 lines · On Tue, 8 May 2007 20:48:45 +0100 Alasdair G Kergon <[email protected]> wrote:
drivers/md/dm-bio-list.h +2 -0
+#define BIO_LIST(bl) \
+	struct bio_list bl = BIO_LIST_INIT

BIO_LIST is a strange name for something which initialises storage.

Those came by analogy with list.h, with list_head -> bio_list:

  #define LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)

We could use something like INIT_BIO_LIST(bl) for that, but perhaps it would be more readable always written out in full?
struct bio_list bl = BIO_LIST_INIT;

Alasdair

Signature · 1 line
[email protected]
#8 lore raw
In reply to Andrew Morton
Quoted 3 lines · Andrew Morton

I have this vague memory from a long time ago that one particular CPU type wants to go oops when prefetching from an invalid address.

AMD K7/K8, but we got a generic workaround for a long time.

-Andi

#9 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton

drivers/md/dm-bio-list.h line 26

Quoted 4 lines · On Tue, 8 May 2007 20:48:45 +0100 Alasdair G Kergon <[email protected]> wrote:
drivers/md/dm-bio-list.h +4 -0
+#define BIO_LIST_INIT { .head = NULL, .tail = NULL }
+
+#define BIO_LIST(bl) \
+	struct bio_list bl = BIO_LIST_INIT

BIO_LIST is a strange name for something which initialises storage.

So try DEFINE_BIO_LIST, it goes in line with DEFINE_SPINLOCK for example.

Jan