]> git.baikalelectronics.ru Git - kernel.git/commit
net/mlx5e: Allocate per-channel stats dynamically at first usage
authorLama Kayal <lkayal@nvidia.com>
Wed, 22 Sep 2021 06:32:33 +0000 (09:32 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 22 Dec 2021 03:08:58 +0000 (19:08 -0800)
commit3489e712b3c8103a2838c3bbc9016c744386310c
tree64b923181ad56df4cfaf4c551664afa887f4bff2
parent16b77a7d66bf357b8a9325c5e1df4ef1a80d0281
net/mlx5e: Allocate per-channel stats dynamically at first usage

Make stats allocation per-channel dynamic on demand, at channel open
operation.

Previously the stats array was pre-allocated for the maximum possible
number of channels. Here we defer the per-channel stats instance allocation
upon its first usage, so that it's allocated only if really needed.

Allocating stats on demand helps maintain a more memory-efficient code,
as we're saving memory when the used number of channels is smaller than
the maximum.

The stats memory instances are still freed in mlx5e_priv_arrays_free(),
so that they are persistent to channels' closure.

Memory size allocated for struct mlx5e_channel_stats is 3648 bytes.
If maximum number of channel stands for 64, the total memory space
allocated for stats is 3648x64 = 228K bytes. In scenarios where the
number of channels in use is significantly smaller than maximum number,
the memory saved can be remarkable.

Signed-off-by: Lama Kayal <lkayal@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/en_main.c