Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ddcf43d authored by Alexander Duyck's avatar Alexander Duyck Committed by David S. Miller
Browse files

ipv4: FIB Local/MAIN table collapse



This patch is meant to collapse local and main into one by converting
tb_data from an array to a pointer.  Doing this allows us to point the
local table into the main while maintaining the same variables in the
table.

As such the tb_data was converted from an array to a pointer, and a new
array called data is added in order to still provide an object for tb_data
to point to.

In order to track the origin of the fib aliases a tb_id value was added in
a hole that existed on 64b systems.  Using this we can also reverse the
merge in the event that custom FIB rules are enabled.

With this patch I am seeing an improvement of 20ns to 30ns for routing
lookups as long as custom rules are not enabled, with custom rules enabled
we fall back to split tables and the original behavior.

Signed-off-by: default avatarAlexander Duyck <alexander.h.duyck@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 169bf912
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ struct fib_rules_ops {
					     struct sk_buff *,
					     struct fib_rule_hdr *,
					     struct nlattr **);
	void			(*delete)(struct fib_rule *);
	int			(*delete)(struct fib_rule *);
	int			(*compare)(struct fib_rule *,
					   struct fib_rule_hdr *,
					   struct nlattr **);
+9 −17
Original line number Diff line number Diff line
@@ -186,7 +186,8 @@ struct fib_table {
	int			tb_default;
	int			tb_num_default;
	struct rcu_head		rcu;
	unsigned long		tb_data[0];
	unsigned long 		*tb_data;
	unsigned long		__data[0];
};

int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,
@@ -196,11 +197,10 @@ int fib_table_delete(struct fib_table *, struct fib_config *);
int fib_table_dump(struct fib_table *table, struct sk_buff *skb,
		   struct netlink_callback *cb);
int fib_table_flush(struct fib_table *table);
struct fib_table *fib_trie_unmerge(struct fib_table *main_tb);
void fib_table_flush_external(struct fib_table *table);
void fib_free_table(struct fib_table *tb);



#ifndef CONFIG_IP_MULTIPLE_TABLES

#define TABLE_LOCAL_INDEX	(RT_TABLE_LOCAL & (FIB_TABLE_HASHSZ - 1))
@@ -229,18 +229,13 @@ static inline int fib_lookup(struct net *net, const struct flowi4 *flp,
			     struct fib_result *res)
{
	struct fib_table *tb;
	int err;
	int err = -ENETUNREACH;

	rcu_read_lock();

	for (err = 0; !err; err = -ENETUNREACH) {
		tb = fib_get_table(net, RT_TABLE_LOCAL);
		if (tb && !fib_table_lookup(tb, flp, res, FIB_LOOKUP_NOREF))
			break;
	tb = fib_get_table(net, RT_TABLE_MAIN);
	if (tb && !fib_table_lookup(tb, flp, res, FIB_LOOKUP_NOREF))
			break;
	}
		err = 0;

	rcu_read_unlock();

@@ -270,10 +265,6 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
	res->tclassid = 0;

	for (err = 0; !err; err = -ENETUNREACH) {
		tb = rcu_dereference_rtnl(net->ipv4.fib_local);
		if (tb && !fib_table_lookup(tb, flp, res, FIB_LOOKUP_NOREF))
			break;

		tb = rcu_dereference_rtnl(net->ipv4.fib_main);
		if (tb && !fib_table_lookup(tb, flp, res, FIB_LOOKUP_NOREF))
			break;
@@ -309,6 +300,7 @@ static inline int fib_num_tclassid_users(struct net *net)
	return 0;
}
#endif
int fib_unmerge(struct net *net);
void fib_flush_external(struct net *net);

/* Exported by fib_semantics.c */
@@ -320,7 +312,7 @@ void fib_select_multipath(struct fib_result *res);

/* Exported by fib_trie.c */
void fib_trie_init(void);
struct fib_table *fib_trie_table(u32 id);
struct fib_table *fib_trie_table(u32 id, struct fib_table *alias);

static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
{
+6 −2
Original line number Diff line number Diff line
@@ -492,6 +492,12 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh)
			goto errout;
		}

		if (ops->delete) {
			err = ops->delete(rule);
			if (err)
				goto errout;
		}

		list_del_rcu(&rule->list);

		if (rule->action == FR_ACT_GOTO) {
@@ -517,8 +523,6 @@ static int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr* nlh)

		notify_rule_change(RTM_DELRULE, rule, ops, nlh,
				   NETLINK_CB(skb).portid);
		if (ops->delete)
			ops->delete(rule);
		fib_rule_put(rule);
		flush_route_cache(ops);
		rules_ops_put(ops);
