Re: bio_chain: proposed solution for bio_alloc failure and large IO simplification

From: Adam J. Richter (
Date: Fri Jun 14 2002 - 23:38:29 EST

I wrote:
> Anyhow, I can write bio_chain in a separate file without
>touching changing any existing code in the kernel, if I am not going
>to implement the merge hint. I think I will do just that so that
>we have something that we can discuss more concretely.

        In case anyone is intersted, here is a sample implementation
that compiles. I do not know if it works. I have renamed it
recycle_bio. This version allocates a bio on the stack (56 bytes
on x86). I also wrote a version that avoided the stack allocation,
but added a field "void *bi_destructor_private;" to struct bio.

Adam J. Richter __ ______________ 575 Oroville Road \ / Milpitas, California 95035
+1 408 309-6081 | g g d r a s i l United States of America
                         "Free Software For The Rest Of Us."

/* In bio.h: */

extern struct bio *__recycle_bio(struct bio *oldbio);
static inline struct bio *recycle_bio(struct bio *oldbio,
                                      int gfp_mask, int nvecs) {
        struct bio *newbio;

        if (nvecs > oldbio->bi_max)

        if ((newbio = bio_alloc(gfp_mask, nvecs)) != NULL) {
                submit_bio(oldbio->bi_rw, oldbio);
                return newbio;
        } else
                return __recycle_bio(oldbio);

/* In bio.c: */
struct bio_completion {
        struct bio bio;
        struct completion done;

static void fake_destruct(struct bio *bio)
        struct bio_completion *stackbio;

        stackbio = list_entry(bio, struct bio_completion, bio);

struct bio *__recycle_bio(struct bio *bio)
        struct bio_completion stackbio; = *bio; = fake_destruct;

        submit_bio(, &;

        return bio;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sat Jun 15 2002 - 22:00:32 EST