Skip to content

Commit 09ce874

Browse files
committed
block: use flags instead of bit fields for blkdev_dio
This generates a lot better code for me, and bumps performance from 7650K IOPS to 7750K IOPS. Looking at profiles for the run and running perf diff, it confirms that we're now sending a lot less time there: 6.38% -2.80% [kernel.vmlinux] [k] blkdev_direct_IO Taking it from the 2nd most cycle consumer to only the 9th most at 3.35% of the CPU time. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent fac7c6d commit 09ce874

1 file changed

Lines changed: 20 additions & 14 deletions

File tree

‎block/fops.c‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,20 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
123123
return ret;
124124
}
125125

126+
enum {
127+
DIO_MULTI_BIO = 1,
128+
DIO_SHOULD_DIRTY = 2,
129+
DIO_IS_SYNC = 4,
130+
};
131+
126132
struct blkdev_dio {
127133
union {
128134
struct kiocb *iocb;
129135
struct task_struct *waiter;
130136
};
131137
size_t size;
132138
atomic_t ref;
133-
bool multi_bio : 1;
134-
bool should_dirty : 1;
135-
bool is_sync : 1;
139+
unsigned int flags;
136140
struct bio bio;
137141
};
138142

@@ -141,13 +145,13 @@ static struct bio_set blkdev_dio_pool;
141145
static void blkdev_bio_end_io(struct bio *bio)
142146
{
143147
struct blkdev_dio *dio = bio->bi_private;
144-
bool should_dirty = dio->should_dirty;
148+
bool should_dirty = dio->flags & DIO_SHOULD_DIRTY;
145149

146150
if (bio->bi_status && !dio->bio.bi_status)
147151
dio->bio.bi_status = bio->bi_status;
148152

149-
if (!dio->multi_bio || atomic_dec_and_test(&dio->ref)) {
150-
if (!dio->is_sync) {
153+
if (!(dio->flags & DIO_MULTI_BIO) || atomic_dec_and_test(&dio->ref)) {
154+
if (!(dio->flags & DIO_IS_SYNC)) {
151155
struct kiocb *iocb = dio->iocb;
152156
ssize_t ret;
153157

@@ -161,7 +165,7 @@ static void blkdev_bio_end_io(struct bio *bio)
161165
}
162166

163167
dio->iocb->ki_complete(iocb, ret, 0);
164-
if (dio->multi_bio)
168+
if (dio->flags & DIO_MULTI_BIO)
165169
bio_put(&dio->bio);
166170
} else {
167171
struct task_struct *waiter = dio->waiter;
@@ -198,17 +202,19 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
198202
bio = bio_alloc_kiocb(iocb, nr_pages, &blkdev_dio_pool);
199203

200204
dio = container_of(bio, struct blkdev_dio, bio);
201-
dio->is_sync = is_sync = is_sync_kiocb(iocb);
202-
if (dio->is_sync) {
205+
is_sync = is_sync_kiocb(iocb);
206+
if (is_sync) {
207+
dio->flags = DIO_IS_SYNC;
203208
dio->waiter = current;
204209
bio_get(bio);
205210
} else {
211+
dio->flags = 0;
206212
dio->iocb = iocb;
207213
}
208214

209215
dio->size = 0;
210-
dio->multi_bio = false;
211-
dio->should_dirty = is_read && iter_is_iovec(iter);
216+
if (is_read && iter_is_iovec(iter))
217+
dio->flags |= DIO_SHOULD_DIRTY;
212218

213219
/*
214220
* Don't plug for HIPRI/polled IO, as those should go straight
@@ -234,7 +240,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
234240

235241
if (is_read) {
236242
bio->bi_opf = REQ_OP_READ;
237-
if (dio->should_dirty)
243+
if (dio->flags & DIO_SHOULD_DIRTY)
238244
bio_set_pages_dirty(bio);
239245
} else {
240246
bio->bi_opf = dio_bio_write_op(iocb);
@@ -255,15 +261,15 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
255261
WRITE_ONCE(iocb->private, bio);
256262
break;
257263
}
258-
if (!dio->multi_bio) {
264+
if (!(dio->flags & DIO_MULTI_BIO)) {
259265
/*
260266
* AIO needs an extra reference to ensure the dio
261267
* structure which is embedded into the first bio
262268
* stays around.
263269
*/
264270
if (!is_sync)
265271
bio_get(bio);
266-
dio->multi_bio = true;
272+
dio->flags |= DIO_MULTI_BIO;
267273
atomic_set(&dio->ref, 2);
268274
do_poll = false;
269275
} else {

0 commit comments

Comments
 (0)