Author: kmacy
Date: Sun Apr 19 04:44:05 2009
New Revision: 191259
URL: http://svn.freebsd.org/changeset/base/191259

Log:
  - Allocate a small flowtable in ip_input.c (changeable by tuneable)
  - Use for accelerating ip_output

Modified:
  head/sys/netinet/ip_input.c
  head/sys/netinet/ip_output.c
  head/sys/netinet/vinet.h

Modified: head/sys/netinet/ip_input.c
==============================================================================
--- head/sys/netinet/ip_input.c Sun Apr 19 04:39:42 2009        (r191258)
+++ head/sys/netinet/ip_input.c Sun Apr 19 04:44:05 2009        (r191259)
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
 #include <net/route.h>
 #include <net/netisr.h>
 #include <net/vnet.h>
+#include <net/flowtable.h>
 
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
@@ -211,6 +212,11 @@ SYSCTL_INT(_net_inet_ip, IPCTL_DEFMTU, m
 SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_ip, OID_AUTO, stealth, CTLFLAG_RW,
     ipstealth, 0, "IP stealth mode, no TTL decrementation on forwarding");
 #endif
+static int ip_output_flowtable_size = 2048;
+TUNABLE_INT("net.inet.ip.output_flowtable_size", &ip_output_flowtable_size);
+SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_ip, OID_AUTO, output_flowtable_size,
+    CTLFLAG_RDTUN, ip_output_flowtable_size, 2048,
+    "number of entries in the per-cpu output flow caches");
 
 /*
  * ipfw_ether and ipfw_bridge hooks.
@@ -221,6 +227,7 @@ ip_dn_io_t *ip_dn_io_ptr = NULL;
 #ifdef VIMAGE_GLOBALS
 int fw_one_pass;
 #endif
+struct flowtable *ip_ft;
 
 static void    ip_freef(struct ipqhead *, struct ipq *);
 
@@ -342,6 +349,8 @@ ip_init(void)
        ipintrq.ifq_maxlen = ipqmaxlen;
        mtx_init(&ipintrq.ifq_mtx, "ip_inq", NULL, MTX_DEF);
        netisr_register(NETISR_IP, ip_input, &ipintrq, 0);
+
+       ip_ft = flowtable_alloc(ip_output_flowtable_size, FL_PCPU);
 }
 
 void

Modified: head/sys/netinet/ip_output.c
==============================================================================
--- head/sys/netinet/ip_output.c        Sun Apr 19 04:39:42 2009        
(r191258)
+++ head/sys/netinet/ip_output.c        Sun Apr 19 04:44:05 2009        
(r191259)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
 #include <net/netisr.h>
 #include <net/pfil.h>
 #include <net/route.h>
+#include <net/flowtable.h>
 #ifdef RADIX_MPATH
 #include <net/radix_mpath.h>
 #endif
@@ -135,6 +136,7 @@ ip_output(struct mbuf *m, struct mbuf *o
        int hlen = sizeof (struct ip);
        int mtu;
        int len, error = 0;
+       int nortfree = 0;
        struct sockaddr_in *dst = NULL; /* keep compiler happy */
        struct in_ifaddr *ia = NULL;
        int isbroadcast, sw_csum;
@@ -158,6 +160,10 @@ ip_output(struct mbuf *m, struct mbuf *o
                        m->m_flags |= M_FLOWID;
                }
        }
+       if ((ro == &iproute) && (ro->ro_rt == NULL) && (ro->ro_lle == NULL)) {
+               if (flowtable_lookup(ip_ft, m, ro) == 0)
+                       nortfree = 1;
+       }
 
        if (opt) {
                len = 0;
@@ -199,7 +205,8 @@ again:
        if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 ||
                          dst->sin_family != AF_INET ||
                          dst->sin_addr.s_addr != ip->ip_dst.s_addr)) {
-               RTFREE(ro->ro_rt);
+               if (!nortfree)
+                       RTFREE(ro->ro_rt);
                ro->ro_rt = (struct rtentry *)NULL;
        }
 #ifdef IPFIREWALL_FORWARD
@@ -638,7 +645,7 @@ passout:
                IPSTAT_INC(ips_fragmented);
 
 done:
-       if (ro == &iproute && ro->ro_rt) {
+       if (ro == &iproute && ro->ro_rt && !nortfree) {
                RTFREE(ro->ro_rt);
        }
        return (error);

Modified: head/sys/netinet/vinet.h
==============================================================================
--- head/sys/netinet/vinet.h    Sun Apr 19 04:39:42 2009        (r191258)
+++ head/sys/netinet/vinet.h    Sun Apr 19 04:44:05 2009        (r191259)
@@ -72,6 +72,7 @@ struct vnet_inet {
        int     _ip_sendsourcequench;
        int     _ip_do_randomid;
        int     _ip_checkinterface;
+       int     _ip_output_flowtable_size;
        u_short _ip_id;
 
        uma_zone_t _ipq_zone;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to