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

mm/migrate: optimize migrate_vma_setup() for holes

Patch series "mm/migrate: optimize migrate_vma_setup() for holes".

A simple optimization for migrate_vma_*() when the source vma is not an
anonymous vma and a new test case to exercise it.

This patch (of 2):

When migrating system memory to device private memory, if the source
address range is a valid VMA range and there is no memory or a zero page,
the source PFN array is marked as valid but with no PFN.

This lets the device driver allocate private memory and clear it, then
insert the new device private struct page into the CPU's page tables when
migrate_vma_pages() is called. migrate_vma_pages() only inserts the new
page if the VMA is an anonymous range.

There is no point in telling the device driver to allocate device private
memory and then not migrate the page. Instead, mark the source PFN array
entries as not migrating to avoid this overhead.

[rcampbell@nvidia.com: v2]
Link: http://lkml.kernel.org/r/20200710194840.7602-2-rcampbell@nvidia.com

Signed-off-by: Ralph Campbell <rcampbell@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: "Bharata B Rao" <bharata@linux.ibm.com>
Cc: Shuah Khan <shuah@kernel.org>
Link: http://lkml.kernel.org/r/20200710194840.7602-1-rcampbell@nvidia.com
Link: http://lkml.kernel.org/r/20200709165711.26584-1-rcampbell@nvidia.com
Link: http://lkml.kernel.org/r/20200709165711.26584-2-rcampbell@nvidia.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ralph Campbell and committed by
Linus Torvalds
0744f280 34ae204f

+14 -2
+14 -2
mm/migrate.c
··· 2168 2168 struct migrate_vma *migrate = walk->private; 2169 2169 unsigned long addr; 2170 2170 2171 + /* Only allow populating anonymous memory. */ 2172 + if (!vma_is_anonymous(walk->vma)) { 2173 + for (addr = start; addr < end; addr += PAGE_SIZE) { 2174 + migrate->src[migrate->npages] = 0; 2175 + migrate->dst[migrate->npages] = 0; 2176 + migrate->npages++; 2177 + } 2178 + return 0; 2179 + } 2180 + 2171 2181 for (addr = start; addr < end; addr += PAGE_SIZE) { 2172 2182 migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE; 2173 2183 migrate->dst[migrate->npages] = 0; ··· 2270 2260 pte = *ptep; 2271 2261 2272 2262 if (pte_none(pte)) { 2273 - mpfn = MIGRATE_PFN_MIGRATE; 2274 - migrate->cpages++; 2263 + if (vma_is_anonymous(vma)) { 2264 + mpfn = MIGRATE_PFN_MIGRATE; 2265 + migrate->cpages++; 2266 + } 2275 2267 goto next; 2276 2268 } 2277 2269