mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	lib: replace kmap() with kmap_local_page()
kmap() has been deprecated in favor of the 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() is faster than kmap() and offers thread-local and CPU-local mappings, take pagefaults in a local kmap region and preserves preemption by saving the mappings of outgoing tasks and restoring those of the incoming one during a context switch. The mappings are kept thread local in the functions “dmirror_do_read” and “dmirror_do_write” in test_hmm.c Therefore, replace kmap() with kmap_local_page() and use mempcy_from/to_page() to avoid open coding kmap_local_page() + memcpy() + kunmap_local(). Remove the unused variable “tmp”. Link: https://lkml.kernel.org/r/20230610175712.GA348514@sumitra.com Signed-off-by: Sumitra Sharma <sumitraartsy@gmail.com> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Cc: Deepak R Varma <drv@mailo.com> Cc: Jérôme Glisse <jglisse@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									f58a2dd8d5
								
							
						
					
					
						commit
						ae96e0cdc7
					
				
					 1 changed files with 2 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -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(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, ptr, PAGE_SIZE);
 | 
			
		||||
 | 
			
		||||
		ptr += PAGE_SIZE;
 | 
			
		||||
		bounce->cpages++;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue