* Speed up the reclamation of pages that precede the faulting pindex within * the first object of the shadow chain. Essentially, perform the equivalent * to madvise(..., MADV_DONTNEED) on a large cluster of pages that precedes * the faulting pindex by the cluster size when the pages read by vm_fault() * cross a cluster-size boundary. The cluster size is the greater of the * smallest superpa
| 1646 | * function must only be concerned with pages in the first object. |
| 1647 | */ |
| 1648 | static void |
| 1649 | vm_fault_dontneed(const struct faultstate *fs, vm_offset_t vaddr, int ahead) |
| 1650 | { |
| 1651 | vm_map_entry_t entry; |
| 1652 | vm_object_t first_object, object; |
| 1653 | vm_offset_t end, start; |
| 1654 | vm_page_t m, m_next; |
| 1655 | vm_pindex_t pend, pstart; |
| 1656 | vm_size_t size; |
| 1657 | |
| 1658 | object = fs->object; |
| 1659 | VM_OBJECT_ASSERT_UNLOCKED(object); |
| 1660 | first_object = fs->first_object; |
| 1661 | /* Neither fictitious nor unmanaged pages can be reclaimed. */ |
| 1662 | if ((first_object->flags & (OBJ_FICTITIOUS | OBJ_UNMANAGED)) == 0) { |
| 1663 | VM_OBJECT_RLOCK(first_object); |
| 1664 | size = VM_FAULT_DONTNEED_MIN; |
| 1665 | if (MAXPAGESIZES > 1 && size < pagesizes[1]) |
| 1666 | size = pagesizes[1]; |
| 1667 | end = rounddown2(vaddr, size); |
| 1668 | if (vaddr - end >= size - PAGE_SIZE - ptoa(ahead) && |
| 1669 | (entry = fs->entry)->start < end) { |
| 1670 | if (end - entry->start < size) |
| 1671 | start = entry->start; |
| 1672 | else |
| 1673 | start = end - size; |
| 1674 | pmap_advise(fs->map->pmap, start, end, MADV_DONTNEED); |
| 1675 | pstart = OFF_TO_IDX(entry->offset) + atop(start - |
| 1676 | entry->start); |
| 1677 | m_next = vm_page_find_least(first_object, pstart); |
| 1678 | pend = OFF_TO_IDX(entry->offset) + atop(end - |
| 1679 | entry->start); |
| 1680 | while ((m = m_next) != NULL && m->pindex < pend) { |
| 1681 | m_next = TAILQ_NEXT(m, listq); |
| 1682 | if (!vm_page_all_valid(m) || |
| 1683 | vm_page_busied(m)) |
| 1684 | continue; |
| 1685 | |
| 1686 | /* |
| 1687 | * Don't clear PGA_REFERENCED, since it would |
| 1688 | * likely represent a reference by a different |
| 1689 | * process. |
| 1690 | * |
| 1691 | * Typically, at this point, prefetched pages |
| 1692 | * are still in the inactive queue. Only |
| 1693 | * pages that triggered page faults are in the |
| 1694 | * active queue. The test for whether the page |
| 1695 | * is in the inactive queue is racy; in the |
| 1696 | * worst case we will requeue the page |
| 1697 | * unnecessarily. |
| 1698 | */ |
| 1699 | if (!vm_page_inactive(m)) |
| 1700 | vm_page_deactivate(m); |
| 1701 | } |
| 1702 | } |
| 1703 | VM_OBJECT_RUNLOCK(first_object); |
| 1704 | } |
| 1705 | } |
no test coverage detected