Commit 2452626
mm: mempolicy: keep VMA walk if both MPOL_MF_STRICT and MPOL_MF_MOVE are specified
When calling mbind() with MPOL_MF_{MOVE|MOVEALL} | MPOL_MF_STRICT, kernel
should attempt to migrate all existing pages, and return -EIO if there is
misplaced or unmovable page. Then commit 6f4576e ("mempolicy: apply
page table walker on queue_pages_range()") messed up the return value and
didn't break VMA scan early ianymore when MPOL_MF_STRICT alone. The
return value problem was fixed by commit a7f40cf ("mm: mempolicy:
make mbind() return -EIO when MPOL_MF_STRICT is specified"), but it broke
the VMA walk early if unmovable page is met, it may cause some pages are
not migrated as expected.
The code should conceptually do:
if (MPOL_MF_MOVE|MOVEALL)
scan all vmas
try to migrate the existing pages
return success
else if (MPOL_MF_MOVE* | MPOL_MF_STRICT)
scan all vmas
try to migrate the existing pages
return -EIO if unmovable or migration failed
else /* MPOL_MF_STRICT alone */
break early if meets unmovable and don't call mbind_range() at all
else /* none of those flags */
check the ranges in test_walk, EFAULT without mbind_range() if discontig.
Fixed the behavior.
Link: https://lkml.kernel.org/r/20230920223242.3425775-1-yang@os.amperecomputing.com
Fixes: a7f40cf ("mm: mempolicy: make mbind() return -EIO when MPOL_MF_STRICT is specified")
Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: David Rientjes <rientjes@google.com>
Cc: <stable@vger.kernel.org> [4.9+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>1 parent 45120b1 commit 2452626
1 file changed
+19
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
| |||
446 | 447 | | |
447 | 448 | | |
448 | 449 | | |
449 | | - | |
450 | | - | |
451 | | - | |
| 450 | + | |
| 451 | + | |
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
| |||
479 | 479 | | |
480 | 480 | | |
481 | 481 | | |
482 | | - | |
| 482 | + | |
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | | - | |
499 | | - | |
500 | | - | |
| 498 | + | |
| 499 | + | |
501 | 500 | | |
502 | 501 | | |
503 | 502 | | |
| |||
508 | 507 | | |
509 | 508 | | |
510 | 509 | | |
511 | | - | |
512 | 510 | | |
513 | 511 | | |
514 | 512 | | |
| |||
538 | 536 | | |
539 | 537 | | |
540 | 538 | | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
546 | 545 | | |
547 | 546 | | |
548 | 547 | | |
549 | 548 | | |
550 | 549 | | |
551 | 550 | | |
552 | 551 | | |
553 | | - | |
| 552 | + | |
554 | 553 | | |
555 | 554 | | |
556 | 555 | | |
557 | 556 | | |
558 | 557 | | |
559 | 558 | | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | 559 | | |
564 | 560 | | |
565 | 561 | | |
| |||
599 | 595 | | |
600 | 596 | | |
601 | 597 | | |
602 | | - | |
| 598 | + | |
603 | 599 | | |
604 | 600 | | |
605 | 601 | | |
| |||
620 | 616 | | |
621 | 617 | | |
622 | 618 | | |
623 | | - | |
| 619 | + | |
624 | 620 | | |
625 | 621 | | |
626 | 622 | | |
| |||
756 | 752 | | |
757 | 753 | | |
758 | 754 | | |
| 755 | + | |
759 | 756 | | |
760 | 757 | | |
761 | 758 | | |
762 | 759 | | |
763 | 760 | | |
764 | 761 | | |
| 762 | + | |
| 763 | + | |
765 | 764 | | |
766 | 765 | | |
767 | 766 | | |
| |||
1358 | 1357 | | |
1359 | 1358 | | |
1360 | 1359 | | |
1361 | | - | |
| 1360 | + | |
1362 | 1361 | | |
1363 | 1362 | | |
1364 | 1363 | | |
| |||
0 commit comments