FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
/*
 * Evict buffers from the cache, such that arc_size is capped by arc_c.
 */
Evict buffers from the cache, such that arc_size is capped by arc_c.
Evict buffers from the cache such that arc_size is capped by arc_c .
static uint64_t
arc_adjust(void)
{
	uint64_t total_evicted = 0;
	uint64_t bytes;
	int64_t target;
	total_evicted += arc_adjust_meta();
	target = MIN((int64_t)(arc_size - arc_c),
	    (int64_t)(refcount_count(&arc_anon->arcs_size) +
	    refcount_count(&arc_mru->arcs_size) + arc_meta_used - arc_p));
	if (arc_adjust_type(arc_mru) == ARC_BUFC_METADATA &&
	    arc_meta_used > arc_meta_min) {
		bytes = arc_adjust_impl(arc_mru, 0, target, ARC_BUFC_METADATA);
		total_evicted += bytes;
		target -= bytes;
		total_evicted +=
		    arc_adjust_impl(arc_mru, 0, target, ARC_BUFC_DATA);
	} else {
		bytes = arc_adjust_impl(arc_mru, 0, target, ARC_BUFC_DATA);
		total_evicted += bytes;
		target -= bytes;
		total_evicted +=
		    arc_adjust_impl(arc_mru, 0, target, ARC_BUFC_METADATA);
	}
	target = arc_size - arc_c;
	if (arc_adjust_type(arc_mfu) == ARC_BUFC_METADATA &&
	    arc_meta_used > arc_meta_min) {
		bytes = arc_adjust_impl(arc_mfu, 0, target, ARC_BUFC_METADATA);
		total_evicted += bytes;
		target -= bytes;
		total_evicted +=
		    arc_adjust_impl(arc_mfu, 0, target, ARC_BUFC_DATA);
	} else {
		bytes = arc_adjust_impl(arc_mfu, 0, target, ARC_BUFC_DATA);
		total_evicted += bytes;
		target -= bytes;
		total_evicted +=
		    arc_adjust_impl(arc_mfu, 0, target, ARC_BUFC_METADATA);
	}
	target = refcount_count(&arc_mru->arcs_size) +
	    refcount_count(&arc_mru_ghost->arcs_size) - arc_c;
	bytes = arc_adjust_impl(arc_mru_ghost, 0, target, ARC_BUFC_DATA);
	total_evicted += bytes;
	target -= bytes;
	total_evicted +=
	    arc_adjust_impl(arc_mru_ghost, 0, target, ARC_BUFC_METADATA);
	target = refcount_count(&arc_mru_ghost->arcs_size) +
	    refcount_count(&arc_mfu_ghost->arcs_size) - arc_c;
	bytes = arc_adjust_impl(arc_mfu_ghost, 0, target, ARC_BUFC_DATA);
	total_evicted += bytes;
	target -= bytes;
	total_evicted +=
	    arc_adjust_impl(arc_mfu_ghost, 0, target, ARC_BUFC_METADATA);
	return (total_evicted);
}
static uint64_t arc_adjust ( void ) { uint64_t total_evicted = 0 ; uint64_t bytes ; int64_t target ; total_evicted += arc_adjust_meta ( ) ; target = MIN ( ( int64_t ) ( arc_size - arc_c ) , ( int64_t ) ( refcount_count ( & arc_anon -> arcs_size ) + refcount_count ( & arc_mru -> arcs_size ) + arc_meta_used - arc_p ) ) ; if ( arc_adjust_type ( arc_mru ) == ARC_BUFC_METADATA && arc_meta_used > arc_meta_min ) { bytes = arc_adjust_impl ( arc_mru , 0 , target , ARC_BUFC_METADATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mru , 0 , target , ARC_BUFC_DATA ) ; } else { bytes = arc_adjust_impl ( arc_mru , 0 , target , ARC_BUFC_DATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mru , 0 , target , ARC_BUFC_METADATA ) ; } target = arc_size - arc_c ; if ( arc_adjust_type ( arc_mfu ) == ARC_BUFC_METADATA && arc_meta_used > arc_meta_min ) { bytes = arc_adjust_impl ( arc_mfu , 0 , target , ARC_BUFC_METADATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mfu , 0 , target , ARC_BUFC_DATA ) ; } else { bytes = arc_adjust_impl ( arc_mfu , 0 , target , ARC_BUFC_DATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mfu , 0 , target , ARC_BUFC_METADATA ) ; } target = refcount_count ( & arc_mru -> arcs_size ) + refcount_count ( & arc_mru_ghost -> arcs_size ) - arc_c ; bytes = arc_adjust_impl ( arc_mru_ghost , 0 , target , ARC_BUFC_DATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mru_ghost , 0 , target , ARC_BUFC_METADATA ) ; target = refcount_count ( & arc_mru_ghost -> arcs_size ) + refcount_count ( & arc_mfu_ghost -> arcs_size ) - arc_c ; bytes = arc_adjust_impl ( arc_mfu_ghost , 0 , target , ARC_BUFC_DATA ) ; total_evicted += bytes ; target -= bytes ; total_evicted += arc_adjust_impl ( arc_mfu_ghost , 0 , target , ARC_BUFC_METADATA ) ; return ( total_evicted ) ; }
Evict buffers from the cache, such that arc_size is capped by arc_c.
Evict buffers from the cache such that arc_size is capped by arc_c .
/*
	 * If we're over arc_meta_limit, we want to correct that before
	 * potentially evicting data buffers below.
	 */ /*
	 * Adjust MRU size
	 *
	 * If we're over the target cache size, we want to evict enough
	 * from the list to get back to our target size. We don't want
	 * to evict too much from the MRU, such that it drops below
	 * arc_p. So, if we're over our target cache size more than
	 * the MRU is over arc_p, we'll evict enough to get back to
	 * arc_p here, and then evict more from the MFU below.
	 */ /*
	 * If we're below arc_meta_min, always prefer to evict data.
	 * Otherwise, try to satisfy the requested number of bytes to
	 * evict from the type which contains older buffers; in an
	 * effort to keep newer buffers in the cache regardless of their
	 * type. If we cannot satisfy the number of bytes from this
	 * type, spill over into the next type.
	 */ /*
		 * If we couldn't evict our target number of bytes from
		 * metadata, we try to get the rest from data.
		 */ /*
		 * If we couldn't evict our target number of bytes from
		 * data, we try to get the rest from metadata.
		 */ /*
	 * Adjust MFU size
	 *
	 * Now that we've tried to evict enough from the MRU to get its
	 * size back to arc_p, if we're still above the target cache
	 * size, we evict the rest from the MFU.
	 */ /*
		 * If we couldn't evict our target number of bytes from
		 * metadata, we try to get the rest from data.
		 */ /*
		 * If we couldn't evict our target number of bytes from
		 * data, we try to get the rest from data.
		 */ /*
	 * Adjust ghost lists
	 *
	 * In addition to the above, the ARC also defines target values
	 * for the ghost lists. The sum of the mru list and mru ghost
	 * list should never exceed the target size of the cache, and
	 * the sum of the mru list, mfu list, mru ghost list, and mfu
	 * ghost list should never exceed twice the target size of the
	 * cache. The following logic enforces these limits on the ghost
	 * caches, and evicts from them as needed.
	 */ /*
	 * We assume the sum of the mru list and mfu list is less than
	 * or equal to arc_c (we enforced this above), which means we
	 * can use the simpler of the two equations below:
	 *
	 *	mru + mfu + mru ghost + mfu ghost <= 2 * arc_c
	 *		    mru ghost + mfu ghost <= arc_c
	 */