MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tcp_hc_init

Function tcp_hc_init

freebsd/netinet/tcp_hostcache.c:193–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191#define THC_UNLOCK(lp) mtx_unlock(lp)
192
193void
194tcp_hc_init(void)
195{
196 u_int cache_limit;
197 int i;
198
199 /*
200 * Initialize hostcache structures.
201 */
202 V_tcp_hostcache.cache_count = 0;
203 V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE;
204 V_tcp_hostcache.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT;
205 V_tcp_hostcache.expire = TCP_HOSTCACHE_EXPIRE;
206 V_tcp_hostcache.prune = TCP_HOSTCACHE_PRUNE;
207
208 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize",
209 &V_tcp_hostcache.hashsize);
210 if (!powerof2(V_tcp_hostcache.hashsize)) {
211 printf("WARNING: hostcache hash size is not a power of 2.\n");
212 V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */
213 }
214 V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1;
215
216 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit",
217 &V_tcp_hostcache.bucket_limit);
218
219 cache_limit = V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit;
220 V_tcp_hostcache.cache_limit = cache_limit;
221 TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit",
222 &V_tcp_hostcache.cache_limit);
223 if (V_tcp_hostcache.cache_limit > cache_limit)
224 V_tcp_hostcache.cache_limit = cache_limit;
225
226 /*
227 * Allocate the hash table.
228 */
229 V_tcp_hostcache.hashbase = (struct hc_head *)
230 malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head),
231 M_HOSTCACHE, M_WAITOK | M_ZERO);
232
233 /*
234 * Initialize the hash buckets.
235 */
236 for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
237 TAILQ_INIT(&V_tcp_hostcache.hashbase[i].hch_bucket);
238 V_tcp_hostcache.hashbase[i].hch_length = 0;
239 mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry",
240 NULL, MTX_DEF);
241 }
242
243 /*
244 * Allocate the hostcache entries.
245 */
246 V_tcp_hostcache.zone =
247 uma_zcreate("hostcache", sizeof(struct hc_metrics),
248 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
249 uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit);
250

Callers 1

tcp_initFunction · 0.85

Calls 6

mallocFunction · 0.85
mtx_initFunction · 0.85
uma_zcreateFunction · 0.85
uma_zone_set_maxFunction · 0.85
printfFunction · 0.50
callout_initFunction · 0.50

Tested by

no test coverage detected