net/mlx5: HWS, reduce memory consumption of a matcher struct
authorYevgeny Kliteynik <kliteyn@nvidia.com>
Thu, 2 Jan 2025 18:14:07 +0000 (20:14 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Jan 2025 00:33:40 +0000 (16:33 -0800)
Instead of having a large array of action templates allocated with
kmalloc, have smaller array and allocate it with kvmalloc.

The size of the array represents the max number of AT attach
operations for the same matcher. This number is not expected
to be very high. In any case, when the limit is reached, the
next attempt to attach new AT will result in creation of a new
matcher and moving all the rules to this matcher.

Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Erez Shitrit <erezsh@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20250102181415.1477316-9-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/bwc.h
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/matcher.c

index 3d49652..1d27638 100644 (file)
@@ -8,7 +8,13 @@
 #define MLX5HWS_BWC_MATCHER_SIZE_LOG_STEP 1
 #define MLX5HWS_BWC_MATCHER_REHASH_PERCENT_TH 70
 #define MLX5HWS_BWC_MATCHER_REHASH_BURST_TH 32
-#define MLX5HWS_BWC_MATCHER_ATTACH_AT_NUM 255
+
+/* Max number of AT attach operations for the same matcher.
+ * When the limit is reached, next attempt to attach new AT
+ * will result in creation of a new matcher and moving all
+ * the rules to this matcher.
+ */
+#define MLX5HWS_BWC_MATCHER_ATTACH_AT_NUM 8
 
 #define MLX5HWS_BWC_MAX_ACTS 16
 
index fea2a94..4419c72 100644 (file)
@@ -999,9 +999,9 @@ hws_matcher_set_templates(struct mlx5hws_matcher *matcher,
        if (!matcher->mt)
                return -ENOMEM;
 
-       matcher->at = kcalloc(num_of_at + matcher->attr.max_num_of_at_attach,
-                             sizeof(*matcher->at),
-                             GFP_KERNEL);
+       matcher->at = kvcalloc(num_of_at + matcher->attr.max_num_of_at_attach,
+                              sizeof(*matcher->at),
+                              GFP_KERNEL);
        if (!matcher->at) {
                mlx5hws_err(ctx, "Failed to allocate action template array\n");
                ret = -ENOMEM;
@@ -1027,7 +1027,7 @@ free_mt:
 static void
 hws_matcher_unset_templates(struct mlx5hws_matcher *matcher)
 {
-       kfree(matcher->at);
+       kvfree(matcher->at);
        kfree(matcher->mt);
 }