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: refactor vma_map_pages to use vm_insert_pages

vma_map_pages currently calls vm_insert_page on each individual page in
the mapping, which creates significant overhead because we are repeatedly
spinlocking. Instead, we should batch insert pages using vm_insert_pages,
which amortizes the cost of the spinlock.

Tested through watching hardware accelerated video on a MTK ChromeOS
device. This particular path maps both a V4L2 buffer and a GEM allocated
buffer into userspace and converts the contents from one pixel format to
another. Both vb2_mmap() and mtk_gem_object_mmap() exercise this pathway.

Link: https://lkml.kernel.org/r/20260128225648.2938636-1-greenjustin@chromium.org
Signed-off-by: Justin Green <greenjustin@chromium.org>
Acked-by: Brian Geffon <bgeffon@google.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Arjun Roy <arjunroy@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Justin Green and committed by
Andrew Morton
cc5cbf37 9a2791e7

+1 -9
+1 -9
mm/memory.c
··· 2499 2499 { 2500 2500 unsigned long count = vma_pages(vma); 2501 2501 unsigned long uaddr = vma->vm_start; 2502 - int ret, i; 2503 2502 2504 2503 /* Fail if the user requested offset is beyond the end of the object */ 2505 2504 if (offset >= num) ··· 2508 2509 if (count > num - offset) 2509 2510 return -ENXIO; 2510 2511 2511 - for (i = 0; i < count; i++) { 2512 - ret = vm_insert_page(vma, uaddr, pages[offset + i]); 2513 - if (ret < 0) 2514 - return ret; 2515 - uaddr += PAGE_SIZE; 2516 - } 2517 - 2518 - return 0; 2512 + return vm_insert_pages(vma, uaddr, pages + offset, &count); 2519 2513 } 2520 2514 2521 2515 /**