Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a54ad72

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: policy: remove remaining use of inexact list
No consumers anymore, remove it. After this, insertion of policies no longer require list walk of all inexact policies but only those that are reachable via the candidate sets. This gives almost linear insertion speeds provided the inserted policies are for non-overlapping networks. Before: Inserted 1000 policies in 70 ms Inserted 10000 policies in 1155 ms Inserted 100000 policies in 216848 ms After: Inserted 1000 policies in 56 ms Inserted 10000 policies in 478 ms Inserted 100000 policies in 4580 ms Insertion of 1m entries takes about ~40s after this change on my test vm. Cc: Noel Kuntze <[email protected]> Cc: Tobias Brunner <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 563d5ca commit a54ad72

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed

include/net/xfrm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ struct xfrm_policy {
555555
u16 family;
556556
struct xfrm_sec_ctx *security;
557557
struct xfrm_tmpl xfrm_vec[XFRM_MAX_DEPTH];
558-
struct hlist_node bydst_inexact_list;
559558
struct rcu_head rcu;
560559

561560
struct xfrm_dev_offload xdo;

net/xfrm/xfrm_policy.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ xfrm_policy_inexact_lookup_rcu(struct net *net,
196196
static struct xfrm_policy *
197197
xfrm_policy_insert_list(struct hlist_head *chain, struct xfrm_policy *policy,
198198
bool excl);
199-
static void xfrm_policy_insert_inexact_list(struct hlist_head *chain,
200-
struct xfrm_policy *policy);
201199

202200
static bool
203201
xfrm_policy_find_inexact_candidates(struct xfrm_pol_inexact_candidates *cand,
@@ -410,7 +408,6 @@ struct xfrm_policy *xfrm_policy_alloc(struct net *net, gfp_t gfp)
410408
if (policy) {
411409
write_pnet(&policy->xp_net, net);
412410
INIT_LIST_HEAD(&policy->walk.all);
413-
INIT_HLIST_NODE(&policy->bydst_inexact_list);
414411
INIT_HLIST_NODE(&policy->bydst);
415412
INIT_HLIST_NODE(&policy->byidx);
416413
rwlock_init(&policy->lock);
@@ -1228,9 +1225,6 @@ xfrm_policy_inexact_insert(struct xfrm_policy *policy, u8 dir, int excl)
12281225
return ERR_PTR(-EEXIST);
12291226
}
12301227

1231-
chain = &net->xfrm.policy_inexact[dir];
1232-
xfrm_policy_insert_inexact_list(chain, policy);
1233-
12341228
if (delpol)
12351229
__xfrm_policy_inexact_prune_bin(bin, false);
12361230

@@ -1346,7 +1340,6 @@ static void xfrm_hash_rebuild(struct work_struct *work)
13461340
}
13471341

13481342
hlist_del_rcu(&policy->bydst);
1349-
hlist_del_init(&policy->bydst_inexact_list);
13501343

13511344
newpos = NULL;
13521345
chain = policy_hash_bysel(net, &policy->selector,
@@ -1515,36 +1508,6 @@ static const struct rhashtable_params xfrm_pol_inexact_params = {
15151508
.automatic_shrinking = true,
15161509
};
15171510

1518-
static void xfrm_policy_insert_inexact_list(struct hlist_head *chain,
1519-
struct xfrm_policy *policy)
1520-
{
1521-
struct xfrm_policy *pol, *delpol = NULL;
1522-
struct hlist_node *newpos = NULL;
1523-
1524-
hlist_for_each_entry(pol, chain, bydst_inexact_list) {
1525-
if (pol->type == policy->type &&
1526-
pol->if_id == policy->if_id &&
1527-
!selector_cmp(&pol->selector, &policy->selector) &&
1528-
xfrm_policy_mark_match(&policy->mark, pol) &&
1529-
xfrm_sec_ctx_match(pol->security, policy->security) &&
1530-
!WARN_ON(delpol)) {
1531-
delpol = pol;
1532-
if (policy->priority > pol->priority)
1533-
continue;
1534-
} else if (policy->priority >= pol->priority) {
1535-
newpos = &pol->bydst_inexact_list;
1536-
continue;
1537-
}
1538-
if (delpol)
1539-
break;
1540-
}
1541-
1542-
if (newpos && policy->xdo.type != XFRM_DEV_OFFLOAD_PACKET)
1543-
hlist_add_behind_rcu(&policy->bydst_inexact_list, newpos);
1544-
else
1545-
hlist_add_head_rcu(&policy->bydst_inexact_list, chain);
1546-
}
1547-
15481511
static struct xfrm_policy *xfrm_policy_insert_list(struct hlist_head *chain,
15491512
struct xfrm_policy *policy,
15501513
bool excl)
@@ -2346,7 +2309,6 @@ static struct xfrm_policy *__xfrm_policy_unlink(struct xfrm_policy *pol,
23462309
/* Socket policies are not hashed. */
23472310
if (!hlist_unhashed(&pol->bydst)) {
23482311
hlist_del_rcu(&pol->bydst);
2349-
hlist_del_init(&pol->bydst_inexact_list);
23502312
hlist_del(&pol->byidx);
23512313
}
23522314

0 commit comments

Comments
 (0)