Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/memory: replace kmap() with kmap_local_page()

kmap() has been deprecated in favor of kmap_local_page().

Therefore, replace kmap() with kmap_local_page() in mm/memory.c.

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. The tasks can
be preempted and, when they are scheduled to run again, the kernel virtual
addresses are restored and still valid.

Obviously, thread locality implies that the kernel virtual addresses
returned by kmap_local_page() are only valid in the context of the callers
(i.e., they cannot be handed to other threads).

The use of kmap_local_page() in mm/memory.c does not break the
above-mentioned assumption, so it is allowed and preferred.

Link: https://lkml.kernel.org/r/20231215084417.2002370-1-fabio.maria.de.francesco@linux.intel.com
Link: https://lkml.kernel.org/r/20231214081039.1919328-1-fabio.maria.de.francesco@linux.intel.com
Signed-off-by: Fabio M. De Francesco <fabio.maria.de.francesco@linux.intel.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Fabio M. De Francesco and committed by
Andrew Morton
f7ef5fe7 0abfa8ef

+2 -3
+2 -3
mm/memory.c
··· 5944 5944 if (bytes > PAGE_SIZE-offset) 5945 5945 bytes = PAGE_SIZE-offset; 5946 5946 5947 - maddr = kmap(page); 5947 + maddr = kmap_local_page(page); 5948 5948 if (write) { 5949 5949 copy_to_user_page(vma, page, addr, 5950 5950 maddr + offset, buf, bytes); ··· 5953 5953 copy_from_user_page(vma, page, addr, 5954 5954 buf, maddr + offset, bytes); 5955 5955 } 5956 - kunmap(page); 5957 - put_page(page); 5956 + unmap_and_put_page(page, maddr); 5958 5957 } 5959 5958 len -= bytes; 5960 5959 buf += bytes;