ila: Optimization to preserve value of early demux
Subsystems (3)
v6 cover ila: Optimization to preserve value of early demux
In the current implementation of ILA, LWT is used to perform translation on both the input and output paths. This is functional, however there is a big performance hit in the receive path. Early demux occurs before the routing lookup (a hit actually obviates the route lookup). Therefore the stack currently performs early demux before translation so that a local connection with ILA addresses is never matched. Note that this issue is not just with ILA, but pretty much any translated or encapsulated packet handled by LWT would miss the opportunity for early demux. Solving the general problem seems non trivial since we would need to move the route lookup before early demx thereby mitigating the value.
This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This done by hooking in to NF_INET_PRE_ROUTING
For the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.
This patch set:
- Add an rhashtable function to atomically replace and element. This is useful to implement sub-trees from a table entry without needing to use a special anchor structure as the table entry.
- Add a start callback for starting a netlink dump.
- Creates an ila directory under net/ipv6 and moves ila.c to it. ila.c is split into ila_common.c and ila_lwt.c.
- Implement a table to do identifier->locator mapping. This is an rhashtable (in ila_xlat.c).
- Configuration for the table with netlink.
- Add a hook into NF_INET_PRE_ROUTING to perform ILA translation before early demux.
Changes in v2:
- Use iptables targets instead of a new xfrm function
Changes in v3:
- Add __rcu to next pointer in struct ila_map
Changes in v4:
- Use hook for NF_INET_PRE_ROUTING
Changed in v5:
- Register hooks per namespace using nf_register_net_hooks
- Only register hooks when first mapping is actually added
Changed in v6:
- Remove gfp argument in alloc_ila_locks, it is unnecessary
- Set registered_hooks properly when hooks are registered
Testing:
Running 200 netperf TCP_RR streams
No ILA, baseline
79.26% CPU utilization
1678282 tps
104/189/390 50/90/99% latencies
ILA before fix (LWT on both input and output)
81.91% CPU utilization
1464723 tps (-14.5% from baseline)
121/215/411 50/90/99% latencies
ILA after fix
80.62% CPU utilization
1622985 (-3.4% from baseline)
110/191/347 50/90/99% latencies
Tom Herbert (4):
ila: Create net/ipv6/ila directory
rhashtable: add function to replace an element
netlink: add a start callback for starting a netlink dump
ila: Add generic ILA translation facility
include/linux/netlink.h | 2 + include/linux/rhashtable.h | 82 ++++++ include/net/genetlink.h | 2 + include/net/ila.h | 18 ++ include/uapi/linux/ila.h | 22 ++ net/ipv6/Makefile | 2 +- net/ipv6/ila.c | 229 --------------- net/ipv6/ila/Makefile | 7 + net/ipv6/ila/ila.h | 48 ++++ net/ipv6/ila/ila_common.c | 103 +++++++ net/ipv6/ila/ila_lwt.c | 152 ++++++++++ net/ipv6/ila/ila_xlat.c | 681 +++++++++++++++++++++++++++++++++++++++++++++ net/netlink/af_netlink.c | 4 + net/netlink/genetlink.c | 16 ++ 14 files changed, 1138 insertions(+), 230 deletions(-) create mode 100644 include/net/ila.h delete mode 100644 net/ipv6/ila.c create mode 100644 net/ipv6/ila/Makefile create mode 100644 net/ipv6/ila/ila.h create mode 100644 net/ipv6/ila/ila_common.c create mode 100644 net/ipv6/ila/ila_lwt.c create mode 100644 net/ipv6/ila/ila_xlat.c
Signature · 1 line
2.4.6
PATCH v6 1/4 ila: Create net/ipv6/ila directory
Create ila directory in preparation for supporting other hooks in the kernel than LWT for doing ILA. This includes:
- Moving ila.c to ila/ila_lwt.c
- Splitting out some common functions into ila_common.c
--- net/ipv6/Makefile | 2 +- net/ipv6/ila.c | 229 ---------------------------------------------- net/ipv6/ila/Makefile | 7 ++ net/ipv6/ila/ila.h | 46 ++++++++++ net/ipv6/ila/ila_common.c | 95 +++++++++++++++++++ net/ipv6/ila/ila_lwt.c | 152 ++++++++++++++++++++++++++++++ 6 files changed, 301 insertions(+), 230 deletions(-) delete mode 100644 net/ipv6/ila.c create mode 100644 net/ipv6/ila/Makefile create mode 100644 net/ipv6/ila/ila.h create mode 100644 net/ipv6/ila/ila_common.c create mode 100644 net/ipv6/ila/ila_lwt.c
net/ipv6/Makefile +1 -1
@@ -34,7 +34,7 @@ obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o obj-$(CONFIG_INET6_XFRM_MODE_BEET) += xfrm6_mode_beet.o obj-$(CONFIG_IPV6_MIP6) += mip6.o -obj-$(CONFIG_IPV6_ILA) += ila.o +obj-$(CONFIG_IPV6_ILA) += ila/ obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_IPV6_VTI) += ip6_vti.o
net/ipv6/ila.c deleted +0 -229
229 lines not on this page · raw message
net/ipv6/ila/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for ILA module +# + +obj-$(CONFIG_IPV6_ILA) += ila.o + +ila-objs := ila_common.o ila_lwt.o
net/ipv6/ila/ila.h new file +46 -0
46 lines not on this page · raw message
net/ipv6/ila/ila_common.c new file +95 -0
95 lines not on this page · raw message
net/ipv6/ila/ila_lwt.c new file +152 -0
152 lines not on this page · raw message
Signature · 1 line
2.4.6
PATCH v6 2/4 rhashtable: add function to replace an element
In reply to Tom HerbertAdd the rhashtable_replace_fast function. This replaces one object in the table with another atomically. The hashes of the new and old objects must be equal.
--- include/linux/rhashtable.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
include/linux/rhashtable.h +82 -0
@@ -819,4 +819,86 @@ out: return err; } +/* Internal function, please use rhashtable_replace_fast() instead */ +static inline int __rhashtable_replace_fast ( +struct rhashtable *ht,struct bucket_table *tbl, +struct rhash_head *obj_old,struct rhash_head *obj_new, +const struct rhashtable_params params) +{ +struct rhash_head __rcu **pprev; +struct rhash_head *he; +spinlock_t *lock; +unsigned int hash; +int err = -ENOENT ; + +/* Minimally, the old and new objects must have same hash +* (which should mean identifiers are the same). +*/ + hash =rht_head_hashfn (ht, tbl, obj_old, params); +if (hash !=rht_head_hashfn (ht, tbl, obj_new, params)) +return -EINVAL ; + + lock =rht_bucket_lock (tbl, hash); + +spin_lock_bh (lock); + + pprev = &tbl->buckets[hash]; +rht_for_each (he, tbl, hash) { +if (he != obj_old) { + pprev = &he->next; +continue ; + } + +rcu_assign_pointer (obj_new->next, obj_old->next); +rcu_assign_pointer (*pprev, obj_new); + err =0 ; +break ; + } + +spin_unlock_bh (lock); + +return err; +} + +/** +* rhashtable_replace_fast - replace an object in hash table +* @ht: hash table +* @obj_old: pointer to hash head inside object being replaced +* @obj_new: pointer to hash head inside object which is new +* @params: hash table parameters +* +* Replacing an object doesn't affect the number of elements in the hash table +* or bucket, so we don't need to worry about shrinking or expanding the +* table here. +* +* Returns zero on success, -ENOENT if the entry could not be found, +* -EINVAL if hash is not the same for the old and new objects. +*/ +static inline int rhashtable_replace_fast ( +struct rhashtable *ht,struct rhash_head *obj_old, +struct rhash_head *obj_new, +const struct rhashtable_params params) +{ +struct bucket_table *tbl; +int err; + +rcu_read_lock (); + + tbl =rht_dereference_rcu (ht->tbl, ht); + +/* Because we have already taken (and released) the bucket +* lock in old_tbl, if we find that future_tbl is not yet +* visible then that guarantees the entry to still be in +* the old tbl if it exists. +*/ +while ((err =__rhashtable_replace_fast (ht, tbl, obj_old, + obj_new, params)) && + (tbl =rht_dereference_rcu (tbl->future_tbl, ht))) + ; + +rcu_read_unlock (); + +return err; +} +#endif /* _LINUX_RHASHTABLE_H */
Signature · 1 line
2.4.6
PATCH v6 4/4 ila: Add generic ILA translation facility
In reply to Tom HerbertThis patch implements an ILA tanslation table. This table can be configured with identifier to locator mappings, and can be be queried to resolve a mapping. Queries can be parameterized based on interface, direction (incoming or outoing), and matching locator. The table is implemented using rhashtable and is configured via netlink (through "ip ila .." in iproute).
The table may be used as alternative means to do do ILA tanslations other than the lw tunnels
--- include/net/ila.h | 18 ++ include/uapi/linux/ila.h | 22 ++ net/ipv6/ila/Makefile | 2 +- net/ipv6/ila/ila.h | 2 + net/ipv6/ila/ila_common.c | 8 + net/ipv6/ila/ila_xlat.c | 681 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 732 insertions(+), 1 deletion(-) create mode 100644 include/net/ila.h create mode 100644 net/ipv6/ila/ila_xlat.c
include/net/ila.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* ILA kernel interface +* +* Copyright (c) 2015 Tom Herbert <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +*/ + +#ifndef _NET_ILA_H +#define _NET_ILA_H + +int ila_xlat_outgoing (struct sk_buff *skb); +int ila_xlat_incoming (struct sk_buff *skb); + +#endif /* _NET_ILA_H */
include/uapi/linux/ila.h +22 -0
@@ -3,13 +3,35 @@#ifndef _UAPI_LINUX_ILA_H#define _UAPI_LINUX_ILA_H +/* NETLINK_GENERIC related info */ +#define ILA_GENL_NAME "ila" +#define ILA_GENL_VERSION 0x1 +enum {ILA_ATTR_UNSPEC ,ILA_ATTR_LOCATOR ,/* u64 */ +ILA_ATTR_IDENTIFIER ,/* u64 */ +ILA_ATTR_LOCATOR_MATCH ,/* u64 */ +ILA_ATTR_IFINDEX ,/* s32 */ +ILA_ATTR_DIR ,/* u32 */ __ILA_ATTR_MAX, };#define ILA_ATTR_MAX (__ILA_ATTR_MAX - 1) +enum { +ILA_CMD_UNSPEC , +ILA_CMD_ADD , +ILA_CMD_DEL , +ILA_CMD_GET , + + __ILA_CMD_MAX, +}; + +#define ILA_CMD_MAX (__ILA_CMD_MAX - 1) + +#define ILA_DIR_IN (1 << 0) +#define ILA_DIR_OUT (1 << 1) +#endif /* _UAPI_LINUX_ILA_H */
net/ipv6/ila/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-$(CONFIG_IPV6_ILA) += ila.o -ila-objs := ila_common.o ila_lwt.o +ila-objs := ila_common.o ila_lwt.o ila_xlat.o
net/ipv6/ila/ila.h +2 -0
@@ -42,5 +42,7 @@ void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p);int ila_lwt_init (void );void ila_lwt_fini (void ); +int ila_xlat_init (void ); +void ila_xlat_fini (void );#endif /* __ILA_H */
net/ipv6/ila/ila_common.c +8 -0
@@ -80,12 +80,20 @@ static int __init ila_init(void)if (ret) goto fail_lwt; + ret =ila_xlat_init (); +if (ret) + goto fail_xlat; + +return 0 ; +fail_xlat: +ila_lwt_fini (); fail_lwt:return ret; } static void __exit ila_fini(void) { +ila_xlat_fini ();ila_lwt_fini (); }
net/ipv6/ila/ila_xlat.c new file +681 -0
681 lines not on this page · raw message
Signature · 1 line
2.4.6
PATCH v6 3/4 netlink: add a start callback for starting a netlink dump
In reply to Tom HerbertThe start callback allows the caller to set up a context for the dump callbacks. Presumably, the context can then be destroyed in the done callback.
--- include/linux/netlink.h | 2 ++ include/net/genetlink.h | 2 ++ net/netlink/af_netlink.c | 4 ++++ net/netlink/genetlink.c | 16 ++++++++++++++++ 4 files changed, 24 insertions(+)
include/linux/netlink.h +2 -0
@@ -131,6 +131,7 @@ netlink_skb_clone(struct sk_buff *skb, gfp_t gfp_mask)struct netlink_callback {struct sk_buff *skb;const struct nlmsghdr *nlh; +int (*start)(struct netlink_callback *);int (*dump)(struct sk_buff * skb,struct netlink_callback *cb);int (*done)(struct netlink_callback *cb);
@@ -153,6 +154,7 @@ struct nlmsghdr * __nlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, int type, int len, int flags);struct netlink_dump_control { +int (*start)(struct netlink_callback *);int (*dump)(struct sk_buff *skb,struct netlink_callback *);int (*done)(struct netlink_callback *);void *data;
include/net/genetlink.h +2 -0
@@ -114,6 +114,7 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)* @flags: flags * @policy: attribute validation policy * @doit: standard command callback +* @start: start callback for dumps * @dumpit: callback for dumpers * @done: completion callback for dumps * @ops_list: operations list
@@ -122,6 +123,7 @@ struct genl_ops {const struct nla_policy *policy;int (*doit)(struct sk_buff *skb,struct genl_info *info); +int (*start)(struct netlink_callback *cb);int (*dumpit)(struct sk_buff *skb,struct netlink_callback *cb);int (*done)(struct netlink_callback *cb);
net/netlink/af_netlink.c +4 -0
@@ -2915,6 +2915,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, cb = &nlk->cb;memset (cb,0 ,sizeof (*cb)); + cb->start = control->start; cb->dump = control->dump; cb->done = control->done; cb->nlh = nlh;
@@ -2927,6 +2928,9 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,mutex_unlock (nlk->cb_mutex); +if (cb->start) + cb->start (cb); + ret =netlink_dump (sk);sock_put (sk);
net/netlink/genetlink.c +16 -0
@@ -513,6 +513,20 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, }EXPORT_SYMBOL (genlmsg_put); +static int genl_lock_start (struct netlink_callback *cb) +{ +/* our ops are always const - netlink API doesn't propagate that */ +const struct genl_ops *ops = cb->data; +int rc =0 ; + +if (ops->start) { +genl_lock (); + rc = ops->start (cb); +genl_unlock (); + } +return rc; +} +static int genl_lock_dumpit (struct sk_buff *skb,struct netlink_callback *cb) {/* our ops are always const - netlink API doesn't propagate that */
@@ -577,6 +591,7 @@ static int genl_family_rcv_msg(struct genl_family *family, .module = family->module, /* we have const, but the netlink API doesn't */ .data = (void *)ops, + .start = genl_lock_start, .dump = genl_lock_dumpit, .done = genl_lock_done, };
@@ -588,6 +603,7 @@ static int genl_family_rcv_msg(struct genl_family *family, }else {struct netlink_dump_control c = { .module = family->module, + .start = ops->start, .dump = ops->dumpit, .done = ops->done, };
Signature · 1 line
2.4.6
David Miller
maintainerFrom: Tom Herbert <[email protected]>
Date: Tue, 15 Dec 2015 15:41:34 -0800
Quoted 12 lines
In the current implementation of ILA, LWT is used to perform translation on both the input and output paths. This is functional, however there is a big performance hit in the receive path. Early demux occurs before the routing lookup (a hit actually obviates the route lookup). Therefore the stack currently performs early demux before translation so that a local connection with ILA addresses is never matched. Note that this issue is not just with ILA, but pretty much any translated or encapsulated packet handled by LWT would miss the opportunity for early demux. Solving the general problem seems non trivial since we would need to move the route lookup before early demx thereby mitigating the value.
Quoted 7 lines
This patch set addresses the issue for ILA by adding a fast locator lookup that occurs before early demux. This done by hooking in to
NF_INET_PRE_ROUTINGFor the backend we implement an rhashtable that contains identifier to locator to mappings. The table also allows more specific matches that include original locator and interface.
Series applied, thanks Tom.