]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tcp: move sk_forced_mem_schedule() to tcp.c
authorEric Dumazet <edumazet@google.com>
Fri, 23 Jan 2026 11:16:05 +0000 (11:16 +0000)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 27 Jan 2026 13:58:13 +0000 (14:58 +0100)
TCP fast path can (auto)inline this helper, instead
of (auto)inling it from tcp_send_fin().

No change of overall code size, but tcp_sendmsg() is faster.

$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new
add/remove: 0/0 grow/shrink: 1/1 up/down: 141/-140 (1)
Function                                     old     new   delta
tcp_stream_alloc_skb                         216     357    +141
tcp_send_fin                                 688     548    -140
Total: Before=22236729, After=22236730, chg +0.00%

BTW, we might change tcp_send_fin() to use tcp_stream_alloc_skb().

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Neal Cardwell <ncardwell@google.com>
Link: https://patch.msgid.link/20260123111605.4089200-1-edumazet@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/ipv4/tcp.c
net/ipv4/tcp_output.c

index 22b7ec192272f680709be171184fdc3b2df813fb..d95b5b8c1ffc8b63e97495f0b7ae894aefbe41b5 100644 (file)
@@ -915,6 +915,33 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
 }
 EXPORT_IPV6_MOD(tcp_splice_read);
 
+/* We allow to exceed memory limits for FIN packets to expedite
+ * connection tear down and (memory) recovery.
+ * Otherwise tcp_send_fin() could be tempted to either delay FIN
+ * or even be forced to close flow without any FIN.
+ * In general, we want to allow one skb per socket to avoid hangs
+ * with edge trigger epoll()
+ */
+void sk_forced_mem_schedule(struct sock *sk, int size)
+{
+       int delta, amt;
+
+       delta = size - sk->sk_forward_alloc;
+       if (delta <= 0)
+               return;
+
+       amt = sk_mem_pages(delta);
+       sk_forward_alloc_add(sk, amt << PAGE_SHIFT);
+
+       if (mem_cgroup_sk_enabled(sk))
+               mem_cgroup_sk_charge(sk, amt, gfp_memcg_charge() | __GFP_NOFAIL);
+
+       if (sk->sk_bypass_prot_mem)
+               return;
+
+       sk_memory_allocated_add(sk, amt);
+}
+
 struct sk_buff *tcp_stream_alloc_skb(struct sock *sk, gfp_t gfp,
                                     bool force_schedule)
 {
index 256b669e8d3b4a4d191e61e79784e412aaef8965..597e888af36d8697cd696964077b423e79fdb83e 100644 (file)
@@ -3767,33 +3767,6 @@ void tcp_xmit_retransmit_queue(struct sock *sk)
                                     inet_csk(sk)->icsk_rto, true);
 }
 
-/* We allow to exceed memory limits for FIN packets to expedite
- * connection tear down and (memory) recovery.
- * Otherwise tcp_send_fin() could be tempted to either delay FIN
- * or even be forced to close flow without any FIN.
- * In general, we want to allow one skb per socket to avoid hangs
- * with edge trigger epoll()
- */
-void sk_forced_mem_schedule(struct sock *sk, int size)
-{
-       int delta, amt;
-
-       delta = size - sk->sk_forward_alloc;
-       if (delta <= 0)
-               return;
-
-       amt = sk_mem_pages(delta);
-       sk_forward_alloc_add(sk, amt << PAGE_SHIFT);
-
-       if (mem_cgroup_sk_enabled(sk))
-               mem_cgroup_sk_charge(sk, amt, gfp_memcg_charge() | __GFP_NOFAIL);
-
-       if (sk->sk_bypass_prot_mem)
-               return;
-
-       sk_memory_allocated_add(sk, amt);
-}
-
 /* Send a FIN. The caller locks the socket for us.
  * We should try to send a FIN packet really hard, but eventually give up.
  */