From: Liu Kui <kui.liu@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: azaitsev@virtuozzo.com, devel@openvz.org,
Liu Kui <kui.liu@virtuozzo.com>
Subject: [Devel] [PATCH hci-8.1 3/3] fs/fuse kio: refactor receive path in pcs_sockio_recv()
Date: Wed, 30 Sep 2026 15:34:33 +0800 [thread overview]
Message-ID: <20260930-sockio-refactor-8-1-v1-3-806348b9eb26@virtuozzo.com> (raw)
In-Reply-To: <20260930-sockio-refactor-8-1-v1-0-806348b9eb26@virtuozzo.com>
The receive path consumes data one 4k page per kernel_recvmsg() call:
do_recv_one_seg() extracts a single page from the iov_iter, kmaps it
and receives into it, so a 1M message body costs up to 256 recvmsg
calls plus a page reference and kmap/kunmap per page.
Replace do_recv_one_seg() with do_sockio_recvmsg(), the receive twin
of do_sockio_sendmsg(): hand the whole remaining iov_iter to
sock_recvmsg() and let it drain everything available in one call.
The header read goes through the same helper too, replacing
do_sock_recv(), so the whole receive path now uses one recv primitive.
https://virtuozzo.atlassian.net/browse/VSTOR-142167
Signed-off-by: Liu Kui <kui.liu@virtuozzo.com>
---
fs/fuse/kio/pcs/pcs_sock_io.c | 80 +++++++++++--------------------------------
fs/fuse/kio/pcs/pcs_sock_io.h | 1 +
2 files changed, 21 insertions(+), 60 deletions(-)
diff --git a/fs/fuse/kio/pcs/pcs_sock_io.c b/fs/fuse/kio/pcs/pcs_sock_io.c
index 828c8a98cabf..2da6d51c898b 100644
--- a/fs/fuse/kio/pcs/pcs_sock_io.c
+++ b/fs/fuse/kio/pcs/pcs_sock_io.c
@@ -139,69 +139,24 @@ static bool pcs_should_fail_sock_io(void)
}
#endif
-static int do_sock_recv(struct socket *sock, void *buf, size_t len)
+static int do_sockio_recvmsg(struct pcs_sockio *sio, struct iov_iter *it, size_t left)
{
+ struct msghdr sockmsg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
+ int ret;
- struct kvec iov = {buf, len};
- struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL };
- struct pcs_sockio __maybe_unused *sio;
- int ret = -EIO;
-
- if (pcs_should_fail_sock_io())
- goto out;
-
- ret = kernel_recvmsg(sock, &msg, &iov, 1, len, msg.msg_flags);
-out:
-
-#ifdef CONFIG_FUSE_KIO_DEBUG
- rcu_read_lock();
- sio = rcu_dereference_sk_user_data(sock->sk);
- if (sio) {
- TRACE("RET: "PEER_FMT" len:%ld ret:%d\n", PEER_ARGS(sio->netio.parent),
- len, ret);
- }
- rcu_read_unlock();
-#endif /* CONFIG_FUSE_KIO_DEBUG */
-
- return ret;
-}
-
-static int do_recv_one_seg(struct socket *sock, struct iov_iter *it, size_t left)
-{
- int ret = -EINVAL;
- size_t size = min(iov_iter_single_seg_count(it), left);
-
- if (unlikely(!size))
- return 0;
-
- if (iov_iter_is_kvec(it)) {
- struct kvec kv;
-
- iov_iter_get_kvec(it, &kv);
- if (kv.iov_len > size)
- kv.iov_len = size;
-
- ret = do_sock_recv(sock, kv.iov_base, kv.iov_len);
- if (ret > 0)
- iov_iter_advance(it, ret);
+ if (unlikely(pcs_should_fail_sock_io()))
+ return -EIO;
- } else if (iov_iter_is_bvec(it)) {
- size_t offset;
- ssize_t len;
- struct page* page;
+ sockmsg.msg_iter = *it;
+ /* The iter may cover more than what is left of the message (trash msg) */
+ iov_iter_truncate(&sockmsg.msg_iter, left);
- len = iov_iter_get_pages2(it, &page, size, 1, &offset);
- BUG_ON(len <=0);
+ ret = sock_recvmsg(sio->socket, &sockmsg, sockmsg.msg_flags);
- ret = do_sock_recv(sock, kmap(page) + offset, len);
- if (ret <= 0)
- iov_iter_revert(it, len);
- else if (ret < len)
- iov_iter_revert(it, len - ret);
+ DTRACE("sock(%px) len:%zu ret:%d\n", sio->socket, left, ret);
- kunmap(page);
- put_page(page);
- }
+ if (ret > 0)
+ iov_iter_advance(it, ret);
return ret;
}
@@ -232,8 +187,13 @@ static void pcs_sockio_recv(struct pcs_sockio *sio)
sio->read_offset = 0;
n = 0;
- if (copy)
- n = do_sock_recv(sio->socket, (char *)sio_inline_buffer(sio) + sio->hdr_ptr, copy);
+ if (copy) {
+ sio->hdr_kv.iov_base = (char *)sio_inline_buffer(sio) + sio->hdr_ptr;
+ sio->hdr_kv.iov_len = copy;
+ iov_iter_kvec(it, READ, &sio->hdr_kv, 1, copy);
+
+ n = do_sockio_recvmsg(sio, it, copy);
+ }
if (n > 0 || n == copy /* recv return 0 when copy is 0 */) {
sio->hdr_ptr += n;
@@ -279,7 +239,7 @@ static void pcs_sockio_recv(struct pcs_sockio *sio)
if (msg != PCS_TRASH_MSG)
BUG_ON(iov_iter_count(it) > msg_size - sio->read_offset);
- n = do_recv_one_seg(sio->socket, it, (size_t)(msg_size - sio->read_offset));
+ n = do_sockio_recvmsg(sio, it, (size_t)(msg_size - sio->read_offset));
if (n > 0) {
sio->read_offset += n;
} else {
diff --git a/fs/fuse/kio/pcs/pcs_sock_io.h b/fs/fuse/kio/pcs/pcs_sock_io.h
index d894aebdca7f..01c99f73dc9d 100644
--- a/fs/fuse/kio/pcs/pcs_sock_io.h
+++ b/fs/fuse/kio/pcs/pcs_sock_io.h
@@ -151,6 +151,7 @@ struct pcs_sockio
u32 current_msg_size;
int read_offset;
int write_offset;
+ struct kvec hdr_kv; /* backs read_iter for header reads */
struct iov_iter read_iter;
struct iov_iter write_iter;
struct mutex mutex;
--
Git-155)
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-09-30 7:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 7:34 [Devel] [PATCH hci-8.1 0/3] fs/fuse kio: cut per-4k-page sendmsg/recvmsg calls in the sockio path Liu Kui
2026-09-30 7:34 ` [Devel] [PATCH hci-8.1 1/3] fs/fuse kio: teach pcs_umem about hugepage-backed mappings Liu Kui
2026-09-30 7:41 ` no-reply
2026-09-30 7:34 ` [Devel] [PATCH hci-8.1 2/3] fs/fuse kio: refactor transmit path in pcs_sockio_send() Liu Kui
2026-09-30 7:42 ` no-reply
2026-09-30 16:29 ` Konstantin Khorenko
2026-09-30 7:34 ` Liu Kui [this message]
2026-09-30 7:42 ` [Devel] [PATCH hci-8.1 3/3] fs/fuse kio: refactor receive path in pcs_sockio_recv() no-reply
2026-09-30 16:09 ` [Devel] [PATCH hci-8.1 0/3] fs/fuse kio: cut per-4k-page sendmsg/recvmsg calls in the sockio path Konstantin Khorenko
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=20260930-sockio-refactor-8-1-v1-3-806348b9eb26@virtuozzo.com \
--to=kui.liu@virtuozzo.com \
--cc=azaitsev@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.