Skip to content

Commit 6e5f0f6

Browse files
Hongyu JinMike Snitzer
authored andcommitted
dm io: Support IO priority
Some IO will dispatch from kworker with different io_context settings than the submitting task, we may need to specify a priority to avoid losing priority. Add IO priority parameter to dm_io() and update all callers. Co-developed-by: Yibin Ding <yibin.ding@unisoc.com> Signed-off-by: Yibin Ding <yibin.ding@unisoc.com> Signed-off-by: Hongyu Jin <hongyu.jin@unisoc.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent b9d3ac4 commit 6e5f0f6

10 files changed

Lines changed: 38 additions & 34 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ static void use_dmio(struct dm_buffer *b, enum req_op op, sector_t sector,
13151315
io_req.mem.ptr.vma = (char *)b->data + offset;
13161316
}
13171317

1318-
r = dm_io(&io_req, 1, &region, NULL);
1318+
r = dm_io(&io_req, 1, &region, NULL, IOPRIO_DEFAULT);
13191319
if (unlikely(r))
13201320
b->end_io(b, errno_to_blk_status(r));
13211321
}
@@ -2167,7 +2167,7 @@ int dm_bufio_issue_flush(struct dm_bufio_client *c)
21672167
if (WARN_ON_ONCE(dm_bufio_in_request()))
21682168
return -EINVAL;
21692169

2170-
return dm_io(&io_req, 1, &io_reg, NULL);
2170+
return dm_io(&io_req, 1, &io_reg, NULL, IOPRIO_DEFAULT);
21712171
}
21722172
EXPORT_SYMBOL_GPL(dm_bufio_issue_flush);
21732173

@@ -2191,7 +2191,7 @@ int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t c
21912191
if (WARN_ON_ONCE(dm_bufio_in_request()))
21922192
return -EINVAL; /* discards are optional */
21932193

2194-
return dm_io(&io_req, 1, &io_reg, NULL);
2194+
return dm_io(&io_req, 1, &io_reg, NULL, IOPRIO_DEFAULT);
21952195
}
21962196
EXPORT_SYMBOL_GPL(dm_bufio_issue_discard);
21972197

drivers/md/dm-integrity.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static int sync_rw_sb(struct dm_integrity_c *ic, blk_opf_t opf)
555555
}
556556
}
557557

558-
r = dm_io(&io_req, 1, &io_loc, NULL);
558+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
559559
if (unlikely(r))
560560
return r;
561561

