staging: lib: Use memcpy_to/from_page()
PATCH 1/1 staging: lib: Use memcpy_to/from_page()
Deprecate kmap() in favor of kmap_local_page() due to high cost, restricted mapping space, the overhead of a global lock for synchronization, and making the process sleep in the absence of free slots.
kmap_local_page() offers thread-local and CPU-local mappings, take pagefaults in a local kmap region and preserves preemption by saving the mappings of outgoing task and restoring those of the incoming one during a context switch.
It is faster than kmap(), and in functions "dmirror_do_read" and "dmirror_do_write" the mappings are kept local to the thread.
Therefore, replace kmap/mem*()/kunmap pattern with memcpy_to/from_page() and remove the unused variable "tmp".
Signed-off-by Sumitra Sharma <[email protected]>
---
Suggested-by Fabio M. De Francesco <[email protected]>
lib/test_hmm.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
lib/test_hmm.c +2 -8
@@ -368,16 +368,13 @@ static int dmirror_do_read(struct dmirror *dmirror, unsigned long start,for (pfn = start >>PAGE_SHIFT ; pfn < (end >>PAGE_SHIFT ); pfn++) {void *entry;struct page *page; -void *tmp; entry =xa_load (&dmirror->pt, pfn); page =xa_untag_pointer (entry);if (!page)return -ENOENT ; - tmp =kmap (page); -memcpy (ptr, tmp,PAGE_SIZE ); -kunmap (page); +memcpy_from_page ((char *)ptr, page,0 ,PAGE_SIZE ); ptr +=PAGE_SIZE ; bounce->cpages++;
@@ -437,16 +434,13 @@ static int dmirror_do_write(struct dmirror *dmirror, unsigned long start,for (pfn = start >>PAGE_SHIFT ; pfn < (end >>PAGE_SHIFT ); pfn++) {void *entry;struct page *page; -void *tmp; entry =xa_load (&dmirror->pt, pfn); page =xa_untag_pointer (entry);if (!page ||xa_pointer_tag (entry) !=DPT_XA_TAG_WRITE )return -ENOENT ; - tmp =kmap (page); -memcpy (tmp, ptr,PAGE_SIZE ); -kunmap (page); +memcpy_to_page (page,0 , (char *)ptr,PAGE_SIZE ); ptr +=PAGE_SIZE ; bounce->cpages++;
Signature · 1 line
2.25.1