dm: bio list helpers
Alasdair G Kergon
maintainerPATCH 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
@@ -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 ;
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
-0bl->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.
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
-0bl->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
Alasdair G Kergon
maintainerQuoted 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]
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
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
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
Alasdair G Kergon
maintainerQuoted 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_LISTis 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]
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
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_LISTis a strange name for something which initialises storage.
So try DEFINE_BIO_LIST, it goes in line with DEFINE_SPINLOCK for example.
Jan