Re: [PATCH v7 net-next 10/15] tcp: accecn: AccECN option send control

2025-05-20 Thread Paolo Abeni
On 5/14/25 3:56 PM, [email protected] wrote:
> @@ -6450,8 +6480,12 @@ static bool tcp_validate_incoming(struct sock *sk, 
> struct sk_buff *skb,
>* RFC 5961 4.2 : Send a challenge ack
>*/
>   if (th->syn) {
> - if (tcp_ecn_mode_accecn(tp))
> + if (tcp_ecn_mode_accecn(tp)) {
> + u8 opt_demand = max_t(u8, 1, tp->accecn_opt_demand);
> +
>   accecn_reflector = true;
> + tp->accecn_opt_demand = opt_demand;

There is similar code to update accecn_opt_demand above, possibly worth
an helper.

> @@ -1237,12 +1253,16 @@ static unsigned int tcp_established_options(struct 
> sock *sk, struct sk_buff *skb
>   }
>  
>   if (tcp_ecn_mode_accecn(tp) &&
> - sock_net(sk)->ipv4.sysctl_tcp_ecn_option) {
> + sock_net(sk)->ipv4.sysctl_tcp_ecn_option &&
> + (sock_net(sk)->ipv4.sysctl_tcp_ecn_option >= TCP_ECN_OPTION_FULL ||
> +  tp->accecn_opt_demand ||
> +  tcp_accecn_option_beacon_check(sk))) {
>   int saving = opts->num_sack_blocks > 0 ? 2 : 0;
>   int remaining = MAX_TCP_OPTION_SPACE - size;
>  
>   opts->ecn_bytes = tp->received_ecn_bytes;
> - size += tcp_options_fit_accecn(opts, tp->accecn_minlen,
> + size += tcp_options_fit_accecn(opts,
> +tp->accecn_minlen,
>  remaining,
>  saving);

Please avoid unneeded white-space only changes.

/P





[PATCH v7 net-next 10/15] tcp: accecn: AccECN option send control

2025-05-14 Thread chia-yu . chang
From: Ilpo Järvinen 

Instead of sending the option in every ACK, limit sending to
those ACKs where the option is necessary:
- Handshake
- "Change-triggered ACK" + the ACK following it. The
  2nd ACK is necessary to unambiguously indicate which
  of the ECN byte counters in increasing. The first
  ACK has two counters increasing due to the ecnfield
  edge.
- ACKs with CE to allow CEP delta validations to take
  advantage of the option.
- Force option to be sent every at least once per 2^22
  bytes. The check is done using the bit edges of the
  byte counters (avoids need for extra variables).
- AccECN option beacon to send a few times per RTT even if
  nothing in the ECN state requires that. The default is 3
  times per RTT, and its period can be set via
  sysctl_tcp_ecn_option_beacon.

Below are the pahole outcomes before and after this patch,
in which the group size of tcp_sock_write_tx is increased
from 89 to 97 due to the new u64 accecn_opt_tstamp member:

[BEFORE THIS PATCH]
struct tcp_sock {
[...]
u64tcp_wstamp_ns;/*  2552 8 */
struct list_head   tsorted_sent_queue;   /*  256016 */

[...]
__cacheline_group_end__tcp_sock_write_tx[0]; /*  2585 0 */
__cacheline_group_begin__tcp_sock_write_txrx[0]; /*  2585 0 */
u8 nonagle:4;/*  2585: 0  1 */
u8 rate_app_limited:1;   /*  2585: 4  1 */
/* XXX 3 bits hole, try to pack */

/* Force alignment to the next boundary: */
u8 :0;
u8 received_ce_pending:4;/*  2586: 0  1 */
u8 unused2:4;/*  2586: 4  1 */
u8 accecn_minlen:2;  /*  2587: 0  1 */
u8 est_ecnfield:2;   /*  2587: 2  1 */
u8 unused3:4;/*  2587: 4  1 */

[...]
__cacheline_group_end__tcp_sock_write_txrx[0];   /*  2692 0 */

[...]
/* size: 3264, cachelines: 51, members: 174 */
}

[AFTER THIS PATCH]
struct tcp_sock {
[...]
u64tcp_wstamp_ns;/*  2552 8 */
u64accecn_opt_tstamp;/*  2560 8 */
struct list_head   tsorted_sent_queue;   /*  256816 */

[...]
__cacheline_group_end__tcp_sock_write_tx[0]; /*  2593 0 */
__cacheline_group_begin__tcp_sock_write_txrx[0]; /*  2593 0 */
u8 nonagle:4;/*  2593: 0  1 */
u8 rate_app_limited:1;   /*  2593: 4  1 */
/* XXX 3 bits hole, try to pack */

/* Force alignment to the next boundary: */
u8 :0;
u8 received_ce_pending:4;/*  2594: 0  1 */
u8 unused2:4;/*  2594: 4  1 */
u8 accecn_minlen:2;  /*  2595: 0  1 */
u8 est_ecnfield:2;   /*  2595: 2  1 */
u8 accecn_opt_demand:2;  /*  2595: 4  1 */
u8 prev_ecnfield:2;  /*  2595: 6  1 */

[...]
__cacheline_group_end__tcp_sock_write_txrx[0];   /*  2700 0 */

[...]
/* size: 3264, cachelines: 51, members: 176 */
}

Signed-off-by: Ilpo Järvinen 
Co-developed-by: Chia-Yu Chang 
Signed-off-by: Chia-Yu Chang 
---
 .../networking/net_cachelines/tcp_sock.rst|  3 ++
 include/linux/tcp.h   |  4 ++-
 include/net/netns/ipv4.h  |  1 +
 include/net/tcp.h |  4 +++
 net/ipv4/sysctl_net_ipv4.c|  9 +
 net/ipv4/tcp.c|  5 ++-
 net/ipv4/tcp_input.c  | 36 ++-
 net/ipv4/tcp_ipv4.c   |  1 +
 net/ipv4/tcp_minisocks.c  |  2 ++
 net/ipv4/tcp_output.c | 31 ++--
 10 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/Documentation/networking/net_cachelines/tcp_sock.rst 
b/Documentation/networking/net_cachelines/tcp_sock.rst
index c74f939f32cc..af76d4f9b33a 100644
--- a/Documentation/networking/net_cachelines/tcp_sock.rst
+++ b/Documentation/networking/net_cachelines/tcp_sock.rst
@@ -110,6 +110,9 @@ u8:2  syn_ect_rcv 
read_mostly read_w
 u8:1  wait_third_ack  
read_write
 u8:2  accecn_minlen   write_mostly
read_write
 u8:2  est_ecnfield
read_write
+u8:2  accecn_opt_demand   read_mostly 
read_write
+u8:2  prev_ecnfield   
read_write
+u64   accecn_opt_tstamp   read_write
 u8:4