Commit 72e315f
mempolicy: mmap_lock is not needed while migrating folios
mbind(2) holds down_write of current task's mmap_lock throughout
(exclusive because it needs to set the new mempolicy on the vmas);
migrate_pages(2) holds down_read of pid's mmap_lock throughout.
They both hold mmap_lock across the internal migrate_pages(), under which
all new page allocations (huge or small) are made. I'm nervous about it;
and migrate_pages() certainly does not need mmap_lock itself. It's done
this way for mbind(2), because its page allocator is vma_alloc_folio() or
alloc_hugetlb_folio_vma(), both of which depend on vma and address.
Now that we have alloc_pages_mpol(), depending on (refcounted) memory
policy and interleave index, mbind(2) can be modified to use that or
alloc_hugetlb_folio_nodemask(), and then not need mmap_lock across the
internal migrate_pages() at all: add alloc_migration_target_by_mpol() to
replace mbind's new_page().
(After that change, alloc_hugetlb_folio_vma() is used by nothing but a
userfaultfd function: move it out of hugetlb.h and into the #ifdef.)
migrate_pages(2) has chosen its target node before migrating, so can
continue to use the standard alloc_migration_target(); but let it take and
drop mmap_lock just around migrate_to_node()'s queue_pages_range():
neither the node-to-node calculations nor the page migrations need it.
It seems unlikely, but it is conceivable that some userspace depends on
the kernel's mmap_lock exclusion here, instead of doing its own locking:
more likely in a testsuite than in real life. It is also possible, of
course, that some pages on the list will be munmapped by another thread
before they are migrated, or a newer memory policy applied to the range by
that time: but such races could happen before, as soon as mmap_lock was
dropped, so it does not appear to be a concern.
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Hugh Dickins <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Huang, Ying" <[email protected]>
Cc: Kefeng Wang <[email protected]>
Cc: Matthew Wilcox (Oracle) <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Mike Kravetz <[email protected]>
Cc: Nhat Pham <[email protected]>
Cc: Sidhartha Kumar <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Tejun heo <[email protected]>
Cc: Vishal Moola (Oracle) <[email protected]>
Cc: Yang Shi <[email protected]>
Cc: Yosry Ahmed <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>1 parent ddc1a5c commit 72e315f
3 files changed
+63
-67
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
748 | 748 | | |
749 | 749 | | |
750 | 750 | | |
751 | | - | |
752 | | - | |
753 | 751 | | |
754 | 752 | | |
755 | 753 | | |
| |||
1072 | 1070 | | |
1073 | 1071 | | |
1074 | 1072 | | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
1082 | 1073 | | |
1083 | 1074 | | |
1084 | 1075 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2630 | 2630 | | |
2631 | 2631 | | |
2632 | 2632 | | |
2633 | | - | |
2634 | | - | |
2635 | | - | |
2636 | | - | |
2637 | | - | |
2638 | | - | |
2639 | | - | |
2640 | | - | |
2641 | | - | |
2642 | | - | |
2643 | | - | |
2644 | | - | |
2645 | | - | |
2646 | | - | |
2647 | | - | |
2648 | | - | |
2649 | | - | |
2650 | | - | |
2651 | 2633 | | |
2652 | 2634 | | |
2653 | 2635 | | |
| |||
6559 | 6541 | | |
6560 | 6542 | | |
6561 | 6543 | | |
| 6544 | + | |
| 6545 | + | |
| 6546 | + | |
| 6547 | + | |
| 6548 | + | |
| 6549 | + | |
| 6550 | + | |
| 6551 | + | |
| 6552 | + | |
| 6553 | + | |
| 6554 | + | |
| 6555 | + | |
| 6556 | + | |
| 6557 | + | |
| 6558 | + | |
| 6559 | + | |
| 6560 | + | |
| 6561 | + | |
| 6562 | + | |
| 6563 | + | |
6562 | 6564 | | |
6563 | 6565 | | |
6564 | 6566 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
| 418 | + | |
| 419 | + | |
418 | 420 | | |
419 | 421 | | |
420 | 422 | | |
| |||
1021 | 1023 | | |
1022 | 1024 | | |
1023 | 1025 | | |
| 1026 | + | |
| 1027 | + | |
1024 | 1028 | | |
1025 | 1029 | | |
1026 | 1030 | | |
| |||
1031 | 1035 | | |
1032 | 1036 | | |
1033 | 1037 | | |
| 1038 | + | |
1034 | 1039 | | |
1035 | 1040 | | |
1036 | 1041 | | |
| |||
1059 | 1064 | | |
1060 | 1065 | | |
1061 | 1066 | | |
1062 | | - | |
1063 | | - | |
1064 | 1067 | | |
1065 | 1068 | | |
1066 | 1069 | | |
| |||
1140 | 1143 | | |
1141 | 1144 | | |
1142 | 1145 | | |
1143 | | - | |
1144 | 1146 | | |
1145 | 1147 | | |
1146 | 1148 | | |
| |||
1149 | 1151 | | |
1150 | 1152 | | |
1151 | 1153 | | |
1152 | | - | |
1153 | | - | |
1154 | | - | |
1155 | | - | |
1156 | | - | |
| 1154 | + | |
1157 | 1155 | | |
1158 | | - | |
| 1156 | + | |
| 1157 | + | |
1159 | 1158 | | |
1160 | | - | |
1161 | | - | |
1162 | | - | |
1163 | | - | |
1164 | | - | |
1165 | | - | |
1166 | | - | |
1167 | | - | |
1168 | | - | |
1169 | | - | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1170 | 1165 | | |
1171 | | - | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
| 1166 | + | |
| 1167 | + | |
1179 | 1168 | | |
1180 | 1169 | | |
1181 | | - | |
1182 | | - | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
1183 | 1177 | | |
1184 | 1178 | | |
1185 | 1179 | | |
1186 | 1180 | | |
| 1181 | + | |
| 1182 | + | |
1187 | 1183 | | |
1188 | | - | |
1189 | | - | |
| 1184 | + | |
| 1185 | + | |
1190 | 1186 | | |
1191 | 1187 | | |
1192 | 1188 | | |
| |||
1202 | 1198 | | |
1203 | 1199 | | |
1204 | 1200 | | |
1205 | | - | |
| 1201 | + | |
| 1202 | + | |
1206 | 1203 | | |
1207 | 1204 | | |
1208 | 1205 | | |
| |||
1276 | 1273 | | |
1277 | 1274 | | |
1278 | 1275 | | |
| 1276 | + | |
1279 | 1277 | | |
1280 | 1278 | | |
1281 | 1279 | | |
| |||
1286 | 1284 | | |
1287 | 1285 | | |
1288 | 1286 | | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
1293 | 1294 | | |
1294 | | - | |
1295 | | - | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
1296 | 1299 | | |
1297 | 1300 | | |
| 1301 | + | |
| 1302 | + | |
1298 | 1303 | | |
1299 | 1304 | | |
1300 | | - | |
1301 | | - | |
1302 | 1305 | | |
1303 | 1306 | | |
1304 | 1307 | | |
| |||
0 commit comments