sys/vm/vm_page.c
/*
 * If we could not find the page in the desired queue try to find it in
 * a nearby (NUMA-aware) queue.
 */
If we could not find the page in the desired queue try to find it in
a nearby (NUMA-aware) queue.
If we could not find the page in the desired queue try to find it in a nearby ( NUMA - aware ) queue .
static vm_page_t
_vm_page_list_find2(int basequeue, int index, int *lastp)
{
	struct vpgqueues *pq;
	vm_page_t m = NULL;
	int pqmask = set_assoc_mask >> 1;
	int pqi;
	int range;
	int skip_start;
	int skip_next;
	int count;
	index &= PQ_L2_MASK;
	pq = &vm_page_queues[basequeue];
	count = 0;
	skip_start = -1;
	skip_next = -1;
	do {
		pqmask = (pqmask << 1) | 1;
		pqi = index;
		range = pqmask + 1;
		while (range > 0) {
			if (pqi >= skip_start && pqi < skip_next) {
				range -= skip_next - pqi;
				pqi = (pqi & ~pqmask) | (skip_next & pqmask);
			}
			if (range > 0 && TAILQ_FIRST(&pq[pqi].pl)) {
				spin_lock(&pq[pqi].spin);
				TAILQ_FOREACH(m, &pq[pqi].pl, pageq) {
					if (spin_trylock(&m->spin) == 0)
						continue;
					KKASSERT(m->queue == basequeue + pqi);
					_vm_page_rem_queue_spinlocked(m);
					if (count >= 8)
						*lastp = pqi & PQ_L2_MASK;
					return(m);
				}
				spin_unlock(&pq[pqi].spin);
			}
			--range;
			++count;
			pqi = (pqi & ~pqmask) | ((pqi + 1) & pqmask);
		}
		skip_start = pqi & ~pqmask;
		skip_next = (pqi | pqmask) + 1;
	} while (pqmask != PQ_L2_MASK);
	return(m);
}
static vm_page_t _vm_page_list_find2 ( int basequeue , int index , int * lastp ) { struct vpgqueues * pq ; vm_page_t m = NULL ; int pqmask = set_assoc_mask >> 1 ; int pqi ; int range ; int skip_start ; int skip_next ; int count ; index &= PQ_L2_MASK ; pq = & vm_page_queues [ basequeue ] ; count = 0 ; skip_start = -1 ; skip_next = -1 ; do { pqmask = ( pqmask << 1 ) | 1 ; pqi = index ; range = pqmask + 1 ; while ( range > 0 ) { if ( pqi >= skip_start && pqi < skip_next ) { range -= skip_next - pqi ; pqi = ( pqi & ~ pqmask ) | ( skip_next & pqmask ) ; } if ( range > 0 && TAILQ_FIRST ( & pq [ pqi ] . pl ) ) { spin_lock ( & pq [ pqi ] . spin ) ; TAILQ_FOREACH ( m , & pq [ pqi ] . pl , pageq ) { if ( spin_trylock ( & m -> spin ) == 0 ) continue ; KKASSERT ( m -> queue == basequeue + pqi ) ; _vm_page_rem_queue_spinlocked ( m ) ; if ( count >= 8 ) * lastp = pqi & PQ_L2_MASK ; return ( m ) ; } spin_unlock ( & pq [ pqi ] . spin ) ; } -- range ; ++ count ; pqi = ( pqi & ~ pqmask ) | ( ( pqi + 1 ) & pqmask ) ; } skip_start = pqi & ~ pqmask ; skip_next = ( pqi | pqmask ) + 1 ; } while ( pqmask != PQ_L2_MASK ) ; return ( m ) ; }
If we could not find the page in the desired queue try to find it in
 a nearby (NUMA-aware) queue.
If we could not find the page in the desired queue try to find it in a nearby ( NUMA - aware ) queue .
/*
	 * Run local sets of 16, 32, 64, 128, up to the entire queue if all
	 * else fails (PQ_L2_MASK).
	 *
	 * pqmask is a mask, 15, 31, 63, etc.
	 *
	 * Test each queue unlocked first, then lock the queue and locate
	 * a page.  Note that the lock order is reversed, but we do not want
	 * to dwadle on the page spinlock anyway as it is held significantly
	 * longer than the queue spinlock.
	 */ /*
					 * If we had to wander too far, set
					 * *lastp to skip past empty queues.
					 */