Skip to content

Commit

Permalink
[PATCH] kill bio->bi_set
Browse files Browse the repository at this point in the history
Jens:

->bi_set is totally unnecessary bloat of struct bio.  Just define a proper
destructor for the bio and it already knows what bio_set it belongs too.

Peter:

Fixed the bugs.

Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Peter Osterlund <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Peter Osterlund authored and Linus Torvalds committed Sep 7, 2005
1 parent 6f00df2 commit 3676347
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
6 changes: 6 additions & 0 deletions drivers/md/dm-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ static void vm_dp_init(struct dpages *dp, void *data)
dp->context_ptr = data;
}

static void dm_bio_destructor(struct bio *bio)
{
bio_free(bio, _bios);
}

/*-----------------------------------------------------------------
* IO routines that accept a list of pages.
*---------------------------------------------------------------*/
Expand All @@ -263,6 +268,7 @@ static void do_region(int rw, unsigned int region, struct io_region *where,
bio->bi_bdev = where->bdev;
bio->bi_end_io = endio;
bio->bi_private = io;
bio->bi_destructor = dm_bio_destructor;
bio_set_region(bio, region);

/*
Expand Down
6 changes: 6 additions & 0 deletions drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ struct clone_info {
unsigned short idx;
};

static void dm_bio_destructor(struct bio *bio)
{
bio_free(bio, dm_set);
}

/*
* Creates a little bio that is just does part of a bvec.
*/
Expand All @@ -410,6 +415,7 @@ static struct bio *split_bvec(struct bio *bio, sector_t sector,
struct bio_vec *bv = bio->bi_io_vec + idx;

clone = bio_alloc_bioset(GFP_NOIO, 1, dm_set);
clone->bi_destructor = dm_bio_destructor;
*clone->bi_io_vec = *bv;

clone->bi_sector = sector;
Expand Down
32 changes: 21 additions & 11 deletions fs/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,22 @@ static inline struct bio_vec *bvec_alloc_bs(unsigned int __nocast gfp_mask, int
return bvl;
}

/*
* default destructor for a bio allocated with bio_alloc_bioset()
*/
static void bio_destructor(struct bio *bio)
void bio_free(struct bio *bio, struct bio_set *bio_set)
{
const int pool_idx = BIO_POOL_IDX(bio);
struct bio_set *bs = bio->bi_set;

BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS);

mempool_free(bio->bi_io_vec, bs->bvec_pools[pool_idx]);
mempool_free(bio, bs->bio_pool);
mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]);
mempool_free(bio, bio_set->bio_pool);
}

/*
* default destructor for a bio allocated with bio_alloc_bioset()
*/
static void bio_fs_destructor(struct bio *bio)
{
bio_free(bio, fs_bio_set);
}

inline void bio_init(struct bio *bio)
Expand Down Expand Up @@ -171,16 +175,19 @@ struct bio *bio_alloc_bioset(unsigned int __nocast gfp_mask, int nr_iovecs, stru
bio->bi_max_vecs = bvec_slabs[idx].nr_vecs;
}
bio->bi_io_vec = bvl;
bio->bi_destructor = bio_destructor;
bio->bi_set = bs;
}
out:
return bio;
}

struct bio *bio_alloc(unsigned int __nocast gfp_mask, int nr_iovecs)
{
return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);

if (bio)
bio->bi_destructor = bio_fs_destructor;

return bio;
}

void zero_fill_bio(struct bio *bio)
Expand Down Expand Up @@ -273,8 +280,10 @@ struct bio *bio_clone(struct bio *bio, unsigned int __nocast gfp_mask)
{
struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set);

if (b)
if (b) {
b->bi_destructor = bio_fs_destructor;
__bio_clone(b, bio);
}

return b;
}
Expand Down Expand Up @@ -1075,6 +1084,7 @@ subsys_initcall(init_bio);

EXPORT_SYMBOL(bio_alloc);
EXPORT_SYMBOL(bio_put);
EXPORT_SYMBOL(bio_free);
EXPORT_SYMBOL(bio_endio);
EXPORT_SYMBOL(bio_init);
EXPORT_SYMBOL(__bio_clone);
Expand Down
2 changes: 1 addition & 1 deletion include/linux/bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ struct bio {
void *bi_private;

bio_destructor_t *bi_destructor; /* destructor */
struct bio_set *bi_set; /* memory pools set */
};

/*
Expand Down Expand Up @@ -280,6 +279,7 @@ extern void bioset_free(struct bio_set *);
extern struct bio *bio_alloc(unsigned int __nocast, int);
extern struct bio *bio_alloc_bioset(unsigned int __nocast, int, struct bio_set *);
extern void bio_put(struct bio *);
extern void bio_free(struct bio *, struct bio_set *);

extern void bio_endio(struct bio *, unsigned int, int);
struct request_queue;
Expand Down

0 comments on commit 3676347

Please sign in to comment.