]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
mpls: reduce memory usage of routes
authorRobert Shearman <rshearma@brocade.com>
Tue, 27 Oct 2015 00:37:36 +0000 (00:37 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 28 Oct 2015 02:52:59 +0000 (19:52 -0700)
commitcf4b24f0024fc2e3fbc653a659356d224b5b9172
tree131a351e670f5d86c725c9e140acee1c93b11ce9
parentb4e04fc7357b6cef0856cb14b42306af1af990e5
mpls: reduce memory usage of routes

Nexthops for MPLS routes have a via address field sized for the
largest via address that is expected, which is 32 bytes. This means
that in the most common case of having ipv4 via addresses, 28 bytes of
memory more than required are used per nexthop. In the other common
case of an ipv6 nexthop then 16 bytes more than required are
used. With large numbers of MPLS routes this extra memory usage could
start to become significant.

To avoid allocating memory for a maximum length via address when not
all of it is required and to allow for ease of iterating over
nexthops, then the via addresses are changed to be stored in the same
memory block as the route and nexthops, but in an array after the end
of the array of nexthops. New accessors are provided to retrieve a
pointer to the via address.

To allow for O(1) access without having to store a pointer or offset
per nh, the via address for each nexthop is sized according to the
maximum via address for any nexthop in the route, which is stored in a
new route field, rt_max_alen, but this is in an existing hole in
struct mpls_route so it doesn't increase the size of the
structure. Each via address is ensured to be aligned to VIA_ALEN_ALIGN
to account for architectures that don't allow unaligned accesses.

Signed-off-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mpls/af_mpls.c
net/mpls/internal.h