Skip to content

Commit f27c942

Browse files
xp4ns3Al Viro
authored andcommitted
fs/cramfs: Convert kmap() to kmap_local_data()
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. Since its use in fs/cramfs is safe everywhere, it should be preferred. Therefore, replace kmap() with kmap_local_page() in fs/cramfs. Instead of open-coding kmap_local_page() + memcpy(), use memcpy_from_page(). Cc: Alexander Viro <[email protected]> Cc: "Venkataramanan, Anirudh" <[email protected]> Suggested-by: Ira Weiny <[email protected]> Reviewed-by: Nicolas Pitre <[email protected]> Reviewed-by: Christian Brauner (Microsoft) <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Signed-off-by: Fabio M. De Francesco <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent b7bfaa7 commit f27c942

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/cramfs/inode.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ static void *cramfs_blkdev_read(struct super_block *sb, unsigned int offset,
238238
struct page *page = pages[i];
239239

240240
if (page) {
241-
memcpy(data, kmap(page), PAGE_SIZE);
242-
kunmap(page);
241+
memcpy_from_page(data, page, 0, PAGE_SIZE);
243242
put_page(page);
244243
} else
245244
memset(data, 0, PAGE_SIZE);
@@ -815,7 +814,7 @@ static int cramfs_read_folio(struct file *file, struct folio *folio)
815814

816815
maxblock = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
817816
bytes_filled = 0;
818-
pgdata = kmap(page);
817+
pgdata = kmap_local_page(page);
819818

820819
if (page->index < maxblock) {
821820
struct super_block *sb = inode->i_sb;
@@ -903,13 +902,13 @@ static int cramfs_read_folio(struct file *file, struct folio *folio)
903902

904903
memset(pgdata + bytes_filled, 0, PAGE_SIZE - bytes_filled);
905904
flush_dcache_page(page);
906-
kunmap(page);
905+
kunmap_local(pgdata);
907906
SetPageUptodate(page);
908907
unlock_page(page);
909908
return 0;
910909

911910
err:
912-
kunmap(page);
911+
kunmap_local(pgdata);
913912
ClearPageUptodate(page);
914913
SetPageError(page);
915914
unlock_page(page);

0 commit comments

Comments
 (0)