aboutsummaryrefslogtreecommitdiffstats
path: root/net/mpls/af_mpls.c
diff options
context:
space:
mode:
authorDavid Ahern <dsa@cumulusnetworks.com>2017-03-31 10:14:01 -0400
committerDavid S. Miller <davem@davemloft.net>2017-04-01 23:21:44 -0400
commit59b209667a3bef240ca5da111ce1931f29fa179f (patch)
tree73ea0874d2188dc6610fd3a83dbe53a58d74a505 /net/mpls/af_mpls.c
parent77ef013aadadd248843ad90022f36ba177b24e7f (diff)
net: mpls: change mpls_route layout
Move labels to the end of mpls_nh as a 0-sized array and within mpls_route move the via for a nexthop after the mpls_nh. The new layout becomes: +----------------------+ | mpls_route | +----------------------+ | mpls_nh 0 | +----------------------+ | alignment padding | 4 bytes for odd number of labels; 0 for even +----------------------+ | via[rt_max_alen] 0 | +----------------------+ | alignment padding | via's aligned on sizeof(unsigned long) +----------------------+ | ... | +----------------------+ | mpls_nh n-1 | +----------------------+ | via[rt_max_alen] n-1 | +----------------------+ Memory allocated for nexthop + via is constant across all nexthops and their via. It is based on the maximum number of labels across all nexthops and the maximum via length. The size is saved in the mpls_route as rt_nh_size. Accessing a nexthop becomes rt->rt_nh + index * rt->rt_nh_size. The offset of the via address from a nexthop is saved as rt_via_offset so that given an mpls_nh pointer the via for that hop is simply nh + rt->rt_via_offset. With prior code, memory allocated per mpls_route with 1 nexthop: via is an ethernet address - 64 bytes via is an ipv4 address - 64 via is an ipv6 address - 72 With this patch set, memory allocated per mpls_route with 1 nexthop and 1 or 2 labels: via is an ethernet address - 56 bytes via is an ipv4 address - 56 via is an ipv6 address - 64 The 8-byte reduction is due to the previous patch; the change introduced by this patch has no impact on the size of allocations for 1 or 2 labels. Performance impact of this change was examined using network namespaces with veth pairs connecting namespaces. ns0 inserts the packet to the label-switched path using an lwt route with encap mpls. ns1 adds 1 or 2 labels depending on test, ns2 (and ns3 for 2-label test) pops the label and forwards. ns3 (or ns4) for a 2-label is the destination. Similar series of namespaces used for 2-nexthop test. Intent is to measure changes to latency (overhead in manipulating the packet) in the forwarding path. Tests used netperf with UDP_RR. IPv4: current patches 1 label, 1 nexthop 29908 30115 2 label, 1 nexthop 29071 29612 1 label, 2 nexthop 29582 29776 2 label, 2 nexthop 29086 29149 IPv6: current patches 1 label, 1 nexthop 24502 24960 2 label, 1 nexthop 24041 24407 1 label, 2 nexthop 23795 23899 2 label, 2 nexthop 23074 22959 In short, the change has no effect to a modest increase in performance. This is expected since this patch does not really have an impact on routes with 1 or 2 labels (the current limit) and 1 or 2 nexthops. Signed-off-by: David Ahern <dsa@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/mpls/af_mpls.c')
-rw-r--r--net/mpls/af_mpls.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 665dec84f001..1863b94133e4 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -24,6 +24,8 @@
24#include <net/nexthop.h> 24#include <net/nexthop.h>
25#include "internal.h" 25#include "internal.h"
26 26
27#define MAX_NEW_LABELS 2
28
27/* Maximum number of labels to look ahead at when selecting a path of 29/* Maximum number of labels to look ahead at when selecting a path of
28 * a multipath route 30 * a multipath route
29 */ 31 */
@@ -60,10 +62,7 @@ EXPORT_SYMBOL_GPL(mpls_output_possible);
60 62
61static u8 *__mpls_nh_via(struct mpls_route *rt, struct mpls_nh *nh) 63static u8 *__mpls_nh_via(struct mpls_route *rt, struct mpls_nh *nh)
62{ 64{
63 u8 *nh0_via = PTR_ALIGN((u8 *)&rt->rt_nh[rt->rt_nhn], VIA_ALEN_ALIGN); 65 return (u8 *)nh + rt->rt_via_offset;
64 int nh_index = nh - rt->rt_nh;
65
66 return nh0_via + rt->rt_max_alen * nh_index;
67} 66}
68 67
69static const u8 *mpls_nh_via(const struct mpls_route *rt, 68static const u8 *mpls_nh_via(const struct mpls_route *rt,
@@ -189,6 +188,11 @@ static u32 mpls_multipath_hash(struct mpls_route *rt, struct sk_buff *skb)
189 return hash; 188 return hash;
190} 189}
191 190
191static struct mpls_nh *mpls_get_nexthop(struct mpls_route *rt, u8 index)
192{
193 return (struct mpls_nh *)((u8 *)rt->rt_nh + index * rt->rt_nh_size);
194}
195
192/* number of alive nexthops (rt->rt_nhn_alive) and the flags for 196/* number of alive nexthops (rt->rt_nhn_alive) and the flags for
193 * a next hop (nh->nh_flags) are modified by netdev event handlers. 197 * a next hop (nh->nh_flags) are modified by netdev event handlers.
194 * Since those fields can change at any moment, use READ_ONCE to 198 * Since those fields can change at any moment, use READ_ONCE to
@@ -206,7 +210,7 @@ static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
206 * one path 210 * one path
207 */ 211 */
208 if (rt->rt_nhn == 1) 212 if (rt->rt_nhn == 1)
209 goto out; 213 return rt->rt_nh;
210 214
211 alive = READ_ONCE(rt->rt_nhn_alive); 215 alive = READ_ONCE(rt->rt_nhn_alive);
212 if (alive == 0) 216 if (alive == 0)
@@ -227,7 +231,7 @@ static struct mpls_nh *mpls_select_multipath(struct mpls_route *rt,
227 } endfor_nexthops(rt); 231 } endfor_nexthops(rt);
228 232
229out: 233out:
230 return &rt->rt_nh[nh_index]; 234 return mpls_get_nexthop(rt, nh_index);
231} 235}
232 236
233static bool mpls_egress(struct net *net, struct mpls_route *rt, 237static bool mpls_egress(struct net *net, struct mpls_route *rt,
@@ -466,19 +470,20 @@ struct mpls_route_config {
466 int rc_mp_len; 470 int rc_mp_len;
467}; 471};
468 472
469static struct mpls_route *mpls_rt_alloc(u8 num_nh, u8 max_alen) 473/* all nexthops within a route have the same size based on max
474 * number of labels and max via length for a hop
475 */
476static struct mpls_route *mpls_rt_alloc(u8 num_nh, u8 max_alen, u8 max_labels)
470{ 477{
471 u8 max_alen_aligned = ALIGN(max_alen, VIA_ALEN_ALIGN); 478 u8 nh_size = MPLS_NH_SIZE(max_labels, max_alen);
472 struct mpls_route *rt; 479 struct mpls_route *rt;
473 480
474 rt = kzalloc(ALIGN(sizeof(*rt) + num_nh * sizeof(*rt->rt_nh), 481 rt = kzalloc(sizeof(*rt) + num_nh * nh_size, GFP_KERNEL);
475 VIA_ALEN_ALIGN) +
476 num_nh * max_alen_aligned,
477 GFP_KERNEL);
478 if (rt) { 482 if (rt) {
479 rt->rt_nhn = num_nh; 483 rt->rt_nhn = num_nh;
480 rt->rt_nhn_alive = num_nh; 484 rt->rt_nhn_alive = num_nh;
481 rt->rt_max_alen = max_alen_aligned; 485 rt->rt_nh_size = nh_size;
486 rt->rt_via_offset = MPLS_NH_VIA_OFF(max_labels);
482 } 487 }
483 488
484 return rt; 489 return rt;
@@ -892,7 +897,7 @@ static int mpls_route_add(struct mpls_route_config *cfg)
892 goto errout; 897 goto errout;
893 898
894 err = -ENOMEM; 899 err = -ENOMEM;
895 rt = mpls_rt_alloc(nhs, max_via_alen); 900 rt = mpls_rt_alloc(nhs, max_via_alen, MAX_NEW_LABELS);
896 if (!rt) 901 if (!rt)
897 goto errout; 902 goto errout;
898 903
@@ -1964,7 +1969,7 @@ static int resize_platform_label_table(struct net *net, size_t limit)
1964 /* In case the predefined labels need to be populated */ 1969 /* In case the predefined labels need to be populated */
1965 if (limit > MPLS_LABEL_IPV4NULL) { 1970 if (limit > MPLS_LABEL_IPV4NULL) {
1966 struct net_device *lo = net->loopback_dev; 1971 struct net_device *lo = net->loopback_dev;
1967 rt0 = mpls_rt_alloc(1, lo->addr_len); 1972 rt0 = mpls_rt_alloc(1, lo->addr_len, MAX_NEW_LABELS);
1968 if (!rt0) 1973 if (!rt0)
1969 goto nort0; 1974 goto nort0;
1970 RCU_INIT_POINTER(rt0->rt_nh->nh_dev, lo); 1975 RCU_INIT_POINTER(rt0->rt_nh->nh_dev, lo);
@@ -1978,7 +1983,7 @@ static int resize_platform_label_table(struct net *net, size_t limit)
1978 } 1983 }
1979 if (limit > MPLS_LABEL_IPV6NULL) { 1984 if (limit > MPLS_LABEL_IPV6NULL) {
1980 struct net_device *lo = net->loopback_dev; 1985 struct net_device *lo = net->loopback_dev;
1981 rt2 = mpls_rt_alloc(1, lo->addr_len); 1986 rt2 = mpls_rt_alloc(1, lo->addr_len, MAX_NEW_LABELS);
1982 if (!rt2) 1987 if (!rt2)
1983 goto nort2; 1988 goto nort2;
1984 RCU_INIT_POINTER(rt2->rt_nh->nh_dev, lo); 1989 RCU_INIT_POINTER(rt2->rt_nh->nh_dev, lo);