Skip to content

Commit 262a3dd

Browse files
keithbuschaxboe
authored andcommitted
null_blk: single kmap per bio segment
Rather than kmap the the request bio segment for each sector, do the mapping just once. Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Damien Le Moal <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Tested-by: Hans Holmberg <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8459283 commit 262a3dd

1 file changed

Lines changed: 14 additions & 18 deletions

File tree

drivers/block/null_blk/main.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,8 +1129,8 @@ static int null_make_cache_space(struct nullb *nullb, unsigned long n)
11291129
return 0;
11301130
}
11311131

1132-
static blk_status_t copy_to_nullb(struct nullb *nullb, struct page *source,
1133-
unsigned int off, sector_t sector, size_t n, bool is_fua)
1132+
static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
1133+
sector_t sector, size_t n, bool is_fua)
11341134
{
11351135
size_t temp, count = 0;
11361136
unsigned int offset;
@@ -1148,7 +1148,7 @@ static blk_status_t copy_to_nullb(struct nullb *nullb, struct page *source,
11481148
if (!t_page)
11491149
return BLK_STS_NOSPC;
11501150

1151-
memcpy_page(t_page->page, offset, source, off + count, temp);
1151+
memcpy_to_page(t_page->page, offset, source + count, temp);
11521152

11531153
__set_bit(sector & SECTOR_MASK, t_page->bitmap);
11541154

@@ -1161,8 +1161,8 @@ static blk_status_t copy_to_nullb(struct nullb *nullb, struct page *source,
11611161
return BLK_STS_OK;
11621162
}
11631163

1164-
static void copy_from_nullb(struct nullb *nullb, struct page *dest,
1165-
unsigned int off, sector_t sector, size_t n)
1164+
static void copy_from_nullb(struct nullb *nullb, void *dest, sector_t sector,
1165+
size_t n)
11661166
{
11671167
size_t temp, count = 0;
11681168
unsigned int offset;
@@ -1176,22 +1176,16 @@ static void copy_from_nullb(struct nullb *nullb, struct page *dest,
11761176
!null_cache_active(nullb));
11771177

11781178
if (t_page)
1179-
memcpy_page(dest, off + count, t_page->page, offset,
1180-
temp);
1179+
memcpy_from_page(dest + count, t_page->page, offset,
1180+
temp);
11811181
else
1182-
memzero_page(dest, off + count, temp);
1182+
memset(dest + count, 0, temp);
11831183

11841184
count += temp;
11851185
sector += temp >> SECTOR_SHIFT;
11861186
}
11871187
}
11881188

1189-
static void nullb_fill_pattern(struct nullb *nullb, struct page *page,
1190-
unsigned int len, unsigned int off)
1191-
{
1192-
memset_page(page, off, 0xff, len);
1193-
}
1194-
11951189
blk_status_t null_handle_discard(struct nullb_device *dev,
11961190
sector_t sector, sector_t nr_sectors)
11971191
{
@@ -1240,27 +1234,29 @@ static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
12401234
struct nullb_device *dev = nullb->dev;
12411235
blk_status_t err = BLK_STS_OK;
12421236
unsigned int valid_len = len;
1237+
void *p;
12431238

1239+
p = kmap_local_page(page) + off;
12441240
if (!is_write) {
12451241
if (dev->zoned)
12461242
valid_len = null_zone_valid_read_len(nullb,
12471243
sector, len);
12481244

12491245
if (valid_len) {
1250-
copy_from_nullb(nullb, page, off, sector,
1251-
valid_len);
1246+
copy_from_nullb(nullb, p, sector, valid_len);
12521247
off += valid_len;
12531248
len -= valid_len;
12541249
}
12551250

12561251
if (len)
1257-
nullb_fill_pattern(nullb, page, len, off);
1252+
memset(p + valid_len, 0xff, len);
12581253
flush_dcache_page(page);
12591254
} else {
12601255
flush_dcache_page(page);
1261-
err = copy_to_nullb(nullb, page, off, sector, len, is_fua);
1256+
err = copy_to_nullb(nullb, p, sector, len, is_fua);
12621257
}
12631258

1259+
kunmap_local(p);
12641260
return err;
12651261
}
12661262

0 commit comments

Comments
 (0)