Skip to content

Commit e9b2238

Browse files
Hongyu JinMike Snitzer
authored andcommitted
dm bufio: 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 dm_bufio_read_with_ioprio() and dm_bufio_prefetch_with_ioprio() for use by bufio users to pass an ioprio other than IOPRIO_DEFAULT. 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> [snitzer: introduced _with_ioprio() wrappers to reduce churn] Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 6e5f0f6 commit e9b2238

2 files changed

Lines changed: 56 additions & 19 deletions

File tree

drivers/md/dm-bufio.c

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,8 @@ static void dmio_complete(unsigned long error, void *context)
12921292
}
12931293

12941294
static void use_dmio(struct dm_buffer *b, enum req_op op, sector_t sector,
1295-
unsigned int n_sectors, unsigned int offset)
1295+
unsigned int n_sectors, unsigned int offset,
1296+
unsigned short ioprio)
12961297
{
12971298
int r;
12981299
struct dm_io_request io_req = {
@@ -1315,7 +1316,7 @@ static void use_dmio(struct dm_buffer *b, enum req_op op, sector_t sector,
13151316
io_req.mem.ptr.vma = (char *)b->data + offset;
13161317
}
13171318

1318-
r = dm_io(&io_req, 1, &region, NULL, IOPRIO_DEFAULT);
1319+
r = dm_io(&io_req, 1, &region, NULL, ioprio);
13191320
if (unlikely(r))
13201321
b->end_io(b, errno_to_blk_status(r));
13211322
}
@@ -1331,21 +1332,23 @@ static void bio_complete(struct bio *bio)
13311332
}
13321333

13331334
static void use_bio(struct dm_buffer *b, enum req_op op, sector_t sector,
1334-
unsigned int n_sectors, unsigned int offset)
1335+
unsigned int n_sectors, unsigned int offset,
1336+
unsigned short ioprio)
13351337
{
13361338
struct bio *bio;
13371339
char *ptr;
13381340
unsigned int len;
13391341

13401342
bio = bio_kmalloc(1, GFP_NOWAIT | __GFP_NORETRY | __GFP_NOWARN);
13411343
if (!bio) {
1342-
use_dmio(b, op, sector, n_sectors, offset);
1344+
use_dmio(b, op, sector, n_sectors, offset, ioprio);
13431345
return;
13441346
}
13451347
bio_init(bio, b->c->bdev, bio->bi_inline_vecs, 1, op);
13461348
bio->bi_iter.bi_sector = sector;
13471349
bio->bi_end_io = bio_complete;
13481350
bio->bi_private = b;
1351+
bio->bi_ioprio = ioprio;
13491352

13501353
ptr = (char *)b->data + offset;
13511354
len = n_sectors << SECTOR_SHIFT;
@@ -1368,7 +1371,7 @@ static inline sector_t block_to_sector(struct dm_bufio_client *c, sector_t block
13681371
return sector;
13691372
}
13701373

1371-
static void submit_io(struct dm_buffer *b, enum req_op op,
1374+
static void submit_io(struct dm_buffer *b, enum req_op op, unsigned short ioprio,
13721375
void (*end_io)(struct dm_buffer *, blk_status_t))
13731376
{
13741377
unsigned int n_sectors;
@@ -1398,9 +1401,9 @@ static void submit_io(struct dm_buffer *b, enum req_op op,
13981401
}
13991402

14001403
if (b->data_mode != DATA_MODE_VMALLOC)
1401-
use_bio(b, op, sector, n_sectors, offset);
1404+
use_bio(b, op, sector, n_sectors, offset, ioprio);
14021405
else
1403-
use_dmio(b, op, sector, n_sectors, offset);
1406+
use_dmio(b, op, sector, n_sectors, offset, ioprio);
14041407
}
14051408

14061409
/*
@@ -1456,7 +1459,7 @@ static void __write_dirty_buffer(struct dm_buffer *b,
14561459
b->write_end = b->dirty_end;
14571460

14581461
if (!write_list)
1459-
submit_io(b, REQ_OP_WRITE, write_endio);
1462+
submit_io(b, REQ_OP_WRITE, IOPRIO_DEFAULT, write_endio);
14601463
else
14611464
list_add_tail(&b->write_list, write_list);
14621465
}
@@ -1470,7 +1473,7 @@ static void __flush_write_list(struct list_head *write_list)
14701473
struct dm_buffer *b =
14711474
list_entry(write_list->next, struct dm_buffer, write_list);
14721475
list_del(&b->write_list);
1473-
submit_io(b, REQ_OP_WRITE, write_endio);
1476+
submit_io(b, REQ_OP_WRITE, IOPRIO_DEFAULT, write_endio);
14741477
cond_resched();
14751478
}
14761479
blk_finish_plug(&plug);
@@ -1852,7 +1855,8 @@ static void read_endio(struct dm_buffer *b, blk_status_t status)
18521855
* and uses dm_bufio_mark_buffer_dirty to write new data back).
18531856
*/
18541857
static void *new_read(struct dm_bufio_client *c, sector_t block,
1855-
enum new_flag nf, struct dm_buffer **bp)
1858+
enum new_flag nf, struct dm_buffer **bp,
1859+
unsigned short ioprio)
18561860
{
18571861
int need_submit = 0;
18581862
struct dm_buffer *b;
@@ -1905,7 +1909,7 @@ static void *new_read(struct dm_bufio_client *c, sector_t block,
19051909
return NULL;
19061910

19071911
if (need_submit)
1908-
submit_io(b, REQ_OP_READ, read_endio);
1912+
submit_io(b, REQ_OP_READ, ioprio, read_endio);
19091913

19101914
if (nf != NF_GET) /* we already tested this condition above */
19111915
wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE);
@@ -1926,32 +1930,46 @@ static void *new_read(struct dm_bufio_client *c, sector_t block,
19261930
void *dm_bufio_get(struct dm_bufio_client *c, sector_t block,
19271931
struct dm_buffer **bp)
19281932
{
1929-
return new_read(c, block, NF_GET, bp);
1933+
return new_read(c, block, NF_GET, bp, IOPRIO_DEFAULT);
19301934
}
19311935
EXPORT_SYMBOL_GPL(dm_bufio_get);
19321936

1933-
void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
1934-
struct dm_buffer **bp)
1937+
static void *__dm_bufio_read(struct dm_bufio_client *c, sector_t block,
1938+
struct dm_buffer **bp, unsigned short ioprio)
19351939
{
19361940
if (WARN_ON_ONCE(dm_bufio_in_request()))
19371941
return ERR_PTR(-EINVAL);
19381942

1939-
return new_read(c, block, NF_READ, bp);
1943+
return new_read(c, block, NF_READ, bp, ioprio);
1944+
}
1945+
1946+
void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
1947+
struct dm_buffer **bp)
1948+
{
1949+
return __dm_bufio_read(c, block, bp, IOPRIO_DEFAULT);
19401950
}
19411951
EXPORT_SYMBOL_GPL(dm_bufio_read);
19421952

1953+
void *dm_bufio_read_with_ioprio(struct dm_bufio_client *c, sector_t block,
1954+
struct dm_buffer **bp, unsigned short ioprio)
1955+
{
1956+
return __dm_bufio_read(c, block, bp, ioprio);
1957+
}
1958+
EXPORT_SYMBOL_GPL(dm_bufio_read_with_ioprio);
1959+
19431960
void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
19441961
struct dm_buffer **bp)
19451962
{
19461963
if (WARN_ON_ONCE(dm_bufio_in_request()))
19471964
return ERR_PTR(-EINVAL);
19481965

1949-
return new_read(c, block, NF_FRESH, bp);
1966+
return new_read(c, block, NF_FRESH, bp, IOPRIO_DEFAULT);
19501967
}
19511968
EXPORT_SYMBOL_GPL(dm_bufio_new);
19521969

