Changeset View
Changeset View
Standalone View
Standalone View
head/sys/vm/vm_page.c
Show First 20 Lines • Show All 3,741 Lines • ▼ Show 20 Lines | vm_page_unswappable(vm_page_t m) | ||||
vm_page_assert_locked(m); | vm_page_assert_locked(m); | ||||
KASSERT(!vm_page_wired(m) && (m->oflags & VPO_UNMANAGED) == 0, | KASSERT(!vm_page_wired(m) && (m->oflags & VPO_UNMANAGED) == 0, | ||||
("page %p already unswappable", m)); | ("page %p already unswappable", m)); | ||||
vm_page_dequeue(m); | vm_page_dequeue(m); | ||||
vm_page_enqueue(m, PQ_UNSWAPPABLE); | vm_page_enqueue(m, PQ_UNSWAPPABLE); | ||||
} | } | ||||
static void | |||||
vm_page_release_toq(vm_page_t m, int flags) | |||||
{ | |||||
/* | /* | ||||
* Attempt to free the page. If it cannot be freed, do nothing. Returns true | * Use a check of the valid bits to determine whether we should | ||||
* if the page is freed and false otherwise. | * accelerate reclamation of the page. The object lock might not be | ||||
* held here, in which case the check is racy. At worst we will either | |||||
* accelerate reclamation of a valid page and violate LRU, or | |||||
* unnecessarily defer reclamation of an invalid page. | |||||
* | * | ||||
* The page must be managed. The page and its containing object must be | * If we were asked to not cache the page, place it near the head of the | ||||
* locked. | * inactive queue so that is reclaimed sooner. | ||||
*/ | */ | ||||
bool | if ((flags & (VPR_TRYFREE | VPR_NOREUSE)) != 0 || m->valid == 0) | ||||
vm_page_try_to_free(vm_page_t m) | vm_page_deactivate_noreuse(m); | ||||
else if (vm_page_active(m)) | |||||
vm_page_reference(m); | |||||
else | |||||
vm_page_deactivate(m); | |||||
} | |||||
/* | |||||
* Unwire a page and either attempt to free it or re-add it to the page queues. | |||||
*/ | |||||
void | |||||
vm_page_release(vm_page_t m, int flags) | |||||
{ | { | ||||
vm_object_t object; | |||||
bool freed; | |||||
vm_page_assert_locked(m); | KASSERT((m->oflags & VPO_UNMANAGED) == 0, | ||||
VM_OBJECT_ASSERT_WLOCKED(m->object); | ("vm_page_release: page %p is unmanaged", m)); | ||||
KASSERT((m->oflags & VPO_UNMANAGED) == 0, ("page %p is unmanaged", m)); | |||||
if (m->dirty != 0 || vm_page_wired(m) || vm_page_busied(m)) | vm_page_lock(m); | ||||
return (false); | if (m->object != NULL) | ||||
if (m->object->ref_count != 0) { | VM_OBJECT_ASSERT_UNLOCKED(m->object); | ||||
pmap_remove_all(m); | if (vm_page_unwire_noq(m)) { | ||||
if (m->dirty != 0) | if ((object = m->object) == NULL) { | ||||
return (false); | vm_page_free(m); | ||||
} else { | |||||
freed = false; | |||||
if ((flags & VPR_TRYFREE) != 0 && !vm_page_busied(m) && | |||||
/* Depends on type stability. */ | |||||
VM_OBJECT_TRYWLOCK(object)) { | |||||
/* | |||||
* Only free unmapped pages. The busy test from | |||||
* before the object was locked cannot be relied | |||||
* upon. | |||||
*/ | |||||
if ((object->ref_count == 0 || | |||||
!pmap_page_is_mapped(m)) && m->dirty == 0 && | |||||
!vm_page_busied(m)) { | |||||
vm_page_free(m); | |||||
freed = true; | |||||
} | } | ||||
VM_OBJECT_WUNLOCK(object); | |||||
} | |||||
if (!freed) | |||||
vm_page_release_toq(m, flags); | |||||
} | |||||
} | |||||
vm_page_unlock(m); | |||||
} | |||||
/* See vm_page_release(). */ | |||||
void | |||||
vm_page_release_locked(vm_page_t m, int flags) | |||||
{ | |||||
VM_OBJECT_ASSERT_WLOCKED(m->object); | |||||
KASSERT((m->oflags & VPO_UNMANAGED) == 0, | |||||
("vm_page_release_locked: page %p is unmanaged", m)); | |||||
vm_page_lock(m); | |||||
if (vm_page_unwire_noq(m)) { | |||||
if ((flags & VPR_TRYFREE) != 0 && | |||||
(m->object->ref_count == 0 || !pmap_page_is_mapped(m)) && | |||||
m->dirty == 0 && !vm_page_busied(m)) { | |||||
vm_page_free(m); | vm_page_free(m); | ||||
return (true); | } else { | ||||
vm_page_release_toq(m, flags); | |||||
} | |||||
} | |||||
vm_page_unlock(m); | |||||
} | } | ||||
/* | /* | ||||
* vm_page_advise | * vm_page_advise | ||||
* | * | ||||
* Apply the specified advice to the given page. | * Apply the specified advice to the given page. | ||||
* | * | ||||
* The object and page must be locked. | * The object and page must be locked. | ||||
▲ Show 20 Lines • Show All 730 Lines • Show Last 20 Lines |