ipv4 routing: multipath with cache support, 2.6.10-rc3
Subsystems (3)
PATCH 2/2 ipv4 routing: multipath with cache support, 2.6.10-rc3
[PATCH 2/2] ipv4 routing: multipath with cache support, 2.6.10-rc3
From: Einar Lueck <[email protected]>
This patch is an approach towards solving some problems with the current multipath implementation:
* routing cache allows only one route to be cached for a certain search key
* a mulitpath/load balancing decision is only made in case a corresponding route is not yet cached In the scenarios, that are relevant to us (high amount of outgoing connection requests), this is a serious problem.
Our approach:
* a new flag at the "struct dst_entry" flags field to indicate that further routes having the same key follow in the routing cache chain
* at cache lookup time: we recognize this flag and may apply different load balancing policies to the available routes having the same key. * Garbage Collection: modified in a way that ensures that all routes having the same target are removed together from the cache.
Motivation for the approach:
* keep the overall routing cache entry size constant
* separate load balancing state from the overall routing cache state as good as possible keeping all routes inthe same place
* keep changes to the overall routing code/behaviour at a minimum.
We implemented the following routing policies:
* _weighted_ random routing policiy utilizing the weights configurable via "ip route" that allows to approximate many other policies (e.g. round robin)
* random
* round-robin * interface round robin policy that selects among relevant routes in a way that tries to ensure an overall round robin among the available _interfaces_ is achieved.
Applied tests:
* all policies functionally tested with up to 3 NICs (scripted iperf and ifconfig)
* garbage collection within the routing cache functionally tested
* reference counting on devices functionally tested
* Platforms: s390, x86
Please consider for application!
Regards,
Einar
include/net/dst.h +0 -0
@@ -48,6 +48,7 @@
#define DST_NOXFRM 2
#define DST_NOPOLICY 4
#define DST_NOHASH 8
+#define DST_BALANCED 0x10
unsigned long lastuse; unsigned long expires;
include/net/flow.h +0 -0
@@ -51,6 +51,7 @@
__u8 proto;
__u8 flags;
+#define FLOWI_FLAG_MULTIPATHOLDROUTE 0x01
union {
struct {
__u16 sport;include/net/ip_fib.h +0 -0
@@ -95,6 +95,10 @@
unsigned char nh_sel; unsigned char type; unsigned char scope;
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM
+ __u32 network;
+ __u32 netmask;
+#endif
struct fib_info *fi; #ifdef CONFIG_IP_MULTIPLE_TABLES struct fib_rule *r;
@@ -119,6 +123,14 @@
#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev)
#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif)
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM
+#define FIB_RES_NETWORK(res) ((res).network)
+#define FIB_RES_NETMASK(res) ((res).netmask)
+#else /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
+#define FIB_RES_NETWORK(res) (0)
+#define FIB_RES_NETMASK(res) (0)
+#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */
+
struct fib_table {
unsigned char tb_id;
unsigned tb_stamp;include/net/route.h +0 -0
@@ -46,6 +46,7 @@
#define RT_CONN_FLAGS(sk) (RT_TOS(inet_sk(sk)->tos) | sk->sk_localroute)
+struct fib_nh;
struct inet_peer;
struct rtable
{
@@ -179,6 +180,9 @@
memcpy(&fl, &(*rp)->fl, sizeof(fl)); fl.fl_ip_sport = sport; fl.fl_ip_dport = dport; +#if defined(CONFIG_IP_ROUTE_MULTIPATH_CACHED) + fl.flags |= FLOWI_FLAG_MULTIPATHOLDROUTE; +#endif ip_rt_put(*rp); *rp = NULL; return ip_route_output_flow(rp, &fl, sk, 0); @@ -197,4 +201,69 @@ return rt->peer; }
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM +extern void __multipath_flush(void); +static inline void multipath_flush(void) {
+ __multipath_flush();
+}
+#else /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */ +static inline void multipath_flush(void){} +#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */ +
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM +extern void __multipath_set_nhinfo(__u32 network,
+ __u32 netmask, + unsigned char prefixlen, + const struct fib_nh* nh);
+static inline void multipath_set_nhinfo(__u32 network,
+ __u32 netmask,
+ unsigned char prefixlen,
+ const struct fib_nh* nh) {
+ __multipath_set_nhinfo(network, netmask, prefixlen, nh);
+}
+#else
+static inline void multipath_set_nhinfo(__u32 network,
+ __u32 netmask,
+ unsigned char prefixlen,
+ const struct fib_nh* nh) {
+}
+#endif
+
+
+
+#if defined(CONFIG_IP_ROUTE_MULTIPATH_RR) || defined(CONFIG_IP_ROUTE_MULTIPATH_DRR) +extern void __multipath_remove(struct rtable *rt);
+static inline void multipath_remove(struct rtable *rt) {
+ if ( rt->u.dst.flags & DST_BALANCED ) {
+ __multipath_remove( rt );
+ }
+}
+#else /* CONFIG_IP_ROUTE_MULTIPATH_RR || CONFIG_IP_ROUTE_MULTIPATH_DRR */ +static inline void multipath_remove(struct rtable *rt) {}
+#endif /* CONFIG_IP_ROUTE_MULTIPATH_RR || CONFIG_IP_ROUTE_MULTIPATH_DRR */ +
+
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+extern void __multipath_selectroute(const struct flowi *flp,
+ struct rtable *rth,
+ struct rtable **rp);
+static inline int multipath_selectroute(const struct flowi *flp,
+ struct rtable *rth,
+ struct rtable **rp) {
+ if ( rth->u.dst.flags & DST_BALANCED ) {
+ __multipath_selectroute( flp, rth, rp );
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
+static inline int multipath_selectroute(const struct flowi *flp,
+ struct rtable *rth,
+ struct rtable **rp) {
+ return 0;
+}
+#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
+
#endif /* _ROUTE_H */
net/ipv4/Kconfig +0 -0
@@ -90,6 +90,54 @@
equal "cost" and chooses one of them in a non-deterministic fashion if a matching packet arrives.
+config IP_ROUTE_MULTIPATH_CACHED
+ bool "IP: equal cost multipath with caching support (EXPERIMENTAL)"
+ depends on: IP_ROUTE_MULTIPATH
+ help
+ Normally, equal cost multipath routing is not supported by the + routing cache. If you say Y here, alternative routes are cached + and on cache lookup a route is chosen in a configurable fashion.
+
+ If unsure, say N.
+
+#
+# multipath policy configuration
+# +choice
+ prompt "Multipath policy"
+ depends on IP_ROUTE_MULTIPATH_CACHED
+ default IP_ROUTE_MULTIPATH_RANDOM
+
+config IP_ROUTE_MULTIPATH_RR
+ bool "round robin (EXPERIMENTAL)"
+ help
+ Mulitpath routes are chosen according to Round Robin
+
+config IP_ROUTE_MULTIPATH_RANDOM
+ bool "random multipath (EXPERIMENTAL)"
+ help
+ Multipath routes are chosen in a random fashion. Actually, + there is no weight for a route. The advantage of this policy + is that it is implemented stateless and therefore introduces only + a very small delay. +config IP_ROUTE_MULTIPATH_WRANDOM + bool "weighted random multipath (EXPERIMENTAL)" + help + Multipath routes are chosen in a weighted random fashion. + The per route weights are the weights visible via ip route 2. As the + corresponding state management introduces some overhead routing delay + is increased.
+config IP_ROUTE_MULTIPATH_DRR
+ bool "interface round robin (EXPERIMENTAL)"
+ help
+ Connections are distributed in a round robin fashion over the
+ available interfaces. This policy makes sense if the connections + should be primarily distributed on interfaces and not on routes. +endchoice
+#
+# END OF multipath policy configuration
+#
+
config IP_ROUTE_VERBOSE
bool "IP: verbose route monitoring"
depends on IP_ADVANCED_ROUTER
net/ipv4/Makefile +0 -0
@@ -20,6 +20,10 @@
obj-$(CONFIG_INET_IPCOMP) += ipcomp.o
obj-$(CONFIG_INET_TUNNEL) += xfrm4_tunnel.o obj-$(CONFIG_IP_PNP) += ipconfig.o +obj-$(CONFIG_IP_ROUTE_MULTIPATH_RR) += multipath_rr.o
+obj-$(CONFIG_IP_ROUTE_MULTIPATH_RANDOM) += multipath_random.o
+obj-$(CONFIG_IP_ROUTE_MULTIPATH_WRANDOM) += multipath_wrandom.o
+obj-$(CONFIG_IP_ROUTE_MULTIPATH_DRR) += multipath_drr.o
obj-$(CONFIG_NETFILTER) += netfilter/
obj-$(CONFIG_IP_VS) += ipvs/
obj-$(CONFIG_IP_TCPDIAG) += tcp_diag.o diff -ruN linux-2.6.9.split/net/ipv4/fib_hash.c linux-2.6.9.nicbalancing/net/ipv4/fib_hash.c
net/ipv4/fib_hash.c +0 -0
@@ -261,6 +261,7 @@
err = fib_semantic_match(&f->fn_alias, flp, res, + f->fn_key, fz->fz_mask, fz->fz_order); if (err <= 0) goto out;
net/ipv4/fib_lookup.h +0 -0
@@ -19,7 +19,8 @@
/* Exported by fib_semantics.c */
extern int fib_semantic_match(struct list_head *head,
const struct flowi *flp,
- struct fib_result *res, int prefixlen);
+ struct fib_result *res, __u32 zone, __u32 mask,
+ int prefixlen);
extern void fib_release_info(struct fib_info *); extern struct fib_info *fib_create_info(const struct rtmsg *r,
struct kern_rta *rta,
net/ipv4/fib_semantics.c +0 -0
@@ -763,7 +763,8 @@
}
int fib_semantic_match(struct list_head *head, const struct flowi *flp,
- struct fib_result *res, int prefixlen)
+ struct fib_result *res, __u32 zone, __u32 mask, + int prefixlen)
{
struct fib_alias *fa;
int nh_sel = 0;
@@ -827,6 +828,11 @@
res->type = fa->fa_type;
res->scope = fa->fa_scope;
res->fi = fa->fa_info;+#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM
+ res->netmask = mask;
+ res->network = zone &
+ (0xFFFFFFFF >> (32 - prefixlen));
+#endif
atomic_inc(&res->fi->fib_clntref); return 0; }
net/ipv4/multipath_drr.c +278 -0
278 lines not on this page · raw message
net/ipv4/multipath_random.c +117 -0
117 lines not on this page · raw message
net/ipv4/multipath_rr.c +113 -0
113 lines not on this page · raw message
net/ipv4/multipath_wrandom.c +355 -0
355 lines not on this page · raw message
net/ipv4/route.c +0 -0
@@ -129,7 +129,7 @@
int ip_rt_secret_interval = 10 * 60 * HZ;
static unsigned long rt_deadline;
-#define RTprint(a...) printk(KERN_DEBUG a)
+#define RTprint(a...) // printk(KERN_DEBUG a)
static struct timer_list rt_flush_timer;
static struct timer_list rt_periodic_timer;
@@ -450,11 +450,13 @@
static __inline__ void rt_free(struct rtable *rt)
{
+ multipath_remove( rt ); call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free); }
static __inline__ void rt_drop(struct rtable *rt)
{
+ multipath_remove( rt ); ip_rt_put(rt); call_rcu_bh(&rt->u.dst.rcu_head, dst_rcu_free); } @@ -516,6 +518,54 @@ return score; }
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+static struct rtable **rt_remove_balanced_route(struct rtable **chain_head,
+ struct rtable *expentry,
+ int* removed_count) +{
+ int passedexpired = 0;
+ struct rtable **nextstep = NULL;
+ struct rtable **rthp = chain_head;
+ struct rtable *rth;
+ if (removed_count)
+ *removed_count = 0;
+ while ((rth = *rthp) != NULL) {
+ if ( rth == expentry ) {
+ passedexpired = 1;
+ }
+
+ if (((*rthp)->u.dst.flags & DST_BALANCED) != 0 &&
+ compare_keys(&(*rthp)->fl, &expentry->fl)) {
+ if (*rthp == expentry) {
+ *rthp = rth->u.rt_next;
+ continue;
+ }
+ else {
+ *rthp = rth->u.rt_next;
+ rt_free(rth);
+ if (removed_count)
+ ++(*removed_count);
+ }
+ }
+ else {
+ if ( !((*rthp)->u.dst.flags & DST_BALANCED) && + passedexpired && !nextstep ) {
+ nextstep = &rth->u.rt_next;
+ }
+ rthp = &rth->u.rt_next;
+ }
+ }
+
+ rt_free(expentry);
+ if (removed_count)
+ ++(*removed_count);
+
+ return nextstep;
+}
+ +#endif
+
+
/* This runs via a timer and thus is always in BH context. */ static void rt_check_expire(unsigned long dummy)
{
@@ -547,8 +597,24 @@
} /* Cleanup aged off entries. */
- *rthp = rth->u.rt_next;
- rt_free(rth);
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ /* remove all related balanced entries if necessary */
+ if ( rth->u.dst.flags & DST_BALANCED ) {
+ rthp = rt_remove_balanced_route(
+ &rt_hash_table[i].chain,
+ rth, NULL);
+ if (!rthp) {
+ break;
+ }
+ }
+ else {
+ *rthp = rth->u.rt_next;
+ rt_free(rth);
+ }
+#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
+ *rthp = rth->u.rt_next;
+ rt_free(rth);
+#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
} spin_unlock(&rt_hash_table[i].lock);
@@ -596,6 +662,9 @@
if (delay < 0) delay = ip_rt_min_delay;
+ /* flush existing multipath state*/
+ multipath_flush();
+
spin_lock_bh(&rt_flush_lock);
if (del_timer(&rt_flush_timer) && delay > 0 && rt_deadline) {
@@ -714,9 +783,29 @@
rthp = &rth->u.rt_next;
continue;
}+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ /* remove all related balanced entries if necessary */
+ if ( rth->u.dst.flags & DST_BALANCED ) {
+ int r;
+ rthp = rt_remove_balanced_route(
+ &rt_hash_table[i].chain,
+ rth,
+ &r);
+ goal -= r;
+ if (!rthp) {
+ break;
+ }
+ }
+ else {
+ *rthp = rth->u.rt_next;
+ rt_free(rth);
+ goal--;
+ }
+#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
*rthp = rth->u.rt_next; rt_free(rth); goal--; +#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ } spin_unlock_bh(&rt_hash_table[k].lock); if (goal <= 0)
@@ -797,7 +886,12 @@
spin_lock_bh(&rt_hash_table[hash].lock);
while ((rth = *rthp) != NULL) {+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ if (!(rth->u.dst.flags & DST_BALANCED) &&
+ compare_keys(&rth->fl, &rt->fl)) {
+#else
if (compare_keys(&rth->fl, &rt->fl)) {
+#endif
/* Put it first */
*rthp = rth->u.rt_next;
/*
@@ -1628,6 +1722,10 @@
}
rth->u.dst.flags= DST_HOST;+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ if ( res->fi->fib_nhs > 1 )
+ rth->u.dst.flags |= DST_BALANCED;
+#endif
if (in_dev->cnf.no_policy) rth->u.dst.flags |= DST_NOPOLICY; if (in_dev->cnf.no_xfrm) @@ -1675,7 +1773,7 @@ unsigned hash;
#ifdef CONFIG_IP_ROUTE_MULTIPATH
- if (res->fi->fib_nhs > 1 && fl->oif == 0)
+ if (res->fi && res->fi->fib_nhs > 1 && fl->oif == 0)
fib_select_multipath(fl, res);
#endif
@@ -1696,7 +1794,65 @@
struct in_device *in_dev, u32 daddr, u32 saddr, u32 tos)
{
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED + struct rtable* rth;
+ unsigned char hop, hopcount, lasthop;
+ int err = -EINVAL;
+ unsigned hash;
+ if (res->fi) {
+ hopcount = res->fi->fib_nhs;
+ }
+ else {
+ hopcount = 1;
+ }
+ lasthop = hopcount - 1;
+
+ /* distinguish between multipath and singlepath */
+ if ( hopcount < 2 ) + return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, + saddr, tos);
+
+ RTprint( KERN_DEBUG"%s: entered (hopcount: %d)\n", __FUNCTION__,
+ hopcount);
+
+ /* add all alternatives to the routing cache */
+ for ( hop = 0; hop < hopcount; ++hop ) {
+ res->nh_sel = hop;
+
+ RTprint( KERN_DEBUG"%s: entered (hopcount: %d)\n", + __FUNCTION__, hopcount);
+
+ /* create a routing cache entry */
+ err = __mkroute_input( skb, res, in_dev, daddr, saddr, tos, + &rth );
+ if ( err ) + return err;
+
+
+ /* put it into the cache */
+ hash = rt_hash_code(daddr, saddr ^ (fl->iif << 5), tos);
+ err = rt_intern_hash(hash, rth, (struct rtable**)&skb->dst);
+ if ( err ) + return err;
+
+ /* forward hop information to multipath impl. */
+ multipath_set_nhinfo(FIB_RES_NETWORK(*res),
+ FIB_RES_NETMASK(*res), + res->prefixlen, + &FIB_RES_NH(*res));
+
+
+ /* only for the last hop the reference count is handled + outside */
+ RTprint( KERN_DEBUG"%s: balanced entry created: %d\n",
+ __FUNCTION__, rth );
+ if ( hop == lasthop ) + atomic_set(&(skb->dst->__refcnt), 1);
+ }
+ return err;
+#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
return ip_mkroute_input_def(skb, res, fl, in_dev, daddr, saddr, tos);
+#endif /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */ }
@@ -2017,6 +2173,10 @@
} rth->u.dst.flags= DST_HOST;
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ if (res->fi && res->fi->fib_nhs > 1)
+ rth->u.dst.flags |= DST_BALANCED;
+#endif
if (in_dev->cnf.no_xfrm) rth->u.dst.flags |= DST_NOXFRM; if (in_dev->cnf.no_policy)
@@ -2108,7 +2268,77 @@
struct net_device *dev_out, unsigned flags)
{
+#ifdef CONFIG_IP_ROUTE_MULTIPATH_CACHED
+ u32 tos = RT_FL_TOS(oldflp);
+ unsigned char hop;
+ unsigned hash;
+ int err = -EINVAL;
+ struct rtable* rth;
+
+ if (res->fi && res->fi->fib_nhs > 1) {
+ unsigned char hopcount = res->fi->fib_nhs;
+ RTprint( KERN_DEBUG"%s: entered (hopcount: %d, fl->oif: %d)\n", + __FUNCTION__, hopcount, fl->oif);
+
+ for ( hop = 0; hop < hopcount; ++hop ) {
+ struct net_device *dev2nexthop;
+ RTprint( KERN_DEBUG"%s: hop %d of %d\n", __FUNCTION__,
+ hop, hopcount );
+
+ res->nh_sel = hop;
+
+ /* hold a work reference to the output device */
+ dev2nexthop = FIB_RES_DEV(*res);
+ dev_hold(dev2nexthop);
+
+ err = __mkroute_output(&rth, res, fl, oldflp, + dev2nexthop, flags);
+
+ /** FIXME remove debug code */
+ RTprint( "%s: balanced entry created: %d " \
+ " (GW: %u)\n",
+ __FUNCTION__,
+ &rth->u.dst,
+ FIB_RES_GW(*res) );
+
+ if ( err != 0 ) {
+ goto cleanup;
+ }
+
+ RTprint( KERN_DEBUG"%s: created successfully %d\n", + __FUNCTION__, hop );
+
+ hash = rt_hash_code(oldflp->fl4_dst, + oldflp->fl4_src ^ + (oldflp->oif << 5), tos);
+ err = rt_intern_hash(hash, rth, rp);
+ RTprint( KERN_DEBUG"%s: hashed %d\n", + __FUNCTION__, hop );
+
+ /* forward hop information to multipath impl. */
+ multipath_set_nhinfo(FIB_RES_NETWORK(*res),
+ FIB_RES_NETMASK(*res), + res->prefixlen, + &FIB_RES_NH(*res));
+ cleanup:
+ /* release work reference to output device */
+ dev_put(dev2nexthop);
+
+ if ( err != 0 ) {
+ return err;
+ }
+ }
+ RTprint( "%s: exited loop\n", __FUNCTION__ );
+ atomic_set(&(*rp)->u.dst.__refcnt, 1);
+ return err;
+ }
+ else {
+ return ip_mkroute_output_def(rp, res, fl, oldflp, dev_out, + flags);
+ }
+#else /* CONFIG_IP_ROUTE_MULTIPATH_CACHED */
return ip_mkroute_output_def(rp, res, fl, oldflp, dev_out, flags);
+#endif
}
/*
@@ -2137,6 +2367,7 @@
int free_res = 0; int err;
+
res.fi = NULL;
#ifdef CONFIG_IP_MULTIPLE_TABLES
res.r = NULL;
@@ -2186,6 +2417,8 @@
dev_put(dev_out);
dev_out = NULL;
}
+
+
if (oldflp->oif) {
dev_out = dev_get_by_index(oldflp->oif);
err = -ENODEV;
@@ -2292,9 +2525,11 @@
dev_hold(dev_out);
fl.oif = dev_out->ifindex;+make_route:
err = ip_mkroute_output(rp, &res, &fl, oldflp, dev_out, flags);
+
if (free_res)
fib_res_put(&res);
if (dev_out)
@@ -2321,6 +2556,15 @@
#endif
!((rth->fl.fl4_tos ^ flp->fl4_tos) &
(IPTOS_RT_MASK | RTO_ONLINK))) {+ /* check for multipath routes and choose one if
+ necessary */
+ if (multipath_selectroute(flp, rth, rp)) {
+ dst_hold(&(*rp)->u.dst);
+ RT_CACHE_STAT_INC(out_hit);
+ rcu_read_unlock_bh();
+ return 0;
+ }
+
rth->u.dst.lastuse = jiffies; dst_hold(&rth->u.dst); rth->u.dst.__use++;
Attached the patch as file due to problems with my email-client.
Regards
Einar.
include/net/dst.h +1 -0
@@ -48,6 +48,7 @@#define DST_NOXFRM 2#define DST_NOPOLICY 4#define DST_NOHASH 8 +#define DST_BALANCED 0x10unsigned long lastuse;unsigned long expires;
include/net/flow.h +1 -0
@@ -51,6 +51,7 @@__u8 proto;__u8 flags; +#define FLOWI_FLAG_MULTIPATHOLDROUTE 0x01 union { struct { __u16 sport;
include/net/ip_fib.h +12 -0
@@ -95,6 +95,10 @@unsigned char nh_sel;unsigned char type;unsigned char scope; +#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM +__u32 network; +__u32 netmask; +#endif struct fib_info *fi;#ifdef CONFIG_IP_MULTIPLE_TABLES struct fib_rule *r;
@@ -119,6 +123,14 @@#define FIB_RES_DEV (res) (FIB_RES_NH(res).nh_dev)#define FIB_RES_OIF (res) (FIB_RES_NH(res).nh_oif) +#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM +#define FIB_RES_NETWORK (res) ((res).network) +#define FIB_RES_NETMASK (res) ((res).netmask) +#else /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */ +#define FIB_RES_NETWORK (res) (0) +#define FIB_RES_NETMASK (res) (0) +#endif /* CONFIG_IP_ROUTE_MULTIPATH_WRANDOM */ +struct fib_table {unsigned char tb_id;unsigned tb_stamp;
include/net/route.h +69 -0
85 lines not on this page · raw message
net/ipv4/Kconfig +48 -0
54 lines not on this page · raw message
net/ipv4/Makefile +4 -0
@@ -20,6 +20,10 @@ obj-$(CONFIG_INET_IPCOMP) += ipcomp.o obj-$(CONFIG_INET_TUNNEL) += xfrm4_tunnel.o obj-$(CONFIG_IP_PNP) += ipconfig.o +obj-$(CONFIG_IP_ROUTE_MULTIPATH_RR) += multipath_rr.o +obj-$(CONFIG_IP_ROUTE_MULTIPATH_RANDOM) += multipath_random.o +obj-$(CONFIG_IP_ROUTE_MULTIPATH_WRANDOM) += multipath_wrandom.o +obj-$(CONFIG_IP_ROUTE_MULTIPATH_DRR) += multipath_drr.o obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_IP_VS) += ipvs/ obj-$(CONFIG_IP_TCPDIAG) += tcp_diag.o
net/ipv4/fib_hash.c +1 -0
@@ -261,6 +261,7 @@ err =fib_semantic_match (&f->fn_alias, flp, res, + f->fn_key, fz->fz_mask, fz->fz_order);if (err <=0 ) goto out;
net/ipv4/fib_lookup.h +2 -1
@@ -19,7 +19,8 @@/* Exported by fib_semantics.c */ extern int fib_semantic_match (struct list_head *head,const struct flowi *flp, -struct fib_result *res,int prefixlen); +struct fib_result *res,__u32 zone,__u32 mask, +int prefixlen);extern void fib_release_info (struct fib_info *); extern struct fib_info *fib_create_info(const struct rtmsg *r, struct kern_rta *rta,
net/ipv4/fib_semantics.c +7 -1
@@ -763,7 +763,8 @@ }int fib_semantic_match (struct list_head *head,const struct flowi *flp, -struct fib_result *res,int prefixlen) +struct fib_result *res,__u32 zone,__u32 mask, +int prefixlen) {struct fib_alias *fa;int nh_sel =0 ;
@@ -827,6 +828,11 @@ res->type = fa->fa_type; res->scope = fa->fa_scope; res->fi = fa->fa_info; +#ifdef CONFIG_IP_ROUTE_MULTIPATH_WRANDOM + res->netmask = mask; + res->network = zone & + (0xFFFFFFFF >> (32 - prefixlen)); +#endif atomic_inc (&res->fi->fib_clntref);return 0 ; }
net/ipv4/multipath_drr.c +292 -0
292 lines not on this page · raw message
net/ipv4/multipath_random.c +124 -0
124 lines not on this page · raw message
net/ipv4/multipath_rr.c +118 -0
118 lines not on this page · raw message
net/ipv4/multipath_wrandom.c +374 -0
374 lines not on this page · raw message
net/ipv4/route.c +248 -4
362 lines not on this page · raw message
David S. Miller
maintainerQuoted 8 lines · On Mon, 20 Dec 2004 12:19:43 +0100 Einar Lück <[email protected]> wrote:
This patch is an approach towards solving some problems with the current multipath implementation:
* routing cache allows only one route to be cached for a certain search key
* a mulitpath/load balancing decision is only made in case a corresponding route is not yet cached
In the scenarios, that are relevant to us (high amount of outgoing connection requests), this is a serious problem.
I agree that per-connection attempt a new multipath decision should be made, but within a flow I disagree.
This needs to be flow based.
Can you describe more precisely "the scenerios, that are relevant to us"?
If you are only interested in more precise multipathing when TCP connections on the local system are made, this we can implement via a flag to the ipv4 routing cache which forces a new multipath decision when TCP sockets have their identity established. We have a precise interface that is invoked at this time, called ip_route_connect(). So that is where we would pass in some flag to indicate that we desire the new multipath behavior.
If you want this behavior on a router, you will need to mark the packets using something like firewall marking on the SKB, then this mark would be used at route cache lookup time to determine what kind of multipath decisions to make.
There is no way we can enable the new behavior for every routing cache lookup.
Quoted 2 lines · David S. Miller
Can you describe more precisely "the scenerios, that are relevant to us"?
The scenarios we have in mind are setups in which a set of collaborating servers steadly establish connections among each other with a very high rate. This high rate requirement drove us to consider the inclusion of all alternative routes into the routing cache because the corresponding delay for each connection establishment is low and the load is balanced over all available routes. That's why we did not consider a slow lookup in the fib for each connection established.
Regards,
Einar.
David S. Miller
maintainerQuoted 7 lines · On Wed, 09 Feb 2005 14:28:49 +0100 Einar Lück <[email protected]> wrote:
The scenarios we have in mind are setups in which a set of collaborating servers steadly establish connections among each other with a very high rate. This high rate requirement drove us to consider the inclusion of all alternative routes into the routing cache because the corresponding delay for each connection establishment is low and the load is balanced over all available routes. That's why we did not consider a slow lookup in the fib for each connection established.
So essentially you want per-flow multipathing. Except that you're implementation is over-optimizing it to the point where it's only per-flow for your specific case where the connections are short lived and high rate.
This hurts long lasting connections.
So I'm pretty much against this change. Do it right by making it occur per-connection attempt, it's not my problem to figure out how to do that efficiently, it's your's :-)
Quoted 9 lines · David S. Miller
So essentially you want per-flow multipathing. Except that you're implementation is over-optimizing it to the point where it's only per-flow for your specific case where the connections are short lived and high rate.
This hurts long lasting connections.
So I'm pretty much against this change. Do it right by making it occur per-connection attempt, it's not my problem to figure out how to do that efficiently, it's your's :-)
We do not want per-flow multipathing. We want per connection multipathing with fast route lookups (that's why we have all routes in the cache). That is exactly what we implemented. Our tests prove that a connection keeps its route as long as it lives (the dstentry remains associated with the socket). That's why I do not really understand why our approach hurts long lasting connections in any way. Can you explain your point more precisely?
Regards,
Einar.
David S. Miller
maintainerQuoted 7 lines · On Wed, 09 Feb 2005 21:23:57 +0100 Einar Lück <[email protected]> wrote:
We do not want per-flow multipathing. We want per connection multipathing with fast route lookups (that's why we have all routes in the cache). That is exactly what we implemented. Our tests prove that a connection keeps its route as long as it lives (the dstentry remains associated with the socket). That's why I do not really understand why our approach hurts long lasting connections in any way. Can you explain your point more precisely?
This was brought up before. It's the case where the system is acting as a router, you have to consider that case and not just the one where the local system is where the connections are originating from.
Your trick only works because of how routes are cached per-socket. Once you get into the realm of traffic going through the machine as a router, the trick stops to work.
Quoted 7 lines · David S. Miller
This was brought up before. It's the case where the system is acting as a router, you have to consider that case and not just the one where the local system is where the connections are originating from.
Your trick only works because of how routes are cached per-socket. Once you get into the realm of traffic going through the machine as a router, the trick stops to work.
We considered the routing case: in the routing case ip_route_input is called. In this case we just select the first route in the cache which is always the same (we ensure that). Consequently, the routing behaviour is not changed in this case and remains in the way you like it.
Regards,
Einar.
David S. Miller
maintainerQuoted 4 lines · On Wed, 09 Feb 2005 21:42:39 +0100 Einar Lück <[email protected]> wrote:
We considered the routing case: in the routing case
ip_route_inputis called. In this case we just select the first route in the cache which is always the same (we ensure that). Consequently, the routing behaviour is not changed in this case and remains in the way you like it.
Indeed. You're right. Let me re-review your second patch with this new understanding in mind :-)