+52 −7
Original line number Diff line number Diff line
@@ -52,14 +52,14 @@ static int __net_init fib4_rules_init(struct net *net)
{
	struct fib_table *local_table, *main_table;

	local_table = fib_trie_table(RT_TABLE_LOCAL);
	if (local_table == NULL)
		return -ENOMEM;

	main_table  = fib_trie_table(RT_TABLE_MAIN);
	main_table  = fib_trie_table(RT_TABLE_MAIN, NULL);
	if (main_table == NULL)
		goto fail;

	local_table = fib_trie_table(RT_TABLE_LOCAL, main_table);
	if (local_table == NULL)
		return -ENOMEM;

	hlist_add_head_rcu(&local_table->tb_hlist,
				&net->ipv4.fib_table_hash[TABLE_LOCAL_INDEX]);
	hlist_add_head_rcu(&main_table->tb_hlist,
@@ -74,7 +74,7 @@ static int __net_init fib4_rules_init(struct net *net)

struct fib_table *fib_new_table(struct net *net, u32 id)
{
	struct fib_table *tb;
	struct fib_table *tb, *alias = NULL;
	unsigned int h;

	if (id == 0)
@@ -83,7 +83,10 @@ struct fib_table *fib_new_table(struct net *net, u32 id)
	if (tb)
		return tb;

	tb = fib_trie_table(id);
	if (id == RT_TABLE_LOCAL)
		alias = fib_new_table(net, RT_TABLE_MAIN);

	tb = fib_trie_table(id, alias);
	if (!tb)
		return NULL;

@@ -126,6 +129,48 @@ struct fib_table *fib_get_table(struct net *net, u32 id)
}
#endif /* CONFIG_IP_MULTIPLE_TABLES */

static void fib_replace_table(struct net *net, struct fib_table *old,
			      struct fib_table *new)
{
#ifdef CONFIG_IP_MULTIPLE_TABLES
	switch (new->tb_id) {
	case RT_TABLE_LOCAL:
		rcu_assign_pointer(net->ipv4.fib_local, new);
		break;
	case RT_TABLE_MAIN:
		rcu_assign_pointer(net->ipv4.fib_main, new);
		break;
	case RT_TABLE_DEFAULT:
		rcu_assign_pointer(net->ipv4.fib_default, new);
		break;
	default:
		break;
	}

#endif
	/* replace the old table in the hlist */
	hlist_replace_rcu(&old->tb_hlist, &new->tb_hlist);
}

int fib_unmerge(struct net *net)
{
	struct fib_table *old, *new;

	old = fib_get_table(net, RT_TABLE_LOCAL);
	new = fib_trie_unmerge(old);

	if (!new)
		return -ENOMEM;

	/* replace merged table with clean table */
	if (new != old) {
		fib_replace_table(net, old, new);
		fib_free_table(old);
	}

	return 0;
}

static void fib_flush(struct net *net)
{
	int flushed = 0;
+1 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ struct fib_alias {
	u8			fa_type;
	u8			fa_state;
	u8			fa_slen;
	u32			tb_id;
	struct rcu_head		rcu;
};

Loading