* [PATCH] af_unix: add cond_resched() when flushing receive queue on close
@ 2026-07-11 9:51 albin_yang
2026-07-11 12:41 ` Kuniyuki Iwashima
0 siblings, 1 reply; 2+ messages in thread
From: albin_yang @ 2026-07-11 9:51 UTC (permalink / raw)
To: kuniyu, davem, edumazet, kuba, pabeni, horms
Cc: netdev, linux-kernel, albinwyang
From: Wei Yang <albinwyang@tencent.com>
unix_release_sock() drains sk_receive_queue in a tight loop with no
rescheduling point. Each iteration may do extra work depending on
the socket type: kfree_skb() runs unix_destruct_scm()->fput() for
SCM_RIGHTS fds on data sockets, and a LISTEN socket recurses into
unix_release_sock() for each embryonic child.
A long receive queue can hog the CPU and trip the softlockup watchdog
on CONFIG_PREEMPT_NONE kernels. We have reproduced this multiple
times under stress-ng stress testing. Add cond_resched() as done in
similar teardown loops (inet_csk_listen_stop, inet_twsk_purge,
close_files).
Signed-off-by: Wei Yang <albinwyang@tencent.com>
---
net/unix/af_unix.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index f7a9d55eee8a..8b4624ce4178 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -724,6 +724,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
/* passed fds are erased in the kfree_skb hook */
kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
+ cond_resched();
}
if (path.dentry)
--
2.43.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] af_unix: add cond_resched() when flushing receive queue on close
2026-07-11 9:51 [PATCH] af_unix: add cond_resched() when flushing receive queue on close albin_yang
@ 2026-07-11 12:41 ` Kuniyuki Iwashima
0 siblings, 0 replies; 2+ messages in thread
From: Kuniyuki Iwashima @ 2026-07-11 12:41 UTC (permalink / raw)
To: albin_yang
Cc: davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel,
albinwyang
On Sat, Jul 11, 2026 at 2:52 AM <albin_yang@163.com> wrote:
>
> From: Wei Yang <albinwyang@tencent.com>
>
> unix_release_sock() drains sk_receive_queue in a tight loop with no
> rescheduling point. Each iteration may do extra work depending on
> the socket type: kfree_skb() runs unix_destruct_scm()->fput() for
> SCM_RIGHTS fds on data sockets, and a LISTEN socket recurses into
> unix_release_sock() for each embryonic child.
>
> A long receive queue can hog the CPU and trip the softlockup watchdog
> on CONFIG_PREEMPT_NONE kernels.
AFAIU, CONFIG_PREEMPT_NONE is no longer supported on
modern arch since 7dadeaa6e851, and it also mentions how bad
cond_resched() is.
I think you need to keep this patch downstream.
> We have reproduced this multiple
> times under stress-ng stress testing. Add cond_resched() as done in
> similar teardown loops (inet_csk_listen_stop, inet_twsk_purge,
> close_files).
>
> Signed-off-by: Wei Yang <albinwyang@tencent.com>
> ---
> net/unix/af_unix.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
> index f7a9d55eee8a..8b4624ce4178 100644
> --- a/net/unix/af_unix.c
> +++ b/net/unix/af_unix.c
> @@ -724,6 +724,7 @@ static void unix_release_sock(struct sock *sk, int embrion)
>
> /* passed fds are erased in the kfree_skb hook */
> kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
> + cond_resched();
> }
>
> if (path.dentry)
> --
> 2.43.5
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-11 12:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-11 9:51 [PATCH] af_unix: add cond_resched() when flushing receive queue on close albin_yang
2026-07-11 12:41 ` Kuniyuki Iwashima
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox