From nobody Thu Apr 16 02:01:08 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 394BF390225 for ; Tue, 3 Mar 2026 10:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772532289; cv=none; b=Dq873OVNnJr4hu7A0DPid0Bo65L1A+WsvPEfI60x5uZ9xD8KHQGijt9bUpu6mCJYgoqIy/U+2u/y2uA+wN1+TlVn0T6qd4Bq8RDD2IR+++EHZsjIzXeObk1yuqLe8fEAzu5hn88CtBDFJMmHX88qMRhT00uq31oEvqKG/WkmLi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772532289; c=relaxed/simple; bh=j8x8rSyHICY5qcHKtJbgh2Wkn2gcq92t1omfvouCwNY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=rq3JOwxuecZg/PR2FoTuDTS8BF1JfEjYaj3nHvQKeMTWhINW+mDgg1BC7QGNPkSgRIvrC1n1XUfwNYs1jyOh3g06VLqwj8wleVh/lKMKPhyuGm6/NgcgO5wRLjFF6ORBe0eRjDtWzMR4BFzL3UoV1hlfcgfpQKq9ItJa6QhWTl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zp3LHtWE; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zp3LHtWE" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2aaf59c4f7cso25357025ad.1 for ; Tue, 03 Mar 2026 02:04:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772532287; x=1773137087; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UfAHCrUtdxDkRhQeZ2MUII7KbpuuMok/pw78xOx4c/E=; b=Zp3LHtWEy5JRZlPE3D/tWYPg0dJztNAv2cZuWiNM+sC5ZXdDR3thyjofDAwC8uogeH ltlzDBS9Rk9XX2gxJqbUlciYSjDfYsZpfyvIvX3jyQEQszcV6t6vQldfaJi9a04mRGpQ g+IqbZtoedBfHGsj6CXHuEphXP0qEQENY8FDQOKIUr6NPbTqi9SlT2utpV9kdFpiIXH7 Serl/WejCaRVQECECjn1fqAwXV/OWqc93B3j4tNpeMH6qbJx3FIz3Ek1nmuGtaj1hwyX 2/rKfUqntNQdNHYplhxzLoNQ2H4JrAGMcLjFolrawycNCy58IFT242BZU0VJLRZG5pZO NOwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772532287; x=1773137087; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=UfAHCrUtdxDkRhQeZ2MUII7KbpuuMok/pw78xOx4c/E=; b=d7uCE3L7+IMEm+tta7VqlRyI43qh919jWlQG5k+CcJvFu3FXWsR6q4P3QvUvnSKjmy 8ZNT29S4c8fDiiPxaQthv5HM8cV+DZCpLBrvbvQXqQVN6CCnY2sORjbzsydwmLtaZeld e0fRy10GuPKvQW+URUR6/miqZ4d7b7XEXACDDHHwPIhnxG+P+kIQtA0+ieg0u4oRCAki CF8/sdLOjGG00zR6mRiloe/Wzs4WIeFnAhv1QSMvVxXToPjOm8bnLVqMTnyPGhvpt3lI R+QD0gzCnBHsDBIxlak10jWYG7lGNJOmP7qhea/9XviXYK/Vns6KBkZSJKitS9VLv/jp INhA== X-Forwarded-Encrypted: i=1; AJvYcCWhBbEbrDyCpDBAsWp3JcQF6vxkGjboJFvqqWlKlKbG4yw2WXGCpJ25i6A9D6Mqzwgpnv33gqx4w0iBLlc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4bKNVaoSjgrlJQ4yAtwklqrepoN/s7yAYD4n3RIpjUtLaVeMm 27cpM0ZRBJYY5nUMQswHKPFZp2CQy92/f/UPqCYIPi4IZCtgOshpkrCd/8H2Z1UniFdz5w== X-Gm-Gg: ATEYQzyGp2COwzQ7NhdKVNuvdVlFkaxYlKcQ4/TqmeOkWNoc3cnqDxsKEkfWHG2PSEW XpMT3y3sXYUDm2VAaj/MoanW+BWqtGN5o9wQ0UrOTYF4D2vjddPu+nVriE8bkgWTRphkMIUR70B HwgA/E4LmSPECGSCA6RL9ZTpIATdQ9IdCUZrwfsTDQHj4HUfAkJ0CXe3X4uu5iiNvQQOLsXVA8e 8XZGpayrb/zna6+9hvx17/sIlKtWBL90ZuU8ye9aQVKRc84vGpHFcZ2eDei+WZpvA0Oty4K9DbA ZauPEhC3GVLs0BotkAR2BdiRStiaBsV0AteE+2rCnDa4EW+UiaiKC1ySWvSRrAM8d0HIncMbhfY tRfDm//OE3uBuCKCV56BNSXXIZs8PzH1bICGwYgJ5Tib+hPu8Hb7XmKvyZezKWMjukrM5bWY7I3 4DAqDnNqPLclMbHlIAJJQIC5FM6KGGL3xxlAaAX64g/X/dQMmFAXY6f7plcxhw+UC8mgC1cMaRP t1MzY2DeEm+ X-Received: by 2002:a17:902:c951:b0:2a0:fb1c:144c with SMTP id d9443c01a7336-2ae2e3e3e93mr154800025ad.5.1772532287501; Tue, 03 Mar 2026 02:04:47 -0800 (PST) Received: from dpc2500057.. (fsb6a9315e.tkyc502.ap.nuro.jp. [182.169.49.94]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2adfb6b5813sm166283095ad.63.2026.03.03.02.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 02:04:47 -0800 (PST) From: Keita Morisaki To: Eric Dumazet , Neal Cardwell , "David S . Miller" , David Ahern , Jakub Kicinski , Paolo Abeni Cc: Kuniyuki Iwashima , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Keita Morisaki Subject: [PATCH net-next v2] tcp: shrink per-packet memset in __tcp_transmit_skb() Date: Tue, 3 Mar 2026 19:04:39 +0900 Message-Id: <20260303100439.3172296-1-kmta1236@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use struct_group() to group the three fields in tcp_out_options that are read unconditionally by tcp_options_write() and bpf_skops_write_hdr_opt() (mss, bpf_opt_len, num_sack_blocks), then replace the full-struct memset with a targeted memset of only that group. struct tcp_out_options is 40 bytes without MPTCP and 96 bytes with CONFIG_MPTCP=3Dy (typical distro config). Every remaining field is either assigned before first use by tcp_established_options()/tcp_syn_options(), or gated behind its OPTION_* flag in tcp_options_write(). This memset runs on every transmitted TCP packet, so shrinking it from 96 (or 40) bytes to 4 bytes reduces per-packet overhead on the hot path. Assembly comparison (x86-64, GCC 13, CONFIG_MPTCP=3Dy): Before: rep stos zeroing 96 bytes (5 instructions, 12 8-byte stores) After: movl $0x0 zeroing 4 bytes (1 instruction, 1 store) Also add opts->options =3D 0 at the top of tcp_syn_options(), which already used |=3D without a prior clear. tcp_established_options() already clears opts->options at its top. Signed-off-by: Keita Morisaki Reviewed-by: Eric Dumazet Reviewed-by: Jakub Sitnicki --- net/ipv4/tcp_output.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index 326b58ff1118d..63ee037f46e50 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c @@ -429,14 +429,19 @@ static void smc_options_write(__be32 *ptr, u16 *optio= ns) } =20 struct tcp_out_options { + /* Following group is cleared in __tcp_transmit_skb() */ + struct_group(cleared, + u16 mss; /* 0 to disable */ + u8 bpf_opt_len; /* length of BPF hdr option */ + u8 num_sack_blocks; /* number of SACK blocks to include */ + ); + + /* Caution: following fields are not cleared in __tcp_transmit_skb() */ u16 options; /* bit field of OPTION_* */ - u16 mss; /* 0 to disable */ u8 ws; /* window scale, 0 to disable */ - u8 num_sack_blocks; /* number of SACK blocks to include */ u8 num_accecn_fields:7, /* number of AccECN fields needed */ use_synack_ecn_bytes:1; /* Use synack_ecn_bytes or not */ u8 hash_size; /* bytes in hash_location */ - u8 bpf_opt_len; /* length of BPF hdr option */ __u8 *hash_location; /* temporary pointer, overloaded */ __u32 tsval, tsecr; /* need to include OPTION_TS */ struct tcp_fastopen_cookie *fastopen_cookie; /* Fast open cookie */ @@ -965,6 +970,8 @@ static unsigned int tcp_syn_options(struct sock *sk, st= ruct sk_buff *skb, struct tcp_fastopen_request *fastopen =3D tp->fastopen_req; bool timestamps; =20 + opts->options =3D 0; + /* Better than switch (key.type) as it has static branches */ if (tcp_key_is_md5(key)) { timestamps =3D false; @@ -1549,7 +1556,7 @@ static int __tcp_transmit_skb(struct sock *sk, struct= sk_buff *skb, =20 inet =3D inet_sk(sk); tcb =3D TCP_SKB_CB(skb); - memset(&opts, 0, sizeof(opts)); + memset(&opts.cleared, 0, sizeof(opts.cleared)); =20 tcp_get_current_key(sk, &key); if (unlikely(tcb->tcp_flags & TCPHDR_SYN)) { base-commit: af4e9ef3d78420feb8fe58cd9a1ab80c501b3c08 --=20 2.34.1