Deleted Added
full compact
tcp_hostcache.c (181887) tcp_hostcache.c (181888)
1/*-
2 * Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 */
59
60/*
61 * Many thanks to jlemon for basic structure of tcp_syncache which is being
62 * followed here.
63 */
64
65#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2002 Andre Oppermann, Internet Business Solutions AG
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 49 unchanged lines hidden (view full) ---

58 */
59
60/*
61 * Many thanks to jlemon for basic structure of tcp_syncache which is being
62 * followed here.
63 */
64
65#include <sys/cdefs.h>
66__FBSDID("$FreeBSD: head/sys/netinet/tcp_hostcache.c 181887 2008-08-20 01:05:56Z julian $");
66__FBSDID("$FreeBSD: head/sys/netinet/tcp_hostcache.c 181888 2008-08-20 01:24:55Z julian $");
67
68#include "opt_inet6.h"
69
70#include <sys/param.h>
71#include <sys/systm.h>
72#include <sys/kernel.h>
73#include <sys/lock.h>
74#include <sys/mutex.h>

--- 169 unchanged lines hidden (view full) ---

244 mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry",
245 NULL, MTX_DEF);
246 }
247
248 /*
249 * Allocate the hostcache entries.
250 */
251 V_tcp_hostcache.zone =
67
68#include "opt_inet6.h"
69
70#include <sys/param.h>
71#include <sys/systm.h>
72#include <sys/kernel.h>
73#include <sys/lock.h>
74#include <sys/mutex.h>

--- 169 unchanged lines hidden (view full) ---

244 mtx_init(&V_tcp_hostcache.hashbase[i].hch_mtx, "tcp_hc_entry",
245 NULL, MTX_DEF);
246 }
247
248 /*
249 * Allocate the hostcache entries.
250 */
251 V_tcp_hostcache.zone =
252 uma_zcreate("hostcache", sizeof(struct hc_metrics),
253 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
252 uma_zcreate("hostcache", sizeof(struct hc_metrics),
253 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
254 uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit);
255
256 /*
257 * Set up periodic cache cleanup.
258 */
259 callout_init(&V_tcp_hc_callout, CALLOUT_MPSAFE);
260 callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
261 tcp_hc_purge, 0);

--- 403 unchanged lines hidden (view full) ---

665 if (V_tcp_hostcache.purgeall) {
666 all = 1;
667 V_tcp_hostcache.purgeall = 0;
668 }
669
670 for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
671 THC_LOCK(&V_tcp_hostcache.hashbase[i].hch_mtx);
672 TAILQ_FOREACH_SAFE(hc_entry,
254 uma_zone_set_max(V_tcp_hostcache.zone, V_tcp_hostcache.cache_limit);
255
256 /*
257 * Set up periodic cache cleanup.
258 */
259 callout_init(&V_tcp_hc_callout, CALLOUT_MPSAFE);
260 callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
261 tcp_hc_purge, 0);

--- 403 unchanged lines hidden (view full) ---

665 if (V_tcp_hostcache.purgeall) {
666 all = 1;
667 V_tcp_hostcache.purgeall = 0;
668 }
669
670 for (i = 0; i < V_tcp_hostcache.hashsize; i++) {
671 THC_LOCK(&V_tcp_hostcache.hashbase[i].hch_mtx);
672 TAILQ_FOREACH_SAFE(hc_entry,
673 &V_tcp_hostcache.hashbase[i].hch_bucket,
674 rmx_q, hc_next) {
673 &V_tcp_hostcache.hashbase[i].hch_bucket, rmx_q, hc_next) {
675 if (all || hc_entry->rmx_expire <= 0) {
676 TAILQ_REMOVE(&V_tcp_hostcache.hashbase[i].hch_bucket,
677 hc_entry, rmx_q);
678 uma_zfree(V_tcp_hostcache.zone, hc_entry);
679 V_tcp_hostcache.hashbase[i].hch_length--;
680 V_tcp_hostcache.cache_count--;
681 } else
682 hc_entry->rmx_expire -= V_tcp_hostcache.prune;
683 }
684 THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx);
685 }
686
687 callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
688 tcp_hc_purge, arg);
689}
674 if (all || hc_entry->rmx_expire <= 0) {
675 TAILQ_REMOVE(&V_tcp_hostcache.hashbase[i].hch_bucket,
676 hc_entry, rmx_q);
677 uma_zfree(V_tcp_hostcache.zone, hc_entry);
678 V_tcp_hostcache.hashbase[i].hch_length--;
679 V_tcp_hostcache.cache_count--;
680 } else
681 hc_entry->rmx_expire -= V_tcp_hostcache.prune;
682 }
683 THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx);
684 }
685
686 callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
687 tcp_hc_purge, arg);
688}