Skip to contentSkip to conversation

Optimize lookup of /0 xfrm policies

PATCH Superseded Yannick Brosseau 1 participant 1 message Aug 30, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Optimize lookup of /0 xfrm policies

Currently, all the xfrm policies that are not /32 end up in the inexact policies linked list which take a long time to lookup.

We can optimize the case where we have a /0 prefix in the policy, which means we can match any address to that part.
We do this by putting those policies in the direct hash table after zeroing the address part.
At lookup time, we do an additional lookup with the packet address and either the destination or source address zeroed out.
We still call xfrm_policy_match to validate that the packet match the selector.

In our tests, with this optimization we reduce softirq cpu utilisation from about 40% to 7% with 3k policies.

---
 net/xfrm/xfrm_hash.h   | 10 +++++
 net/xfrm/xfrm_policy.c | 88 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 96 insertions(+), 2 deletions(-)
net/xfrm/xfrm_hash.h +10 -0
index 61be810389d8..40997fb5336d 100644
@@ -145,6 +145,16 @@ static inline unsigned int __sel_hash(const struct xfrm_selector *sel,
 	const xfrm_address_t *saddr = &sel->saddr;
 	unsigned int h = 0;
 
+	/* A selector with a prefixlen of zero can basically be ignored in
+	 * the matching. To speed up the lookup, let's hash it without those
+	 * component. In the lookup, we'll do an additional check for a zero
+	 * daddr and a zero saddr.
+	 */
+	if (sel->prefixlen_d == 0)
+		dbits = 0;
+	if (sel->prefixlen_s == 0)
+		sbits = 0;
+
 	switch (family) {
 	case AF_INET:
 		if (sel->prefixlen_d < dbits ||
net/xfrm/xfrm_policy.c +86 -2

113 lines not on this page · raw message

Signature · 1 line
2.18.0