Changeset View
Changeset View
Standalone View
Standalone View
sys/netinet/tcp_hostcache.c
Show First 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
/* Arbitrary values */ | /* Arbitrary values */ | ||||
#define TCP_HOSTCACHE_HASHSIZE 512 | #define TCP_HOSTCACHE_HASHSIZE 512 | ||||
#define TCP_HOSTCACHE_BUCKETLIMIT 30 | #define TCP_HOSTCACHE_BUCKETLIMIT 30 | ||||
#define TCP_HOSTCACHE_EXPIRE 60*60 /* one hour */ | #define TCP_HOSTCACHE_EXPIRE 60*60 /* one hour */ | ||||
#define TCP_HOSTCACHE_PRUNE 5*60 /* every 5 minutes */ | #define TCP_HOSTCACHE_PRUNE 5*60 /* every 5 minutes */ | ||||
VNET_DEFINE_STATIC(struct tcp_hostcache, tcp_hostcache); | VNET_DEFINE_STATIC(struct tcp_hostcache, tcp_hostcache) = { | ||||
.hashsize = TCP_HOSTCACHE_HASHSIZE, | |||||
zlei: Found a bug.
`kenv net.inet.tcp.hostcache.hashsize=256 && kenv -u net.inet.tcp.hostcache. | |||||
.bucket_limit = TCP_HOSTCACHE_BUCKETLIMIT, | |||||
.expire = TCP_HOSTCACHE_EXPIRE, | |||||
zleiAuthorUnsubmitted Not Done Inline ActionsOoops, expire and prune are not loader tunable ;( zlei: Ooops, `expire` and `prune` are not loader tunable ;( | |||||
.prune = TCP_HOSTCACHE_PRUNE, | |||||
}; | |||||
#define V_tcp_hostcache VNET(tcp_hostcache) | #define V_tcp_hostcache VNET(tcp_hostcache) | ||||
VNET_DEFINE_STATIC(struct callout, tcp_hc_callout); | VNET_DEFINE_STATIC(struct callout, tcp_hc_callout); | ||||
#define V_tcp_hc_callout VNET(tcp_hc_callout) | #define V_tcp_hc_callout VNET(tcp_hc_callout) | ||||
static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); | static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); | ||||
static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); | static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); | ||||
static int sysctl_tcp_hc_histo(SYSCTL_HANDLER_ARGS); | static int sysctl_tcp_hc_histo(SYSCTL_HANDLER_ARGS); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | |||||
tcp_hc_init(void) | tcp_hc_init(void) | ||||
{ | { | ||||
u_int cache_limit; | u_int cache_limit; | ||||
int i; | int i; | ||||
/* | /* | ||||
* Initialize hostcache structures. | * Initialize hostcache structures. | ||||
*/ | */ | ||||
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.hashsalt = arc4random(); | ||||
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.hashsize", | |||||
&V_tcp_hostcache.hashsize); | |||||
if (!powerof2(V_tcp_hostcache.hashsize)) { | if (!powerof2(V_tcp_hostcache.hashsize)) { | ||||
printf("WARNING: hostcache hash size is not a power of 2.\n"); | printf("WARNING: hostcache hash size is not a power of 2.\n"); | ||||
V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */ | V_tcp_hostcache.hashsize = TCP_HOSTCACHE_HASHSIZE; /* default */ | ||||
} | } | ||||
V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1; | V_tcp_hostcache.hashmask = V_tcp_hostcache.hashsize - 1; | ||||
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.bucketlimit", | |||||
&V_tcp_hostcache.bucket_limit); | |||||
cache_limit = V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit; | cache_limit = V_tcp_hostcache.hashsize * V_tcp_hostcache.bucket_limit; | ||||
if (V_tcp_hostcache.cache_limit == 0) | |||||
V_tcp_hostcache.cache_limit = cache_limit; | V_tcp_hostcache.cache_limit = cache_limit; | ||||
TUNABLE_INT_FETCH("net.inet.tcp.hostcache.cachelimit", | else if (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.cache_limit = cache_limit; | ||||
/* | /* | ||||
* Allocate the hash table. | * Allocate the hash table. | ||||
*/ | */ | ||||
V_tcp_hostcache.hashbase = (struct hc_head *) | V_tcp_hostcache.hashbase = (struct hc_head *) | ||||
malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head), | malloc(V_tcp_hostcache.hashsize * sizeof(struct hc_head), | ||||
M_HOSTCACHE, M_WAITOK | M_ZERO); | M_HOSTCACHE, M_WAITOK | M_ZERO); | ||||
▲ Show 20 Lines • Show All 582 Lines • Show Last 20 Lines |
Found a bug.
kenv net.inet.tcp.hostcache.hashsize=256 && kenv -u net.inet.tcp.hostcache.hashsize will trigger ASSERT panic.