@@ -1073,7 +1073,7 @@ static void rw_journal_sectors(struct dm_integrity_c *ic, blk_opf_t opf,
10731073
io_loc.sector = ic->start + SB_SECTORS + sector;
10741074
io_loc.count = n_sectors;
10751075

1076-
r = dm_io(&io_req, 1, &io_loc, NULL);
1076+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
10771077
if (unlikely(r)) {
10781078
dm_integrity_io_error(ic, (opf & REQ_OP_MASK) == REQ_OP_READ ?
10791079
"reading journal" : "writing journal", r);
@@ -1190,7 +1190,7 @@ static void copy_from_journal(struct dm_integrity_c *ic, unsigned int section, u
11901190
io_loc.sector = target;
11911191
io_loc.count = n_sectors;
11921192

1193-
r = dm_io(&io_req, 1, &io_loc, NULL);
1193+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
11941194
if (unlikely(r)) {
11951195
WARN_ONCE(1, "asynchronous dm_io failed: %d", r);
11961196
fn(-1UL, data);
@@ -1519,7 +1519,7 @@ static void dm_integrity_flush_buffers(struct dm_integrity_c *ic, bool flush_dat
15191519
fr.io_reg.count = 0,
15201520
fr.ic = ic;
15211521
init_completion(&fr.comp);
1522-
r = dm_io(&fr.io_req, 1, &fr.io_reg, NULL);
1522+
r = dm_io(&fr.io_req, 1, &fr.io_reg, NULL, IOPRIO_DEFAULT);
15231523
BUG_ON(r);
15241524
}
15251525

@@ -1728,7 +1728,7 @@ static void integrity_recheck(struct dm_integrity_io *dio)
17281728
io_loc.sector = sector;
17291729
io_loc.count = ic->sectors_per_block;
17301730

1731-
r = dm_io(&io_req, 1, &io_loc, NULL);
1731+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
17321732
if (unlikely(r)) {
17331733
dio->bi_status = errno_to_blk_status(r);
17341734
goto free_ret;
@@ -2808,7 +2808,7 @@ static void integrity_recalc(struct work_struct *w)
28082808
io_loc.sector = get_data_sector(ic, area, offset);
28092809
io_loc.count = n_sectors;
28102810

2811-
r = dm_io(&io_req, 1, &io_loc, NULL);
2811+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
28122812
if (unlikely(r)) {
28132813
dm_integrity_io_error(ic, "reading data", r);
28142814
goto err;

drivers/md/dm-io.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void km_dp_init(struct dpages *dp, void *data)
305305
*/
306306
static void do_region(const blk_opf_t opf, unsigned int region,
307307
struct dm_io_region *where, struct dpages *dp,
308-
struct io *io)
308+
struct io *io, unsigned short ioprio)
309309
{
310310
struct bio *bio;
311311
struct page *page;
@@ -354,6 +354,7 @@ static void do_region(const blk_opf_t opf, unsigned int region,
354354
&io->client->bios);
355355
bio->bi_iter.bi_sector = where->sector + (where->count - remaining);
356356
bio->bi_end_io = endio;
357+
bio->bi_ioprio = ioprio;
357358
store_io_and_region_in_bio(bio, io, region);
358359

359360
if (op == REQ_OP_DISCARD || op == REQ_OP_WRITE_ZEROES) {
@@ -383,7 +384,7 @@ static void do_region(const blk_opf_t opf, unsigned int region,
383384

384385
static void dispatch_io(blk_opf_t opf, unsigned int num_regions,
385386
struct dm_io_region *where, struct dpages *dp,
386-
struct io *io, int sync)
387+
struct io *io, int sync, unsigned short ioprio)
387388
{
388389
int i;
389390
struct dpages old_pages = *dp;
@@ -400,7 +401,7 @@ static void dispatch_io(blk_opf_t opf, unsigned int num_regions,
400401
for (i = 0; i < num_regions; i++) {
401402
*dp = old_pages;
402403
if (where[i].count || (opf & REQ_PREFLUSH))
403-
do_region(opf, i, where + i, dp, io);
404+
do_region(opf, i, where + i, dp, io, ioprio);
404405
}
405406

406407
/*
@@ -425,7 +426,7 @@ static void sync_io_complete(unsigned long error, void *context)
425426

426427
static int sync_io(struct dm_io_client *client, unsigned int num_regions,
427428
struct dm_io_region *where, blk_opf_t opf, struct dpages *dp,
428-
unsigned long *error_bits)
429+
unsigned long *error_bits, unsigned short ioprio)
429430
{
430431
struct io *io;
431432
struct sync_io sio;
@@ -447,7 +448,7 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
447448
io->vma_invalidate_address = dp->vma_invalidate_address;
448449
io->vma_invalidate_size = dp->vma_invalidate_size;
449450

450-
dispatch_io(opf, num_regions, where, dp, io, 1);
451+
dispatch_io(opf, num_regions, where, dp, io, 1, ioprio);
451452

452453
wait_for_completion_io(&sio.wait);
453454

@@ -459,7 +460,8 @@ static int sync_io(struct dm_io_client *client, unsigned int num_regions,
459460

460461
static int async_io(struct dm_io_client *client, unsigned int num_regions,
461462
struct dm_io_region *where, blk_opf_t opf,
462-
struct dpages *dp, io_notify_fn fn, void *context)
463+
struct dpages *dp, io_notify_fn fn, void *context,
464+
unsigned short ioprio)
463465
{
464466
struct io *io;
465467

@@ -479,7 +481,7 @@ static int async_io(struct dm_io_client *client, unsigned int num_regions,
479481
io->vma_invalidate_address = dp->vma_invalidate_address;
480482
io->vma_invalidate_size = dp->vma_invalidate_size;
481483

482-
dispatch_io(opf, num_regions, where, dp, io, 0);
484+
dispatch_io(opf, num_regions, where, dp, io, 0, ioprio);
483485
return 0;
484486
}
485487

@@ -521,7 +523,8 @@ static int dp_init(struct dm_io_request *io_req, struct dpages *dp,
521523
}
522524

523525
int dm_io(struct dm_io_request *io_req, unsigned int num_regions,
524-
struct dm_io_region *where, unsigned long *sync_error_bits)
526+
struct dm_io_region *where, unsigned long *sync_error_bits,
527+
unsigned short ioprio)
525528
{
526529
int r;
527530
struct dpages dp;
@@ -532,11 +535,11 @@ int dm_io(struct dm_io_request *io_req, unsigned int num_regions,
532535

533536
if (!io_req->notify.fn)
534537
return sync_io(io_req->client, num_regions, where,
535-
io_req->bi_opf, &dp, sync_error_bits);
538+
io_req->bi_opf, &dp, sync_error_bits, ioprio);
536539

537540
return async_io(io_req->client, num_regions, where,
538541
io_req->bi_opf, &dp, io_req->notify.fn,
539-
io_req->notify.context);
542+
io_req->notify.context, ioprio);
540543
}
541544
EXPORT_SYMBOL(dm_io);
542545

drivers/md/dm-kcopyd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,9 @@ static int run_io_job(struct kcopyd_job *job)
578578
io_job_start(job->kc->throttle);
579579

580580
if (job->op == REQ_OP_READ)
581-
r = dm_io(&io_req, 1, &job->source, NULL);
581+
r = dm_io(&io_req, 1, &job->source, NULL, IOPRIO_DEFAULT);
582582
else
583-
r = dm_io(&io_req, job->num_dests, job->dests, NULL);
583+
r = dm_io(&io_req, job->num_dests, job->dests, NULL, IOPRIO_DEFAULT);
584584

585585
return r;
586586
}

drivers/md/dm-log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int rw_header(struct log_c *lc, enum req_op op)
300300
{
301301
lc->io_req.bi_opf = op;
302302

303-
return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
303+
return dm_io(&lc->io_req, 1, &lc->header_location, NULL, IOPRIO_DEFAULT);
304304
}
305305

306306
static int flush_header(struct log_c *lc)
@@ -313,7 +313,7 @@ static int flush_header(struct log_c *lc)
313313

314314
lc->io_req.bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
315315

316-
return dm_io(&lc->io_req, 1, &null_location, NULL);
316+
return dm_io(&lc->io_req, 1, &null_location, NULL, IOPRIO_DEFAULT);
317317
}
318318

319319
static int read_header(struct log_c *log)

drivers/md/dm-raid1.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static int mirror_flush(struct dm_target *ti)
278278
}
279279

280280
error_bits = -1;
281-
dm_io(&io_req, ms->nr_mirrors, io, &error_bits);
281+
dm_io(&io_req, ms->nr_mirrors, io, &error_bits, IOPRIO_DEFAULT);
282282
if (unlikely(error_bits != 0)) {
283283
for (i = 0; i < ms->nr_mirrors; i++)
284284
if (test_bit(i, &error_bits))
@@ -554,7 +554,7 @@ static void read_async_bio(struct mirror *m, struct bio *bio)
554554

555555
map_region(&io, m, bio);
556556
bio_set_m(bio, m);
557-
BUG_ON(dm_io(&io_req, 1, &io, NULL));
557+
BUG_ON(dm_io(&io_req, 1, &io, NULL, IOPRIO_DEFAULT));
558558
}
559559

560560
static inline int region_in_sync(struct mirror_set *ms, region_t region,
@@ -681,7 +681,7 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
681681
*/
682682
bio_set_m(bio, get_default_mirror(ms));
683683

684-
BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL));
684+
BUG_ON(dm_io(&io_req, ms->nr_mirrors, io, NULL, IOPRIO_DEFAULT));
685685
}
686686

687687
static void do_writes(struct mirror_set *ms, struct bio_list *writes)

drivers/md/dm-snap-persistent.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static void do_metadata(struct work_struct *work)
223223
{
224224
struct mdata_req *req = container_of(work, struct mdata_req, work);
225225

226-
req->result = dm_io(req->io_req, 1, req->where, NULL);
226+
req->result = dm_io(req->io_req, 1, req->where, NULL, IOPRIO_DEFAULT);
227227
}
228228

229229
/*
@@ -247,7 +247,7 @@ static int chunk_io(struct pstore *ps, void *area, chunk_t chunk, blk_opf_t opf,
247247
struct mdata_req req;
248248

249249
if (!metadata)
250-
return dm_io(&io_req, 1, &where, NULL);
250+
return dm_io(&io_req, 1, &where, NULL, IOPRIO_DEFAULT);
251251

252252
req.where = &where;
253253
req.io_req = &io_req;

drivers/md/dm-verity-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static int verity_recheck(struct dm_verity *v, struct dm_verity_io *io,
511511
io_loc.bdev = v->data_dev->bdev;
512512
io_loc.sector = cur_block << (v->data_dev_block_bits - SECTOR_SHIFT);
513513
io_loc.count = 1 << (v->data_dev_block_bits - SECTOR_SHIFT);
514-
r = dm_io(&io_req, 1, &io_loc, NULL);
514+
r = dm_io(&io_req, 1, &io_loc, NULL, IOPRIO_DEFAULT);
515515
if (unlikely(r))
516516
goto free_ret;
517517

drivers/md/dm-writecache.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ static void ssd_commit_flushed(struct dm_writecache *wc, bool wait_for_ios)
531531
req.notify.context = &endio;
532532

533533
/* writing via async dm-io (implied by notify.fn above) won't return an error */
534-
(void) dm_io(&req, 1, &region, NULL);
534+
(void) dm_io(&req, 1, &region, NULL, IOPRIO_DEFAULT);
535535
i = j;
536536
}
537537

@@ -568,7 +568,7 @@ static void ssd_commit_superblock(struct dm_writecache *wc)
568568
req.notify.fn = NULL;
569569
req.notify.context = NULL;
570570

571-
r = dm_io(&req, 1, &region, NULL);
571+
r = dm_io(&req, 1, &region, NULL, IOPRIO_DEFAULT);
572572
if (unlikely(r))
573573
writecache_error(wc, r, "error writing superblock");
574574
}
@@ -596,7 +596,7 @@ static void writecache_disk_flush(struct dm_writecache *wc, struct dm_dev *dev)
596596
req.client = wc->dm_io;
597597
req.notify.fn = NULL;
598598

599-
r = dm_io(&req, 1, &region, NULL);
599+
r = dm_io(&req, 1, &region, NULL, IOPRIO_DEFAULT);
600600
if (unlikely(r))
601601
writecache_error(wc, r, "error flushing metadata: %d", r);
602602
}
@@ -990,7 +990,7 @@ static int writecache_read_metadata(struct dm_writecache *wc, sector_t n_sectors
990990
req.client = wc->dm_io;
991991
req.notify.fn = NULL;
992992

993-
return dm_io(&req, 1, &region, NULL);
993+
return dm_io(&req, 1, &region, NULL, IOPRIO_DEFAULT);
994994
}
995995

996996
static void writecache_resume(struct dm_target *ti)

include/linux/dm-io.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ void dm_io_client_destroy(struct dm_io_client *client);
8080
* error occurred doing io to the corresponding region.
8181
*/
8282
int dm_io(struct dm_io_request *io_req, unsigned int num_regions,
83-
struct dm_io_region *region, unsigned int long *sync_error_bits);
83+
struct dm_io_region *region, unsigned int long *sync_error_bits,
84+
unsigned short ioprio);
8485

8586
#endif /* __KERNEL__ */
8687
#endif /* _LINUX_DM_IO_H */

0 commit comments

Comments
 (0)