1953-
void dm_bufio_prefetch(struct dm_bufio_client *c,
1954-
sector_t block, unsigned int n_blocks)
1970+
static void __dm_bufio_prefetch(struct dm_bufio_client *c,
1971+
sector_t block, unsigned int n_blocks,
1972+
unsigned short ioprio)
19551973
{
19561974
struct blk_plug plug;
19571975

@@ -1987,7 +2005,7 @@ void dm_bufio_prefetch(struct dm_bufio_client *c,
19872005
dm_bufio_unlock(c);
19882006

19892007
if (need_submit)
1990-
submit_io(b, REQ_OP_READ, read_endio);
2008+
submit_io(b, REQ_OP_READ, ioprio, read_endio);
19912009
dm_bufio_release(b);
19922010

19932011
cond_resched();
@@ -2002,8 +2020,20 @@ void dm_bufio_prefetch(struct dm_bufio_client *c,
20022020
flush_plug:
20032021
blk_finish_plug(&plug);
20042022
}
2023+
2024+
void dm_bufio_prefetch(struct dm_bufio_client *c, sector_t block, unsigned int n_blocks)
2025+
{
2026+
return __dm_bufio_prefetch(c, block, n_blocks, IOPRIO_DEFAULT);
2027+
}
20052028
EXPORT_SYMBOL_GPL(dm_bufio_prefetch);
20062029

2030+
void dm_bufio_prefetch_with_ioprio(struct dm_bufio_client *c, sector_t block,
2031+
unsigned int n_blocks, unsigned short ioprio)
2032+
{
2033+
return __dm_bufio_prefetch(c, block, n_blocks, ioprio);
2034+
}
2035+
EXPORT_SYMBOL_GPL(dm_bufio_prefetch_with_ioprio);
2036+
20072037
void dm_bufio_release(struct dm_buffer *b)
20082038
{
20092039
struct dm_bufio_client *c = b->c;

include/linux/dm-bufio.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ void dm_bufio_set_sector_offset(struct dm_bufio_client *c, sector_t start);
6464
void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
6565
struct dm_buffer **bp);
6666

67+
void *dm_bufio_read_with_ioprio(struct dm_bufio_client *c, sector_t block,
68+
struct dm_buffer **bp, unsigned short ioprio);
69+
6770
/*
6871
* Like dm_bufio_read, but return buffer from cache, don't read
6972
* it. If the buffer is not in the cache, return NULL.
@@ -86,6 +89,10 @@ void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
8689
void dm_bufio_prefetch(struct dm_bufio_client *c,
8790
sector_t block, unsigned int n_blocks);
8891

92+
void dm_bufio_prefetch_with_ioprio(struct dm_bufio_client *c,
93+
sector_t block, unsigned int n_blocks,
94+
unsigned short ioprio);
95+
8996
/*
9097
* Release a reference obtained with dm_bufio_{read,get,new}. The data
9198
* pointer and dm_buffer pointer is no longer valid after this call.

0 commit comments

Comments
 (0)