sys/vm/vm_page.c
/*
 * Find a page on the cache queue with color optimization, remove it
 * from the queue, and busy it.  The returned page will not be spinlocked.
 *
 * A candidate failure will be deactivated.  Candidates can fail due to
 * being busied by someone else, in which case they will be deactivated.
 *
 * This routine may not block.
 *
 */
Find a page on the cache queue with color optimization, remove it
from the queue, and busy it.  The returned page will not be spinlocked.

A candidate failure will be deactivated.  Candidates can fail due to
being busied by someone else, in which case they will be deactivated.

This routine may not block.
Find a page on the cache queue with color optimization remove it from the queue and busy it . The returned page will not be spinlocked . A candidate failure will be deactivated . Candidates can fail due to being busied by someone else in which case they will be deactivated . This routine may not block .
static vm_page_t
vm_page_select_cache(u_short pg_color)
{
	vm_page_t m;
	for (;;) {
		m = _vm_page_list_find(PQ_CACHE, pg_color);
		if (m == NULL)
			break;
		if (vm_page_busy_try(m, TRUE)) {
			_vm_page_deactivate_locked(m, 0);
			vm_page_spin_unlock(m);
		} else {
			if ((m->flags & PG_NEED_COMMIT) == 0 &&
			    m->hold_count == 0 &&
			    m->wire_count == 0 &&
			    (m->dirty & m->valid) == 0) {
				vm_page_spin_unlock(m);
				KKASSERT((m->flags & PG_UNQUEUED) == 0);
				pagedaemon_wakeup();
				return(m);
			}
			_vm_page_deactivate_locked(m, 0);
			if (_vm_page_wakeup(m)) {
				vm_page_spin_unlock(m);
				wakeup(m);
			} else {
				vm_page_spin_unlock(m);
			}
		}
	}
	return (m);
}
static vm_page_t vm_page_select_cache ( u_short pg_color ) { vm_page_t m ; for ( ; ; ) { m = _vm_page_list_find ( PQ_CACHE , pg_color ) ; if ( m == NULL ) break ; if ( vm_page_busy_try ( m , TRUE ) ) { _vm_page_deactivate_locked ( m , 0 ) ; vm_page_spin_unlock ( m ) ; } else { if ( ( m -> flags & PG_NEED_COMMIT ) == 0 && m -> hold_count == 0 && m -> wire_count == 0 && ( m -> dirty & m -> valid ) == 0 ) { vm_page_spin_unlock ( m ) ; KKASSERT ( ( m -> flags & PG_UNQUEUED ) == 0 ) ; pagedaemon_wakeup ( ) ; return ( m ) ; } _vm_page_deactivate_locked ( m , 0 ) ; if ( _vm_page_wakeup ( m ) ) { vm_page_spin_unlock ( m ) ; wakeup ( m ) ; } else { vm_page_spin_unlock ( m ) ; } } } return ( m ) ; }
Find a page on the cache queue with color optimization, remove it
 from the queue, and busy it.
Find a page on the cache queue with color optimization remove it from the queue and busy it .
/*
		 * (m) has been removed from its queue and spinlocked
		 */ /*
			 * We successfully busied the page
			 */ /*
			 * The page cannot be recycled, deactivate it.
			 */