FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c
/*
 * Insert an entry into the hash table.  If there is already an element
 * equal to elem in the hash table, then the already existing element
 * will be returned and the new element will not be inserted.
 * Otherwise returns NULL.
 * If lockp == NULL, the caller is assumed to already hold the hash lock.
 */
Insert an entry into the hash table.  If there is already an element
equal to elem in the hash table, then the already existing element
will be returned and the new element will not be inserted.
Otherwise returns NULL.
If lockp == NULL, the caller is assumed to already hold the hash lock.
Insert an entry into the hash table . If there is already an element equal to elem in the hash table then the already existing element will be returned and the new element will not be inserted . Otherwise returns NULL . If lockp == NULL the caller is assumed to already hold the hash lock .
static arc_buf_hdr_t *
buf_hash_insert(arc_buf_hdr_t *hdr, kmutex_t **lockp)
{
	uint64_t idx = BUF_HASH_INDEX(hdr->b_spa, &hdr->b_dva, hdr->b_birth);
	kmutex_t *hash_lock = BUF_HASH_LOCK(idx);
	arc_buf_hdr_t *fhdr;
	uint32_t i;
	ASSERT(!DVA_IS_EMPTY(&hdr->b_dva));
	ASSERT(hdr->b_birth != 0);
	ASSERT(!HDR_IN_HASH_TABLE(hdr));
	if (lockp != NULL) {
		*lockp = hash_lock;
		mutex_enter(hash_lock);
	} else {
		ASSERT(MUTEX_HELD(hash_lock));
	}
	for (fhdr = buf_hash_table.ht_table[idx], i = 0; fhdr != NULL;
	    fhdr = fhdr->b_hash_next, i++) {
		if (BUF_EQUAL(hdr->b_spa, &hdr->b_dva, hdr->b_birth, fhdr))
			return (fhdr);
	}
	hdr->b_hash_next = buf_hash_table.ht_table[idx];
	buf_hash_table.ht_table[idx] = hdr;
	hdr->b_flags |= ARC_FLAG_IN_HASH_TABLE;
	if (i > 0) {
		ARCSTAT_BUMP(arcstat_hash_collisions);
		if (i == 1)
			ARCSTAT_BUMP(arcstat_hash_chains);
		ARCSTAT_MAX(arcstat_hash_chain_max, i);
	}
	ARCSTAT_BUMP(arcstat_hash_elements);
	ARCSTAT_MAXSTAT(arcstat_hash_elements);
	return (NULL);
}
static arc_buf_hdr_t * buf_hash_insert ( arc_buf_hdr_t * hdr , kmutex_t * * lockp ) { uint64_t idx = BUF_HASH_INDEX ( hdr -> b_spa , & hdr -> b_dva , hdr -> b_birth ) ; kmutex_t * hash_lock = BUF_HASH_LOCK ( idx ) ; arc_buf_hdr_t * fhdr ; uint32_t i ; ASSERT ( ! DVA_IS_EMPTY ( & hdr -> b_dva ) ) ; ASSERT ( hdr -> b_birth != 0 ) ; ASSERT ( ! HDR_IN_HASH_TABLE ( hdr ) ) ; if ( lockp != NULL ) { * lockp = hash_lock ; mutex_enter ( hash_lock ) ; } else { ASSERT ( MUTEX_HELD ( hash_lock ) ) ; } for ( fhdr = buf_hash_table . ht_table [ idx ] , i = 0 ; fhdr != NULL ; fhdr = fhdr -> b_hash_next , i ++ ) { if ( BUF_EQUAL ( hdr -> b_spa , & hdr -> b_dva , hdr -> b_birth , fhdr ) ) return ( fhdr ) ; } hdr -> b_hash_next = buf_hash_table . ht_table [ idx ] ; buf_hash_table . ht_table [ idx ] = hdr ; hdr -> b_flags |= ARC_FLAG_IN_HASH_TABLE ; if ( i > 0 ) { ARCSTAT_BUMP ( arcstat_hash_collisions ) ; if ( i == 1 ) ARCSTAT_BUMP ( arcstat_hash_chains ) ; ARCSTAT_MAX ( arcstat_hash_chain_max , i ) ; } ARCSTAT_BUMP ( arcstat_hash_elements ) ; ARCSTAT_MAXSTAT ( arcstat_hash_elements ) ; return ( NULL ) ; }
Insert an entry into the hash table.
Insert an entry into the hash table .
/* collect some hash table performance data */