Skip to content

Commit

Permalink
inetpeer: speed up inetpeer_invalidate_tree()
Browse files Browse the repository at this point in the history
As measured in my prior patch ("sch_netem: faster rb tree removal"),
rbtree_postorder_for_each_entry_safe() is nice looking but much slower
than using rb_next() directly, except when tree is small enough
to fit in CPU caches (then the cost is the same)

From: Eric Dumazet <edumazet@google.com>

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Sep 28, 2017
1 parent a2e4a21 commit 8f1975e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions net/ipv4/inetpeer.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,17 @@ EXPORT_SYMBOL(inet_peer_xrlim_allow);

void inetpeer_invalidate_tree(struct inet_peer_base *base)
{
struct inet_peer *p, *n;
struct rb_node *p = rb_first(&base->rb_root);

rbtree_postorder_for_each_entry_safe(p, n, &base->rb_root, rb_node) {
inet_putpeer(p);
while (p) {
struct inet_peer *peer = rb_entry(p, struct inet_peer, rb_node);

p = rb_next(p);
rb_erase(&peer->rb_node, &base->rb_root);
inet_putpeer(peer);
cond_resched();
}

base->rb_root = RB_ROOT;
base->total = 0;
}
EXPORT_SYMBOL(inetpeer_invalidate_tree);

0 comments on commit 8f1975e

Please sign in to comment.