Skip to content

Commit a369d4a

Browse files
Maor GottliebSaeed Mahameed
authored andcommitted
net/mlx5: Add FGs and FTEs memory pool
Add memory pool allocation for flow groups and flow table entry. It is useful because these objects are not small and could be allocated/deallocated many times. Signed-off-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent f5c2ff1 commit a369d4a

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

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

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ static void tree_put_node(struct fs_node *node)
269269
if (node->del_sw_func)
270270
node->del_sw_func(node);
271271
up_write_ref_node(parent_node);
272+
} else {
273+
kfree(node);
272274
}
273-
kfree(node);
274275
node = NULL;
275276
}
276277
if (!node && parent_node)
@@ -389,6 +390,15 @@ static struct mlx5_flow_root_namespace *find_root(struct fs_node *node)
389390
return container_of(ns, struct mlx5_flow_root_namespace, ns);
390391
}
391392

393+
static inline struct mlx5_flow_steering *get_steering(struct fs_node *node)
394+
{
395+
struct mlx5_flow_root_namespace *root = find_root(node);
396+
397+
if (root)
398+
return root->dev->priv.steering;
399+
return NULL;
400+
}
401+
392402
static inline struct mlx5_core_dev *get_dev(struct fs_node *node)
393403
{
394404
struct mlx5_flow_root_namespace *root = find_root(node);
@@ -424,6 +434,7 @@ static void del_sw_flow_table(struct fs_node *node)
424434
rhltable_destroy(&ft->fgs_hash);
425435
fs_get_obj(prio, ft->node.parent);
426436
prio->num_ft--;
437+
kfree(ft);
427438
}
428439

429440
static void del_sw_hw_rule(struct fs_node *node)
@@ -469,6 +480,7 @@ static void del_sw_hw_rule(struct fs_node *node)
469480
"%s can't del rule fg id=%d fte_index=%d\n",
470481
__func__, fg->id, fte->index);
471482
}
483+
kfree(rule);
472484
}
473485

474486
static void del_hw_fte(struct fs_node *node)
@@ -497,6 +509,7 @@ static void del_hw_fte(struct fs_node *node)
497509

498510
static void del_sw_fte(struct fs_node *node)
499511
{
512+
struct mlx5_flow_steering *steering = get_steering(node);
500513
struct mlx5_flow_group *fg;
501514
struct fs_fte *fte;
502515
int err;
@@ -509,6 +522,7 @@ static void del_sw_fte(struct fs_node *node)
509522
rhash_fte);
510523
WARN_ON(err);
511524
ida_simple_remove(&fg->fte_allocator, fte->index - fg->start_index);
525+
kmem_cache_free(steering->ftes_cache, fte);
512526
}
513527

514528
static void del_hw_flow_group(struct fs_node *node)
@@ -529,6 +543,7 @@ static void del_hw_flow_group(struct fs_node *node)
529543

530544
static void del_sw_flow_group(struct fs_node *node)
531545
{
546+
struct mlx5_flow_steering *steering = get_steering(node);
532547
struct mlx5_flow_group *fg;
533548
struct mlx5_flow_table *ft;
534549
int err;
@@ -544,6 +559,7 @@ static void del_sw_flow_group(struct fs_node *node)
544559
&fg->hash,
545560
rhash_fg);
546561
WARN_ON(err);
562+
kmem_cache_free(steering->fgs_cache, fg);
547563
}
548564

549565
static int insert_fte(struct mlx5_flow_group *fg, struct fs_fte *fte)
@@ -571,12 +587,14 @@ static int insert_fte(struct mlx5_flow_group *fg, struct fs_fte *fte)
571587
return ret;
572588
}
573589

