* vm_object_madvise: * * Implements the madvise function at the object/page level. * * MADV_WILLNEED (any object) * * Activate the specified pages if they are resident. * * MADV_DONTNEED (any object) * * Deactivate the specified pages if they are resident. * * MADV_FREE (OBJT_DEFAULT/OBJT_SWAP objects, * OBJ_ONEMAPPING only) * * Deactivate and clean the specified page
| 1302 | * without I/O. |
| 1303 | */ |
| 1304 | void |
| 1305 | vm_object_madvise(vm_object_t object, vm_pindex_t pindex, vm_pindex_t end, |
| 1306 | int advice) |
| 1307 | { |
| 1308 | vm_pindex_t tpindex; |
| 1309 | vm_object_t backing_object, tobject; |
| 1310 | vm_page_t m, tm; |
| 1311 | |
| 1312 | if (object == NULL) |
| 1313 | return; |
| 1314 | |
| 1315 | relookup: |
| 1316 | VM_OBJECT_WLOCK(object); |
| 1317 | if (!vm_object_advice_applies(object, advice)) { |
| 1318 | VM_OBJECT_WUNLOCK(object); |
| 1319 | return; |
| 1320 | } |
| 1321 | for (m = vm_page_find_least(object, pindex); pindex < end; pindex++) { |
| 1322 | tobject = object; |
| 1323 | |
| 1324 | /* |
| 1325 | * If the next page isn't resident in the top-level object, we |
| 1326 | * need to search the shadow chain. When applying MADV_FREE, we |
| 1327 | * take care to release any swap space used to store |
| 1328 | * non-resident pages. |
| 1329 | */ |
| 1330 | if (m == NULL || pindex < m->pindex) { |
| 1331 | /* |
| 1332 | * Optimize a common case: if the top-level object has |
| 1333 | * no backing object, we can skip over the non-resident |
| 1334 | * range in constant time. |
| 1335 | */ |
| 1336 | if (object->backing_object == NULL) { |
| 1337 | tpindex = (m != NULL && m->pindex < end) ? |
| 1338 | m->pindex : end; |
| 1339 | vm_object_madvise_freespace(object, advice, |
| 1340 | pindex, tpindex - pindex); |
| 1341 | if ((pindex = tpindex) == end) |
| 1342 | break; |
| 1343 | goto next_page; |
| 1344 | } |
| 1345 | |
| 1346 | tpindex = pindex; |
| 1347 | do { |
| 1348 | vm_object_madvise_freespace(tobject, advice, |
| 1349 | tpindex, 1); |
| 1350 | /* |
| 1351 | * Prepare to search the next object in the |
| 1352 | * chain. |
| 1353 | */ |
| 1354 | backing_object = tobject->backing_object; |
| 1355 | if (backing_object == NULL) |
| 1356 | goto next_pindex; |
| 1357 | VM_OBJECT_WLOCK(backing_object); |
| 1358 | tpindex += |
| 1359 | OFF_TO_IDX(tobject->backing_object_offset); |
| 1360 | if (tobject != object) |
| 1361 | VM_OBJECT_WUNLOCK(tobject); |
no test coverage detected