Skip to content

Commit 2c68f6d

Browse files
committed
block: shrink struct bio down to 2 cache lines again
Commit bcf2843b3f8f added ->bi_error to cleanup the error passing for struct bio, but that ended up adding 4 bytes and a 4 byte hole to the size of struct bio. For a clean config, that bumped it from 128 bytes, to 136 bytes, on x86-64. The ->bi_flags member is currently an unsigned long, but it fits easily within an int. Change it to an unsigned int, adjust the the pool offset code, and move ->bi_error into the new hole. Then we end up with a 128 byte bio again. Change the bio flag set/clear to use cmpxchg to ensure we don't lose any flags when manipulating them. Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent b7c44ed commit 2c68f6d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/linux/bio.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,17 +306,17 @@ static inline void bio_cnt_set(struct bio *bio, unsigned int count)
306306

307307
static inline bool bio_flagged(struct bio *bio, unsigned int bit)
308308
{
309-
return (bio->bi_flags & (1UL << bit)) != 0;
309+
return (bio->bi_flags & (1U << bit)) != 0;
310310
}
311311

312312
static inline void bio_set_flag(struct bio *bio, unsigned int bit)
313313
{
314-
bio->bi_flags |= (1UL << bit);
314+
bio->bi_flags |= (1U << bit);
315315
}
316316

317317
static inline void bio_clear_flag(struct bio *bio, unsigned int bit)
318318
{
319-
bio->bi_flags &= ~(1UL << bit);
319+
bio->bi_flags &= ~(1U << bit);
320320
}
321321

322322
enum bip_flags {

include/linux/blk_types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ struct bvec_iter {
4646
struct bio {
4747
struct bio *bi_next; /* request queue link */
4848
struct block_device *bi_bdev;
49-
unsigned long bi_flags; /* status, command, etc */
49+
unsigned int bi_flags; /* status, command, etc */
50+
int bi_error;
5051
unsigned long bi_rw; /* bottom bits READ/WRITE,
5152
* top bits priority
5253
*/
5354

5455
struct bvec_iter bi_iter;
5556

56-
int bi_error;
5757
/* Number of segments in this BIO after
5858
* physical address coalescing is performed.
5959
*/
@@ -134,7 +134,7 @@ struct bio {
134134
*/
135135
#define BIO_POOL_BITS (4)
136136
#define BIO_POOL_NONE ((1UL << BIO_POOL_BITS) - 1)
137-
#define BIO_POOL_OFFSET (BITS_PER_LONG - BIO_POOL_BITS)
137+
#define BIO_POOL_OFFSET (32 - BIO_POOL_BITS)
138138
#define BIO_POOL_MASK (1UL << BIO_POOL_OFFSET)
139139
#define BIO_POOL_IDX(bio) ((bio)->bi_flags >> BIO_POOL_OFFSET)
140140

0 commit comments

Comments
 (0)