* We dropped a reference on an object and discovered that it had a * single remaining shadow. This is a sibling of the reference we * dropped. Attempt to collapse the sibling and backing object. */
| 563 | * dropped. Attempt to collapse the sibling and backing object. |
| 564 | */ |
| 565 | static vm_object_t |
| 566 | vm_object_deallocate_anon(vm_object_t backing_object) |
| 567 | { |
| 568 | vm_object_t object; |
| 569 | |
| 570 | /* Fetch the final shadow. */ |
| 571 | object = LIST_FIRST(&backing_object->shadow_head); |
| 572 | KASSERT(object != NULL && backing_object->shadow_count == 1, |
| 573 | ("vm_object_anon_deallocate: ref_count: %d, shadow_count: %d", |
| 574 | backing_object->ref_count, backing_object->shadow_count)); |
| 575 | KASSERT((object->flags & (OBJ_TMPFS_NODE | OBJ_ANON)) == OBJ_ANON, |
| 576 | ("invalid shadow object %p", object)); |
| 577 | |
| 578 | if (!VM_OBJECT_TRYWLOCK(object)) { |
| 579 | /* |
| 580 | * Prevent object from disappearing since we do not have a |
| 581 | * reference. |
| 582 | */ |
| 583 | vm_object_pip_add(object, 1); |
| 584 | VM_OBJECT_WUNLOCK(backing_object); |
| 585 | VM_OBJECT_WLOCK(object); |
| 586 | vm_object_pip_wakeup(object); |
| 587 | } else |
| 588 | VM_OBJECT_WUNLOCK(backing_object); |
| 589 | |
| 590 | /* |
| 591 | * Check for a collapse/terminate race with the last reference holder. |
| 592 | */ |
| 593 | if ((object->flags & (OBJ_DEAD | OBJ_COLLAPSING)) != 0 || |
| 594 | !refcount_acquire_if_not_zero(&object->ref_count)) { |
| 595 | VM_OBJECT_WUNLOCK(object); |
| 596 | return (NULL); |
| 597 | } |
| 598 | backing_object = object->backing_object; |
| 599 | if (backing_object != NULL && (backing_object->flags & OBJ_ANON) != 0) |
| 600 | vm_object_collapse(object); |
| 601 | VM_OBJECT_WUNLOCK(object); |
| 602 | |
| 603 | return (object); |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * vm_object_deallocate: |
no test coverage detected