From: Srikar Dronamraju <srikar@linux.ibm.com>
To: LKML <linux-kernel@vger.kernel.org>,
netdev@vger.kernel.org, David S Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Dust Li <dust.li@linux.alibaba.com>,
D Wythe <alibuda@linux.alibaba.com>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Jon Maloy <jmaloy@redhat.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
linux-sctp@vger.kernel.org,
Mahanta Jambigi <mjambigi@linux.ibm.com>,
Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
Paolo Abeni <pabeni@redhat.com>,
Sidraya Jayagond <sidraya@linux.ibm.com>,
Simon Horman <horms@kernel.org>,
Tony Lu <tonylu@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
Wenjia Zhang <wenjia@linux.ibm.com>,
Willem de Bruijn <willemb@google.com>,
Xin Long <lucien.xin@gmail.com>,
Shrikanth Hegde <sshegde@linux.ibm.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
Srikar Dronamraju <srikar@linux.ibm.com>
Subject: [PATCH 1/2] net/socket: Record preference for synchronous wakeups
Date: Tue, 14 Jul 2026 07:09:42 +0530 [thread overview]
Message-ID: <20260714013940.4068189-5-srikar@linux.ibm.com> (raw)
In-Reply-To: <20260714013940.4068189-4-srikar@linux.ibm.com>
Scheduler differentiates between affine and non-affine wakeups by the
way of sync flags. Scheduler prefers to pull the tasks towards the waker
if the sync flag is set.
In some cases, socket APIs are blindly requesting sync wakeups. This may
cause load-balance issues and non-optimal performance.
Record whether the most recent blocking socket operation could benefit
from synchronous wakeups. Subsequent readiness notifications use this
hint to determine whether WF_SYNC should be propagated.
The flag is advisory and affects only wakeup placement decisions.
Signed-off-by: Srikar Dronamraju <srikar@linux.ibm.com>
---
include/net/sock.h | 1 +
net/socket.c | 56 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 51185222aac2..acc6b1976dc4 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1022,6 +1022,7 @@ enum sock_flags {
SOCK_RCVMARK, /* Receive SO_MARK ancillary data with packet */
SOCK_RCVPRIORITY, /* Receive SO_PRIORITY ancillary data with packet */
SOCK_TIMESTAMPING_ANY, /* Copy of sk_tsflags & TSFLAGS_ANY */
+ SOCK_SYNC_WAKEUP, /* Prefer synchronous socket wakeups */
};
#define SK_FLAGS_TIMESTAMP ((1UL << SOCK_TIMESTAMP) | (1UL << SOCK_TIMESTAMPING_RX_SOFTWARE))
diff --git a/net/socket.c b/net/socket.c
index 63c69a0fa74e..0bcb57ae490e 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1198,15 +1198,27 @@ static void sock_splice_eof(struct file *file)
ops->splice_eof(sock);
}
+static inline void sock_update_sync_wakeup(struct sock *sk, bool nonblock)
+{
+ if (unlikely(!sk))
+ return;
+
+ if (nonblock) {
+ if (sock_flag(sk, SOCK_SYNC_WAKEUP))
+ sock_reset_flag(sk, SOCK_SYNC_WAKEUP);
+ } else {
+ if (!sock_flag(sk, SOCK_SYNC_WAKEUP))
+ sock_set_flag(sk, SOCK_SYNC_WAKEUP);
+ }
+}
+
static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
struct file *file = iocb->ki_filp;
struct socket *sock = file->private_data;
struct msghdr msg = {.msg_iter = *to};
ssize_t res;
-
- if (file->f_flags & O_NONBLOCK || (iocb->ki_flags & IOCB_NOWAIT))
- msg.msg_flags = MSG_DONTWAIT;
+ bool nonblock;
if (iocb->ki_pos != 0)
return -ESPIPE;
@@ -1214,6 +1226,11 @@ static ssize_t sock_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (!iov_iter_count(to)) /* Match SYS5 behaviour */
return 0;
+ nonblock = (file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT);
+ if (nonblock)
+ msg.msg_flags = MSG_DONTWAIT;
+
+ sock_update_sync_wakeup(sock->sk, nonblock);
res = sock_recvmsg(sock, &msg, msg.msg_flags);
*to = msg.msg_iter;
return res;
@@ -1225,13 +1242,17 @@ static ssize_t sock_write_iter(struct kiocb *iocb, struct iov_iter *from)
struct socket *sock = file->private_data;
struct msghdr msg = {.msg_iter = *from};
ssize_t res;
+ bool nonblock;
if (iocb->ki_pos != 0)
return -ESPIPE;
- if (file->f_flags & O_NONBLOCK || (iocb->ki_flags & IOCB_NOWAIT))
+ nonblock = (file->f_flags & O_NONBLOCK) || (iocb->ki_flags & IOCB_NOWAIT);
+ if (nonblock)
msg.msg_flags = MSG_DONTWAIT;
+ sock_update_sync_wakeup(sock->sk, nonblock);
+
if (sock->type == SOCK_SEQPACKET)
msg.msg_flags |= MSG_EOR;
@@ -2221,6 +2242,7 @@ int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags,
struct sockaddr_storage address;
int err;
struct msghdr msg;
+ bool nonblock;
err = import_ubuf(ITER_SOURCE, buff, len, &msg.msg_iter);
if (unlikely(err))
@@ -2246,8 +2268,11 @@ int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags,
msg.msg_namelen = addr_len;
}
flags &= ~MSG_INTERNAL_SENDMSG_FLAGS;
- if (sock->file->f_flags & O_NONBLOCK)
+ nonblock = (sock->file->f_flags & O_NONBLOCK);
+ if (nonblock)
flags |= MSG_DONTWAIT;
+
+ sock_update_sync_wakeup(sock->sk, nonblock);
msg.msg_flags = flags;
return __sock_sendmsg(sock, &msg);
}
@@ -2284,6 +2309,7 @@ int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
};
struct socket *sock;
int err, err2;
+ bool nonblock;
err = import_ubuf(ITER_DEST, ubuf, size, &msg.msg_iter);
if (unlikely(err))
@@ -2297,8 +2323,11 @@ int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
if (unlikely(!sock))
return -ENOTSOCK;
- if (sock->file->f_flags & O_NONBLOCK)
+ nonblock = (sock->file->f_flags & O_NONBLOCK);
+ if (nonblock)
flags |= MSG_DONTWAIT;
+
+ sock_update_sync_wakeup(sock->sk, nonblock);
err = sock_recvmsg(sock, &msg, flags);
if (err >= 0 && addr != NULL) {
@@ -2634,6 +2663,7 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys,
unsigned char *ctl_buf = ctl;
int ctl_len;
ssize_t err;
+ bool nonblock;
err = -ENOBUFS;
@@ -2666,8 +2696,12 @@ static int ____sys_sendmsg(struct socket *sock, struct msghdr *msg_sys,
flags &= ~MSG_INTERNAL_SENDMSG_FLAGS;
msg_sys->msg_flags = flags;
- if (sock->file->f_flags & O_NONBLOCK)
+ nonblock = (sock->file->f_flags & O_NONBLOCK);
+ if (nonblock)
msg_sys->msg_flags |= MSG_DONTWAIT;
+
+ sock_update_sync_wakeup(sock->sk, nonblock);
+
/*
* If this is sendmmsg() and current destination address is same as
* previously succeeded address, omit asking LSM's decision.
@@ -2887,6 +2921,7 @@ static int ____sys_recvmsg(struct socket *sock, struct msghdr *msg_sys,
unsigned long cmsg_ptr;
int len;
ssize_t err;
+ bool nonblock;
msg_sys->msg_name = &addr;
cmsg_ptr = (unsigned long)msg_sys->msg_control;
@@ -2895,9 +2930,12 @@ static int ____sys_recvmsg(struct socket *sock, struct msghdr *msg_sys,
/* We assume all kernel code knows the size of sockaddr_storage */
msg_sys->msg_namelen = 0;
- if (sock->file->f_flags & O_NONBLOCK)
+ nonblock = (sock->file->f_flags & O_NONBLOCK);
+ if (nonblock)
flags |= MSG_DONTWAIT;
+ sock_update_sync_wakeup(sock->sk, nonblock);
+
if (unlikely(nosec))
err = sock_recvmsg_nosec(sock, msg_sys, flags);
else
@@ -3056,6 +3094,8 @@ static int do_recvmmsg(int fd, struct mmsghdr __user *mmsg,
if (flags & MSG_WAITFORONE)
flags |= MSG_DONTWAIT;
+ sock_update_sync_wakeup(sock->sk, flags & MSG_WAITFORONE);
+
if (timeout) {
ktime_get_ts64(&timeout64);
*timeout = timespec64_sub(end_time, timeout64);
--
2.52.0
next prev parent reply other threads:[~2026-07-14 1:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 1:39 [PATCH 0/2] net: Use synchronous wakeups selectively Srikar Dronamraju
2026-07-14 1:39 ` Srikar Dronamraju [this message]
2026-07-14 1:39 ` [PATCH 2/2] net/sock: Propagate WF_SYNC only when requested Srikar Dronamraju
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260714013940.4068189-5-srikar@linux.ibm.com \
--to=srikar@linux.ibm.com \
--cc=alibuda@linux.alibaba.com \
--cc=bsegall@google.com \
--cc=davem@davemloft.net \
--cc=dietmar.eggemann@arm.com \
--cc=dust.li@linux.alibaba.com \
--cc=edumazet@google.com \
--cc=guwen@linux.alibaba.com \
--cc=horms@kernel.org \
--cc=jmaloy@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sctp@vger.kernel.org \
--cc=lucien.xin@gmail.com \
--cc=marcelo.leitner@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=mjambigi@linux.ibm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=sidraya@linux.ibm.com \
--cc=sshegde@linux.ibm.com \
--cc=tonylu@linux.alibaba.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=wenjia@linux.ibm.com \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox