]> www.infradead.org Git - users/jedix/linux-maple.git/commit
xfrm: policy: don't iterate inexact policies twice at insert time
authorFlorian Westphal <fw@strlen.de>
Thu, 22 Aug 2024 13:04:30 +0000 (15:04 +0200)
committerSteffen Klassert <steffen.klassert@secunet.com>
Sat, 24 Aug 2024 07:55:36 +0000 (09:55 +0200)
commit33f611cf7d52ffdaebdcd6e42672ca1d06e22974
tree8a108d2cd4e7f5f9bee56e2cc77ac90876fd4cb2
parent9c5b6d4e33dd78a0511ec34756d783b7e36028c2
xfrm: policy: don't iterate inexact policies twice at insert time

Since commit
6be3b0db6db8 ("xfrm: policy: add inexact policy search tree infrastructure")
policy lookup no longer walks a list but has a set of candidate lists.

This set has to be searched for the best match.
In case there are several matches, the priority wins.

If the priority is also the same, then the historic behaviour with
a single list was to return the first match (first-in-list).

With introduction of serval lists, this doesn't work and a new
'pos' member was added that reflects the xfrm_policy structs position
in the list.

This value is not exported to userspace and it does not need to be
the 'position in the list', it just needs to make sure that
a->pos < b->pos means that a was added to the lists more recently
than b.

This re-walk is expensive when many inexact policies are in use.

Speed this up: when appending the policy to the end of the walker list,
then just take the ->pos value of the last entry made and add 1.

Add a slowpath version to prevent overflow, if we'd assign UINT_MAX
then iterate the entire list and fix the ordering.

While this speeds up insertion considerably finding the insertion spot
in the inexact list still requires a partial list walk.

This is addressed in followup patches.

Before:
./xfrm_policy_add_speed.sh
Inserted 1000   policies in 72 ms
Inserted 10000  policies in 1540 ms
Inserted 100000 policies in 334780 ms

After:
Inserted 1000   policies in 68 ms
Inserted 10000  policies in 1137 ms
Inserted 100000 policies in 157307 ms

Reported-by: Noel Kuntze <noel@familie-kuntze.de>
Cc: Tobias Brunner <tobias@strongswan.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c