From eddfbb763ded6b5f6777335142be9a0edab628bb Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Tue, 14 Jul 2009 22:48:30 +0000 Subject: Build on Jeff Roberson's linker-set based dynamic per-CPU allocator (DPCPU), as suggested by Peter Wemm, and implement a new per-virtual network stack memory allocator. Modify vnet to use the allocator instead of monolithic global container structures (vinet, ...). This change solves many binary compatibility problems associated with VIMAGE, and restores ELF symbols for virtualized global variables. Each virtualized global variable exists as a "reference copy", and also once per virtual network stack. Virtualized global variables are tagged at compile-time, placing the in a special linker set, which is loaded into a contiguous region of kernel memory. Virtualized global variables in the base kernel are linked as normal, but those in modules are copied and relocated to a reserved portion of the kernel's vnet region with the help of a the kernel linker. Virtualized global variables exist in per-vnet memory set up when the network stack instance is created, and are initialized statically from the reference copy. Run-time access occurs via an accessor macro, which converts from the current vnet and requested symbol to a per-vnet address. When "options VIMAGE" is not compiled into the kernel, normal global ELF symbols will be used instead and indirection is avoided. This change restores static initialization for network stack global variables, restores support for non-global symbols and types, eliminates the need for many subsystem constructors, eliminates large per-subsystem structures that caused many binary compatibility issues both for monitoring applications (netstat) and kernel modules, removes the per-function INIT_VNET_*() macros throughout the stack, eliminates the need for vnet_symmap ksym(2) munging, and eliminates duplicate definitions of virtualized globals under VIMAGE_GLOBALS. Bump __FreeBSD_version and update UPDATING. Portions submitted by: bz Reviewed by: bz, zec Discussed with: gnn, jamie, jeff, jhb, julian, sam Suggested by: peter Approved by: re (kensmith) --- sys/netinet/tcp_hostcache.c | 49 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'sys/netinet/tcp_hostcache.c') diff --git a/sys/netinet/tcp_hostcache.c b/sys/netinet/tcp_hostcache.c index cdd8c3652183..e7bf0d1ec9cd 100644 --- a/sys/netinet/tcp_hostcache.c +++ b/sys/netinet/tcp_hostcache.c @@ -94,7 +94,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #ifdef INET6 #include #endif @@ -107,10 +106,11 @@ __FBSDID("$FreeBSD$"); #define TCP_HOSTCACHE_EXPIRE 60*60 /* one hour */ #define TCP_HOSTCACHE_PRUNE 5*60 /* every 5 minutes */ -#ifdef VIMAGE_GLOBALS -static struct tcp_hostcache tcp_hostcache; -static struct callout tcp_hc_callout; -#endif +static VNET_DEFINE(struct tcp_hostcache, tcp_hostcache); +static VNET_DEFINE(struct callout, tcp_hc_callout); + +#define V_tcp_hostcache VNET_GET(tcp_hostcache) +#define V_tcp_hc_callout VNET_GET(tcp_hc_callout) static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); static struct hc_metrics *tcp_hc_insert(struct in_conninfo *); @@ -120,31 +120,32 @@ static void tcp_hc_purge(void *); SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache, CTLFLAG_RW, 0, "TCP Host cache"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, cachelimit, - CTLFLAG_RDTUN, tcp_hostcache.cache_limit, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, cachelimit, CTLFLAG_RDTUN, + &VNET_NAME(tcp_hostcache.cache_limit), 0, "Overall entry limit for hostcache"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, hashsize, - CTLFLAG_RDTUN, tcp_hostcache.hashsize, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, hashsize, CTLFLAG_RDTUN, + &VNET_NAME(tcp_hostcache.hashsize), 0, "Size of TCP hostcache hashtable"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, bucketlimit, - CTLFLAG_RDTUN, tcp_hostcache.bucket_limit, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, bucketlimit, + CTLFLAG_RDTUN, &VNET_NAME(tcp_hostcache.bucket_limit), 0, "Per-bucket hash limit for hostcache"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, count, - CTLFLAG_RD, tcp_hostcache.cache_count, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, count, CTLFLAG_RD, + &VNET_NAME(tcp_hostcache.cache_count), 0, "Current number of entries in hostcache"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, expire, - CTLFLAG_RW, tcp_hostcache.expire, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, expire, CTLFLAG_RW, + &VNET_NAME(tcp_hostcache.expire), 0, "Expire time of TCP hostcache entries"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, prune, - CTLFLAG_RW, tcp_hostcache.prune, 0, "Time between purge runs"); +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, prune, CTLFLAG_RW, + &VNET_NAME(tcp_hostcache.prune), 0, + "Time between purge runs"); -SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_tcp_hostcache, OID_AUTO, purge, - CTLFLAG_RW, tcp_hostcache.purgeall, 0, +SYSCTL_VNET_INT(_net_inet_tcp_hostcache, OID_AUTO, purge, CTLFLAG_RW, + &VNET_NAME(tcp_hostcache.purgeall), 0, "Expire all entires on next purge run"); SYSCTL_PROC(_net_inet_tcp_hostcache, OID_AUTO, list, @@ -172,7 +173,6 @@ static MALLOC_DEFINE(M_HOSTCACHE, "hostcache", "TCP hostcache"); void tcp_hc_init(void) { - INIT_VNET_INET(curvnet); int i; /* @@ -235,7 +235,6 @@ tcp_hc_init(void) void tcp_hc_destroy(void) { - INIT_VNET_INET(curvnet); /* XXX TODO walk the hashtable and free all entries */ @@ -252,7 +251,6 @@ tcp_hc_destroy(void) static struct hc_metrics * tcp_hc_lookup(struct in_conninfo *inc) { - INIT_VNET_INET(curvnet); int hash; struct hc_head *hc_head; struct hc_metrics *hc_entry; @@ -308,7 +306,6 @@ tcp_hc_lookup(struct in_conninfo *inc) static struct hc_metrics * tcp_hc_insert(struct in_conninfo *inc) { - INIT_VNET_INET(curvnet); int hash; struct hc_head *hc_head; struct hc_metrics *hc_entry; @@ -399,7 +396,6 @@ tcp_hc_insert(struct in_conninfo *inc) void tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite) { - INIT_VNET_INET(curvnet); struct hc_metrics *hc_entry; /* @@ -440,7 +436,6 @@ tcp_hc_get(struct in_conninfo *inc, struct hc_metrics_lite *hc_metrics_lite) u_long tcp_hc_getmtu(struct in_conninfo *inc) { - INIT_VNET_INET(curvnet); struct hc_metrics *hc_entry; u_long mtu; @@ -463,7 +458,6 @@ tcp_hc_getmtu(struct in_conninfo *inc) void tcp_hc_updatemtu(struct in_conninfo *inc, u_long mtu) { - INIT_VNET_INET(curvnet); struct hc_metrics *hc_entry; /* @@ -503,7 +497,6 @@ tcp_hc_updatemtu(struct in_conninfo *inc, u_long mtu) void tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml) { - INIT_VNET_INET(curvnet); struct hc_metrics *hc_entry; hc_entry = tcp_hc_lookup(inc); @@ -584,7 +577,6 @@ tcp_hc_update(struct in_conninfo *inc, struct hc_metrics_lite *hcml) static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) { - INIT_VNET_INET(curvnet); int bufsize; int linesize = 128; char *p, *buf; @@ -648,7 +640,6 @@ static void tcp_hc_purge(void *arg) { CURVNET_SET((struct vnet *) arg); - INIT_VNET_INET(curvnet); struct hc_metrics *hc_entry, *hc_next; int all = 0; int i; -- cgit v1.2.3