Skip to content

Commit e082036

Browse files
xp4ns3richardweinberger
authored andcommitted
hostfs: Replace kmap() with kmap_local_page()
The use of kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as the mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Therefore, replace kmap() with kmap_local_page() in hostfs_kern.c, it being the only file with kmap() call sites currently left in fs/hostfs. Cc: "Venkataramanan, Anirudh" <anirudh.venkataramanan@intel.com> Suggested-by: Ira Weiny <ira.weiny@intel.com> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 28b2bb0 commit e082036

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/hostfs/hostfs_kern.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
412412
if (page->index >= end_index)
413413
count = inode->i_size & (PAGE_SIZE-1);
414414

415-
buffer = kmap(page);
415+
buffer = kmap_local_page(page);
416416

417417
err = write_file(HOSTFS_I(inode)->fd, &base, buffer, count);
418418
if (err != count) {
@@ -428,9 +428,9 @@ static int hostfs_writepage(struct page *page, struct writeback_control *wbc)
428428
err = 0;
429429

430430
out:
431-
kunmap(page);
432-
431+
kunmap_local(buffer);
433432
unlock_page(page);
433+
434434
return err;
435435
}
436436

@@ -441,7 +441,7 @@ static int hostfs_read_folio(struct file *file, struct folio *folio)
441441
loff_t start = page_offset(page);
442442
int bytes_read, ret = 0;
443443

444-
buffer = kmap(page);
444+
buffer = kmap_local_page(page);
445445
bytes_read = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
446446
PAGE_SIZE);
447447
if (bytes_read < 0) {
@@ -458,8 +458,9 @@ static int hostfs_read_folio(struct file *file, struct folio *folio)
458458

459459
out:
460460
flush_dcache_page(page);
461-
kunmap(page);
461+
kunmap_local(buffer);
462462
unlock_page(page);
463+
463464
return ret;
464465
}
465466

@@ -484,9 +485,9 @@ static int hostfs_write_end(struct file *file, struct address_space *mapping,
484485
unsigned from = pos & (PAGE_SIZE - 1);
485486
int err;
486487

487-
buffer = kmap(page);
488+
buffer = kmap_local_page(page);
488489
err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied);
489-
kunmap(page);
490+
kunmap_local(buffer);
490491

491492
if (!PageUptodate(page) && err == PAGE_SIZE)
492493
SetPageUptodate(page);

0 commit comments

Comments
 (0)