574-
static struct fs_fte *alloc_fte(u32 *match_value,
590+
static struct fs_fte *alloc_fte(struct mlx5_flow_table *ft,
591+
u32 *match_value,
575592
struct mlx5_flow_act *flow_act)
576593
{
594+
struct mlx5_flow_steering *steering = get_steering(&ft->node);
577595
struct fs_fte *fte;
578596

579-
fte = kzalloc(sizeof(*fte), GFP_KERNEL);
597+
fte = kmem_cache_zalloc(steering->ftes_cache, GFP_KERNEL);
580598
if (!fte)
581599
return ERR_PTR(-ENOMEM);
582600

@@ -592,27 +610,29 @@ static struct fs_fte *alloc_fte(u32 *match_value,
592610
return fte;
593611
}
594612

595-
static void dealloc_flow_group(struct mlx5_flow_group *fg)
613+
static void dealloc_flow_group(struct mlx5_flow_steering *steering,
614+
struct mlx5_flow_group *fg)
596615
{
597616
rhashtable_destroy(&fg->ftes_hash);
598-
kfree(fg);
617+
kmem_cache_free(steering->fgs_cache, fg);
599618
}
600619

601-
static struct mlx5_flow_group *alloc_flow_group(u8 match_criteria_enable,
620+
static struct mlx5_flow_group *alloc_flow_group(struct mlx5_flow_steering *steering,
621+
u8 match_criteria_enable,
602622
void *match_criteria,
603623
int start_index,
604624
int end_index)
605625
{
606626
struct mlx5_flow_group *fg;
607627
int ret;
608628

609-
fg = kzalloc(sizeof(*fg), GFP_KERNEL);
629+
fg = kmem_cache_zalloc(steering->fgs_cache, GFP_KERNEL);
610630
if (!fg)
611631
return ERR_PTR(-ENOMEM);
612632

613633
ret = rhashtable_init(&fg->ftes_hash, &rhash_fte);
614634
if (ret) {
615-
kfree(fg);
635+
kmem_cache_free(steering->fgs_cache, fg);
616636
return ERR_PTR(ret);
617637
}
618638
ida_init(&fg->fte_allocator);
@@ -633,10 +653,11 @@ static struct mlx5_flow_group *alloc_insert_flow_group(struct mlx5_flow_table *f
633653
int end_index,
634654
struct list_head *prev)
635655
{
656+
struct mlx5_flow_steering *steering = get_steering(&ft->node);
636657
struct mlx5_flow_group *fg;
637658
int ret;
638659

639-
fg = alloc_flow_group(match_criteria_enable, match_criteria,
660+
fg = alloc_flow_group(steering, match_criteria_enable, match_criteria,
640661
start_index, end_index);
641662
if (IS_ERR(fg))
642663
return fg;
@@ -646,7 +667,7 @@ static struct mlx5_flow_group *alloc_insert_flow_group(struct mlx5_flow_table *f
646667
&fg->hash,
647668
rhash_fg);
648669
if (ret) {
649-
dealloc_flow_group(fg);
670+
dealloc_flow_group(steering, fg);
650671
return ERR_PTR(ret);
651672
}
652673

@@ -1569,6 +1590,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15691590
int dest_num,
15701591
int ft_version)
15711592
{
1593+
struct mlx5_flow_steering *steering = get_steering(&ft->node);
15721594
struct mlx5_flow_group *g;
15731595
struct mlx5_flow_handle *rule;
15741596
struct match_list *iter;
@@ -1577,7 +1599,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
15771599
u64 version;
15781600
int err;
15791601

1580-
fte = alloc_fte(spec->match_value, flow_act);
1602+
fte = alloc_fte(ft, spec->match_value, flow_act);
15811603
if (IS_ERR(fte))
15821604
return ERR_PTR(-ENOMEM);
15831605

@@ -1611,7 +1633,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16111633
flow_act, dest, dest_num, fte_tmp);
16121634
up_write_ref_node(&fte_tmp->node);
16131635
tree_put_node(&fte_tmp->node);
1614-
kfree(fte);
1636+
kmem_cache_free(steering->ftes_cache, fte);
16151637
return rule;
16161638
}
16171639

@@ -1653,7 +1675,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16531675
continue;
16541676
list_for_each_entry(iter, match_head, list)
16551677
up_write_ref_node(&iter->g->node);
1656-
kfree(fte);
1678+
kmem_cache_free(steering->ftes_cache, fte);
16571679
return ERR_PTR(err);
16581680
}
16591681

@@ -1670,7 +1692,7 @@ try_add_to_existing_fg(struct mlx5_flow_table *ft,
16701692
out:
16711693
list_for_each_entry(iter, match_head, list)
16721694
up_write_ref_node(&iter->g->node);
1673-
kfree(fte);
1695+
kmem_cache_free(steering->ftes_cache, fte);
16741696
return rule;
16751697
}
16761698

@@ -1682,6 +1704,7 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
16821704
int dest_num)
16831705

16841706
{
1707+
struct mlx5_flow_steering *steering = get_steering(&ft->node);
16851708
struct mlx5_flow_group *g;
16861709
struct mlx5_flow_handle *rule;
16871710
struct match_list_head match_head;
@@ -1740,15 +1763,15 @@ _mlx5_add_flow_rules(struct mlx5_flow_table *ft,
17401763
if (err)
17411764
goto err_release_fg;
17421765

1743-
fte = alloc_fte(spec->match_value, flow_act);
1766+
fte = alloc_fte(ft, spec->match_value, flow_act);
17441767
if (IS_ERR(fte)) {
17451768
err = PTR_ERR(fte);
17461769
goto err_release_fg;
17471770
}
17481771

17491772
err = insert_fte(g, fte);
17501773
if (err) {
1751-
kfree(fte);
1774+
kmem_cache_free(steering->ftes_cache, fte);
17521775
goto err_release_fg;
17531776
}
17541777

@@ -2281,6 +2304,8 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev)
22812304
cleanup_root_ns(steering->sniffer_rx_root_ns);
22822305
cleanup_root_ns(steering->sniffer_tx_root_ns);
22832306
mlx5_cleanup_fc_stats(dev);
2307+
kmem_cache_destroy(steering->ftes_cache);
2308+
kmem_cache_destroy(steering->fgs_cache);
22842309
kfree(steering);
22852310
}
22862311

@@ -2386,6 +2411,16 @@ int mlx5_init_fs(struct mlx5_core_dev *dev)
23862411
steering->dev = dev;
23872412
dev->priv.steering = steering;
23882413

2414+
steering->fgs_cache = kmem_cache_create("mlx5_fs_fgs",
2415+
sizeof(struct mlx5_flow_group), 0,
2416+
0, NULL);
2417+
steering->ftes_cache = kmem_cache_create("mlx5_fs_ftes", sizeof(struct fs_fte), 0,
2418+
0, NULL);
2419+
if (!steering->ftes_cache || !steering->fgs_cache) {
2420+
err = -ENOMEM;
2421+
goto err;
2422+
}
2423+
23892424
if ((((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
23902425
(MLX5_CAP_GEN(dev, nic_flow_table))) ||
23912426
((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) &&

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ enum fs_fte_status {
6565

6666
struct mlx5_flow_steering {
6767
struct mlx5_core_dev *dev;
68+
struct kmem_cache *fgs_cache;
69+
struct kmem_cache *ftes_cache;
6870
struct mlx5_flow_root_namespace *root_ns;
6971
struct mlx5_flow_root_namespace *fdb_root_ns;
7072
struct mlx5_flow_root_namespace *esw_egress_root_ns;

0 commit comments

Comments
 (0)