V_tcp_hostcache
V_tcp_hostcache.hashsalt) & V_tcp_hostcache.hashmask) \
V_tcp_hostcache.hashsalt) & V_tcp_hostcache.hashmask)
atomic_store_int(&V_tcp_hostcache.cache_count, 0);
V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE;
V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT;
V_tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE;
V_tcp_hostcache.prune = TCP_HOSTCACHE_PRUNE;
V_tcp_hostcache.hashsalt = arc4random();
&V_tcp_hostcache.hashsize);
if (!powerof2(V_tcp_hostcache.hashsize)) {
V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */
V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1;
&V_tcp_hostcache.bucket_limit);
cache_limit = V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit;
V_tcp_hostcache.cache_limit = cache_limit;
&V_tcp_hostcache.cache_limit);
if (V_tcp_hostcache.cache_limit > cache_limit)
V_tcp_hostcache.cache_limit = cache_limit;
V_tcp_hostcache.hashbase = (struct hc_head *)
malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head),
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
CK_SLIST_INIT(&V_tcp_hostcache.hashbase[i].hch_bucket);
V_tcp_hostcache.hashbase[i].hch_length = 0;
mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry",
V_tcp_hostcache.zone =
uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit);
V_tcp_hostcache.smr = uma_zone_get_smr(V_tcp_hostcache.zone);
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
uma_zdestroy(V_tcp_hostcache.zone);
for (i = 0; i < V_tcp_hostcache.hashsize; i++)
mtx_destroy(&V_tcp_hostcache.hashbase[i].hch_mtx);
free(V_tcp_hostcache.hashbase, M_HOSTCACHE);
hc_head = &V_tcp_hostcache.hashbase[HOSTCACHE_HASH(inc)];
smr_enter(V_tcp_hostcache.smr);
V_tcp_hostcache.expire)
V_tcp_hostcache.expire);
smr_exit(V_tcp_hostcache.smr);
smr_exit(V_tcp_hostcache.smr);
smr_exit(V_tcp_hostcache.smr);
hc_head = &V_tcp_hostcache.hashbase[HOSTCACHE_HASH(inc)];
V_tcp_hostcache.expire)
V_tcp_hostcache.expire);
if (hc_head->hch_length >= V_tcp_hostcache.bucket_limit ||
atomic_load_int(&V_tcp_hostcache.cache_count) >=
V_tcp_hostcache.cache_limit) {
hc_head->hch_length <= V_tcp_hostcache.bucket_limit,
atomic_subtract_int(&V_tcp_hostcache.cache_count, 1);
uma_zfree_smr(V_tcp_hostcache.zone, hc_entry);
hc_entry = uma_zalloc_smr(V_tcp_hostcache.zone, M_NOWAIT);
hc_entry->hc_expire = V_tcp_hostcache.expire;
KASSERT(hc_head->hch_length <= V_tcp_hostcache.bucket_limit,
atomic_add_int(&V_tcp_hostcache.cache_count, 1);
expire = V_tcp_hostcache.expire;
if (expire < V_tcp_hostcache.prune)
V_tcp_hostcache.prune = expire;
V_tcp_hostcache.expire = expire;
prune = V_tcp_hostcache.prune;
if (prune > V_tcp_hostcache.expire)
V_tcp_hostcache.expire = prune;
V_tcp_hostcache.prune = prune;
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
len = (atomic_load_int(&V_tcp_hostcache.cache_count) + 1) *
sbuf_new_for_sysctl(&sb, NULL, V_tcp_hostcache.bucket_limit *
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
THC_LOCK(&V_tcp_hostcache.hashbase[i]);
&V_tcp_hostcache.hashbase[i].hch_bucket, hc_q) {
THC_UNLOCK(&V_tcp_hostcache.hashbase[i]);
histo = (int *)malloc(sizeof(int) * (V_tcp_hostcache.bucket_limit + 1),
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
hch_length = V_tcp_hostcache.hashbase[i].hch_length;
KASSERT(hch_length <= V_tcp_hostcache.bucket_limit,
for (i = 0; i <= V_tcp_hostcache.bucket_limit; i++) {
for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
head = &V_tcp_hostcache.hashbase[i];
V_tcp_hostcache.bucket_limit, ("tcp_hostcache: "
uma_zfree_smr(V_tcp_hostcache.zone, hc_entry);
atomic_subtract_int(&V_tcp_hostcache.cache_count, 1);
V_tcp_hostcache.prune);
if (V_tcp_hostcache.purgeall) {
if (V_tcp_hostcache.purgeall == 2)
V_tcp_hostcache.hashsalt = arc4random();
V_tcp_hostcache.purgeall = 0;
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
V_tcp_hostcache.hashsalt = arc4random();
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,