Skip to content

Commit

Permalink
inetpeer: remove AVL implementation in favor of RB tree
Browse files Browse the repository at this point in the history
As discussed in Faro during Netfilter Workshop 2017, RB trees can be
used with RCU, using a seqlock.

Note that net/rxrpc/conn_service.c is already using this.

This patch converts inetpeer from AVL tree to RB tree, since it allows
to remove private AVL implementation in favor of shared RB code.

$ size net/ipv4/inetpeer.before net/ipv4/inetpeer.after
   text    data     bss     dec     hex filename
   3195      40     128    3363     d23 net/ipv4/inetpeer.before
   1562      24       0    1586     632 net/ipv4/inetpeer.after

The same technique can be used to speed up
net/netfilter/nft_set_rbtree.c (removing rwlock contention in fast path)

Signed-off-by: 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 Jul 17, 2017
1 parent 27eac47 commit b145425
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 347 deletions.
11 changes: 2 additions & 9 deletions include/net/inetpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ struct inetpeer_addr {
};

struct inet_peer {
/* group together avl_left,avl_right,v4daddr to speedup lookups */
struct inet_peer __rcu *avl_left, *avl_right;
struct rb_node rb_node;
struct inetpeer_addr daddr;
__u32 avl_height;

u32 metrics[RTAX_MAX];
u32 rate_tokens; /* rate limiting for ICMP */
unsigned long rate_last;
union {
struct list_head gc_list;
struct rcu_head gc_rcu;
};
/*
* Once inet_peer is queued for deletion (refcnt == 0), following field
* is not available: rid
Expand All @@ -55,7 +49,6 @@ struct inet_peer {
atomic_t rid; /* Frag reception counter */
};
struct rcu_head rcu;
struct inet_peer *gc_next;
};

/* following fields might be frequently dirtied */
Expand All @@ -64,7 +57,7 @@ struct inet_peer {
};

struct inet_peer_base {
struct inet_peer __rcu *root;
struct rb_root rb_root;
seqlock_t lock;
int total;
};
Expand Down
Loading

0 comments on commit b145425

Please sign in to comment.