Commit 94efde1
mm/gup: avoid an unnecessary allocation call for FOLL_LONGTERM cases
commit 53ba78d ("mm/gup: introduce
check_and_migrate_movable_folios()") created a new constraint on the
pin_user_pages*() API family: a potentially large internal allocation must
now occur, for FOLL_LONGTERM cases.
A user-visible consequence has now appeared: user space can no longer pin
more than 2GB of memory anymore on x86_64. That's because, on a 4KB
PAGE_SIZE system, when user space tries to (indirectly, via a device
driver that calls pin_user_pages()) pin 2GB, this requires an allocation
of a folio pointers array of MAX_PAGE_ORDER size, which is the limit for
kmalloc().
In addition to the directly visible effect described above, there is also
the problem of adding an unnecessary allocation. The **pages array
argument has already been allocated, and there is no need for a redundant
**folios array allocation in this case.
Fix this by avoiding the new allocation entirely. This is done by
referring to either the original page[i] within **pages, or to the
associated folio. Thanks to David Hildenbrand for suggesting this
approach and for providing the initial implementation (which I've tested
and adjusted slightly) as well.
[[email protected]: whitespace tweak, per David]
Link: https://lkml.kernel.org/r/[email protected]
[[email protected]: bypass pofs_get_folio(), per Oscar]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Fixes: 53ba78d ("mm/gup: introduce check_and_migrate_movable_folios()")
Signed-off-by: John Hubbard <[email protected]>
Suggested-by: David Hildenbrand <[email protected]>
Acked-by: David Hildenbrand <[email protected]>
Reviewed-by: Oscar Salvador <[email protected]>
Cc: Vivek Kasireddy <[email protected]>
Cc: Dave Airlie <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Dongwon Kim <[email protected]>
Cc: Hugh Dickins <[email protected]>
Cc: Junxiao Chang <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>1 parent 247d720 commit 94efde1
1 file changed
+77
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2273 | 2273 | | |
2274 | 2274 | | |
2275 | 2275 | | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
| 2290 | + | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
2276 | 2314 | | |
2277 | 2315 | | |
2278 | 2316 | | |
2279 | 2317 | | |
2280 | | - | |
2281 | | - | |
2282 | | - | |
| 2318 | + | |
| 2319 | + | |
2283 | 2320 | | |
2284 | 2321 | | |
2285 | 2322 | | |
2286 | 2323 | | |
2287 | 2324 | | |
2288 | | - | |
2289 | | - | |
| 2325 | + | |
| 2326 | + | |
2290 | 2327 | | |
2291 | 2328 | | |
2292 | 2329 | | |
| |||
2327 | 2364 | | |
2328 | 2365 | | |
2329 | 2366 | | |
2330 | | - | |
2331 | | - | |
2332 | | - | |
2333 | | - | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
2334 | 2370 | | |
2335 | 2371 | | |
2336 | 2372 | | |
2337 | 2373 | | |
2338 | | - | |
2339 | | - | |
| 2374 | + | |
| 2375 | + | |
2340 | 2376 | | |
2341 | 2377 | | |
2342 | 2378 | | |
2343 | 2379 | | |
2344 | 2380 | | |
2345 | 2381 | | |
2346 | 2382 | | |
2347 | | - | |
| 2383 | + | |
2348 | 2384 | | |
2349 | 2385 | | |
2350 | 2386 | | |
| |||
2363 | 2399 | | |
2364 | 2400 | | |
2365 | 2401 | | |
2366 | | - | |
2367 | | - | |
| 2402 | + | |
| 2403 | + | |
2368 | 2404 | | |
2369 | 2405 | | |
2370 | 2406 | | |
| |||
2387 | 2423 | | |
2388 | 2424 | | |
2389 | 2425 | | |
2390 | | - | |
| 2426 | + | |
2391 | 2427 | | |
2392 | 2428 | | |
2393 | 2429 | | |
2394 | 2430 | | |
2395 | 2431 | | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
2396 | 2446 | | |
2397 | 2447 | | |
2398 | 2448 | | |
| |||
2417 | 2467 | | |
2418 | 2468 | | |
2419 | 2469 | | |
2420 | | - | |
2421 | | - | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
2422 | 2475 | | |
2423 | | - | |
2424 | | - | |
2425 | | - | |
2426 | | - | |
2427 | | - | |
2428 | | - | |
2429 | | - | |
| 2476 | + | |
2430 | 2477 | | |
2431 | 2478 | | |
2432 | 2479 | | |
| |||
2436 | 2483 | | |
2437 | 2484 | | |
2438 | 2485 | | |
2439 | | - | |
2440 | | - | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
2441 | 2491 | | |
2442 | | - | |
2443 | | - | |
2444 | | - | |
2445 | | - | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
2449 | | - | |
2450 | | - | |
2451 | | - | |
2452 | | - | |
2453 | | - | |
2454 | | - | |
| 2492 | + | |
2455 | 2493 | | |
2456 | 2494 | | |
2457 | 2495 | | |
| |||
0 commit comments