OSDN Git Service

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)
commitfa691d0c9c0812b9045f3a9420862e47b3b92518
tree64b923181ad56df4cfaf4c551664afa887f4bff2
parentbe98737a4faa3a0dc1781ced5bbf5c47865e29d7
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