Skip to content

Commit 21586a0

Browse files
alexveskerSaeed Mahameed
authored andcommitted
net/mlx5: DR, Limit STE hash table enlarge based on bytemask
When an ste hash table has too many collision we enlarge it to a bigger hash table (rehash). Rehashing collision improvement depends on the bytemask value. The more 1 bits we have in bytemask means better spreading in the table. Without this fix tables can grow in size without providing any improvement which can lead to memory depletion and failures. This patch will limit table rehash to reduce memory and improve the performance. Fixes: 41d0707 ("net/mlx5: DR, Expose steering rule functionality") Signed-off-by: Alex Vesker <[email protected]> Reviewed-by: Erez Shitrit <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 83e7948 commit 21586a0

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_rule.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,18 @@ static void dr_rule_clean_rule_members(struct mlx5dr_rule *rule,
595595
}
596596
}
597597

598+
static u16 dr_get_bits_per_mask(u16 byte_mask)
599+
{
600+
u16 bits = 0;
601+
602+
while (byte_mask) {
603+
byte_mask = byte_mask & (byte_mask - 1);
604+
bits++;
605+
}
606+
607+
return bits;
608+
}
609+
598610
static bool dr_rule_need_enlarge_hash(struct mlx5dr_ste_htbl *htbl,
599611
struct mlx5dr_domain *dmn,
600612
struct mlx5dr_domain_rx_tx *nic_dmn)
@@ -607,6 +619,9 @@ static bool dr_rule_need_enlarge_hash(struct mlx5dr_ste_htbl *htbl,
607619
if (!ctrl->may_grow)
608620
return false;
609621

622+
if (dr_get_bits_per_mask(htbl->byte_mask) * BITS_PER_BYTE <= htbl->chunk_size)
623+
return false;
624+
610625
if (ctrl->num_of_collisions >= ctrl->increase_threshold &&
611626
(ctrl->num_of_valid_entries - ctrl->num_of_collisions) >= ctrl->increase_threshold)
612627
return true;

drivers/net/ethernet/mellanox/mlx5/core/steering/dr_ste.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,6 @@ bool mlx5dr_ste_not_used_ste(struct mlx5dr_ste *ste)
560560
return !refcount_read(&ste->refcount);
561561
}
562562

563-
static u16 get_bits_per_mask(u16 byte_mask)
564-
{
565-
u16 bits = 0;
566-
567-
while (byte_mask) {
568-
byte_mask = byte_mask & (byte_mask - 1);
569-
bits++;
570-
}
571-
572-
return bits;
573-
}
574-
575563
/* Init one ste as a pattern for ste data array */
576564
void mlx5dr_ste_set_formatted_ste(u16 gvmi,
577565
struct mlx5dr_domain_rx_tx *nic_dmn,
@@ -620,20 +608,12 @@ int mlx5dr_ste_create_next_htbl(struct mlx5dr_matcher *matcher,
620608
struct mlx5dr_ste_htbl *next_htbl;
621609

622610
if (!mlx5dr_ste_is_last_in_rule(nic_matcher, ste->ste_chain_location)) {
623-
u32 bits_in_mask;
624611
u8 next_lu_type;
625612
u16 byte_mask;
626613

627614
next_lu_type = MLX5_GET(ste_general, hw_ste, next_lu_type);
628615
byte_mask = MLX5_GET(ste_general, hw_ste, byte_mask);
629616

630-
/* Don't allocate table more than required,
631-
* the size of the table defined via the byte_mask, so no need
632-
* to allocate more than that.
633-
*/
634-
bits_in_mask = get_bits_per_mask(byte_mask) * BITS_PER_BYTE;
635-
log_table_size = min(log_table_size, bits_in_mask);
636-
637617
next_htbl = mlx5dr_ste_htbl_alloc(dmn->ste_icm_pool,
638618
log_table_size,
639619
next_lu_type,

0 commit comments

Comments
 (0)