Skip to content

Commit 7dee607

Browse files
paravmellanoxSaeed Mahameed
authored andcommitted
net/mlx5: Support lockless FTE read lookups
During connection tracking offloads with high number of connections, (40K connections per second), flow table group lock contention is observed. To improve the performance by reducing lock contention, lockless FTE read lookup is performed as described below. Each flow table entry is refcounted. Flow table entry is removed when refcount drops to zero. rhash table allows rcu protected lookup. Each hash table entry insertion and removal is write lock protected. Hence, it is possible to perform lockless lookup in rhash table using following scheme. (a) Guard FTE entry lookup per group using rcu read lock. (b) Before freeing the FTE entry, wait for all readers to finish accessing the FTE. Below example of one reader and write in parallel racing, shows protection in effect with rcu lock. lookup_fte_locked() rcu_read_lock(); search_hash_table() existing_flow_group_write_lock(); tree_put_node(fte) drop_ref_cnt(fte) del_sw_fte(fte) del_hash_table_entry(); call_rcu(); existing_flow_group_write_unlock(); get_ref_cnt(fte) fails rcu_read_unlock(); rcu grace period(); [..] kmem_cache_free(fte); Signed-off-by: Parav Pandit <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 84c7af6 commit 7dee607

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,16 @@ static void del_hw_fte(struct fs_node *node)
531531
}
532532
}
533533

534+
static void del_sw_fte_rcu(struct rcu_head *head)
535+
{
536+
struct fs_fte *fte = container_of(head, struct fs_fte, rcu);
537+
struct mlx5_flow_steering *steering = get_steering(&fte->node);
538+
539+
kmem_cache_free(steering->ftes_cache, fte);
540+
}
541+
534542
static void del_sw_fte(struct fs_node *node)
535543
{
536-
struct mlx5_flow_steering *steering = get_steering(node);
537544
struct mlx5_flow_group *fg;
538545
struct fs_fte *fte;
539546
int err;
@@ -546,7 +553,8 @@ static void del_sw_fte(struct fs_node *node)
546553
rhash_fte);
547554
WARN_ON(err);
548555
ida_simple_remove(&fg->fte_allocator, fte->index - fg->start_index);
549-
kmem_cache_free(steering->ftes_cache, fte);
556+
557+
call_rcu(&fte->rcu, del_sw_fte_rcu);
550558
}
551559

552560
static void del_hw_flow_group(struct fs_node *node)
@@ -1623,37 +1631,69 @@ static u64 matched_fgs_get_version(struct list_head *match_head)
16231631
}
16241632

16251633
static struct fs_fte *
1626-
lookup_fte_locked(struct mlx5_flow_group *g,
1627-
const u32 *match_value,
1628-
bool take_write)
1634+
lookup_fte_for_write_locked(struct mlx5_flow_group *g, const u32 *match_value)
16291635
{
16301636
struct fs_fte *fte_tmp;
16311637

1632-
if (take_write)
1633-
nested_down_write_ref_node(&g->node, FS_LOCK_PARENT);
1634-
else
1635-
nested_down_read_ref_node(&g->node, FS_LOCK_PARENT);
1636-
fte_tmp = rhashtable_lookup_fast(&g->ftes_hash, match_value,
1637-
rhash_fte);
1638+
nested_down_write_ref_node(&g->node, FS_LOCK_PARENT);
1639+
1640+
fte_tmp = rhashtable_lookup_fast(&g->ftes_hash, match_value, rhash_fte);
16381641
if (!fte_tmp || !tree_get_node(&fte_tmp->node)) {
16391642
fte_tmp = NULL;
16401643
goto out;
16411644
}
1645+
1646+
if (!fte_tmp->node.active) {
1647+
tree_put_node(&fte_tmp->node, false);
1648+
fte_tmp = NULL;
1649+
goto out;
1650+
}
1651+
nested_down_write_ref_node(&fte_tmp->node, FS_LOCK_CHILD);
1652+
1653+
out:
1654+
up_write_ref_node(&g->node, false);
1655+
return fte_tmp;
1656+
}
1657+
1658+
static struct fs_fte *
1659+
lookup_fte_for_read_locked(struct mlx5_flow_group *g, const u32 *match_value)
1660+
{
1661+
struct fs_fte *fte_tmp;
1662+
1663+
if (!tree_get_node(&g->node))
1664+
return NULL;
1665+
1666+
rcu_read_lock();
1667+
fte_tmp = rhashtable_lookup(&g->ftes_hash, match_value, rhash_fte);
1668+
if (!fte_tmp || !tree_get_node(&fte_tmp->node)) {
1669+
rcu_read_unlock();
1670+
fte_tmp = NULL;
1671+
goto out;
1672+
}
1673+
rcu_read_unlock();
1674+
16421675
if (!fte_tmp->node.active) {
16431676
tree_put_node(&fte_tmp->node, false);
16441677
fte_tmp = NULL;
16451678
goto out;
16461679
}
16471680

16481681
nested_down_write_ref_node(&fte_tmp->node, FS_LOCK_CHILD);
1682+
16491683
out:
1650-
if (take_write)
1651-
up_write_ref_node(&g->node, false);
1652-
else
1653-
up_read_ref_node(&g->node);
1684+
tree_put_node(&g->node, false);
16541685
return fte_tmp;
16551686
}
16561687

1688+
static struct fs_fte *
1689+
lookup_fte_locked(struct mlx5_flow_group *g, const u32 *match_value, bool write)
1690+
{
1691+
if (write)
1692+
return lookup_fte_for_write_locked(g, match_value);
1693+
else
1694+
return lookup_fte_for_read_locked(g, match_value);
1695+
}
1696+
16571697
static struct mlx5_flow_handle *
16581698
try_add_to_existing_fg(struct mlx5_flow_table *ft,
16591699
struct list_head *match_head,

drivers/net/ethernet/mellanox/mlx5/core/fs_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct fs_fte {
202202
enum fs_fte_status status;
203203
struct mlx5_fc *counter;
204204
struct rhash_head hash;
205+
struct rcu_head rcu;
205206
int modify_mask;
206207
};
207208

0 commit comments

Comments
 (0)