RE: [PATCH] net/mlx5e: fix high stack usage

From: David Laight
Date: Mon Nov 05 2018 - 06:24:09 EST


From: Arnd Bergmann
> Sent: 02 November 2018 15:33
>
> A patch that looks harmless causes the stack usage of the mlx5e_grp_sw_update_stats()
> function to drastically increase with x86 gcc-4.9 and higher (tested up to 8.1):
>
> drivers/net/ethernet/mellanox/mlx5/core/en_stats.c: In function âmlx5e_grp_sw_update_statsâ:
> drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:216:1: warning: the frame size of 1276 bytes is
> larger than 500 bytes [-Wframe-larger-than=]
>
> By splitting out the loop body into a non-inlined function, the stack size goes
> back down to under 500 bytes.

I'd look at the generated code for the function.
It might be truly horrid.

I suspect that gcc allocates 'virtual registers' for all the
s->tx_... members and then writes them to 's' outside the loop.
Unfortunately there aren't enough real registers so all the
virtual ones get spilled to stack.

I've seen it do something similar (extra spills to stack) in the
ixgbe byte and packet counting.

I think it is really a gcc bug.

...
> + for (j = 0; j < priv->max_opened_tc; j++) {
> + struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j];

Try adding barrier() here.

> +
> + s->tx_packets += sq_stats->packets;

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)