From: Pavel Begunkov <[email protected]>
To: [email protected], [email protected]
Cc: Jens Axboe <[email protected]>,
"David S . Miller" <[email protected]>,
Jakub Kicinski <[email protected]>,
[email protected], [email protected],
[email protected], Wei Liu <[email protected]>,
Paul Durrant <[email protected]>,
[email protected], [email protected],
"Michael S . Tsirkin" <[email protected]>,
Jason Wang <[email protected]>,
Pavel Begunkov <[email protected]>
Subject: [RFC net-next io_uring 07/11] net/tcp: optimise tcp ubuf refcounting
Date: Wed, 10 Aug 2022 16:49:15 +0100 [thread overview]
Message-ID: <9a42187cdc9ce034fd23179c7b31d7cc6a54bd45.1660124059.git.asml.silence@gmail.com> (raw)
In-Reply-To: <[email protected]>
Add UARGFL_CALLER_PINNED letting protocols know that the caller holds a
reference to the ubuf_info and so it doesn't need additional refcounting
for purposes of keeping it alive. With that TCP can save a refcount
put/get pair per send when used with ->msg_ubuf.
Signed-off-by: Pavel Begunkov <[email protected]>
---
include/linux/skbuff.h | 7 +++++++
net/ipv4/tcp.c | 9 ++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 2b2e0020030b..45fe7f0648d0 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -522,6 +522,13 @@ enum {
#define SKBFL_ALL_ZEROCOPY (SKBFL_ZEROCOPY_FRAG | SKBFL_PURE_ZEROCOPY | \
SKBFL_DONT_ORPHAN | SKBFL_MANAGED_FRAG_REFS)
+enum {
+ /* The caller holds a reference during the submission so the ubuf won't
+ * be freed until we return.
+ */
+ UARGFL_CALLER_PINNED = BIT(0),
+};
+
/*
* The callback notifies userspace to release buffers when skb DMA is done in
* lower device, the skb last reference should be 0 when calling this.
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 3152da8f4763..4925107de57d 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1229,7 +1229,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
if (msg->msg_ubuf) {
uarg = msg->msg_ubuf;
- net_zcopy_get(uarg);
+ if (!(uarg->flags & UARGFL_CALLER_PINNED))
+ net_zcopy_get(uarg);
zc = sk->sk_route_caps & NETIF_F_SG;
} else if (sock_flag(sk, SOCK_ZEROCOPY)) {
uarg = msg_zerocopy_realloc(sk, size, skb_zcopy(skb));
@@ -1455,7 +1456,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
tcp_push(sk, flags, mss_now, tp->nonagle, size_goal);
}
out_nopush:
- net_zcopy_put(uarg);
+ if (uarg && !(uarg->flags & UARGFL_CALLER_PINNED))
+ net_zcopy_put(uarg);
return copied + copied_syn;
do_error:
@@ -1464,7 +1466,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
if (copied + copied_syn)
goto out;
out_err:
- net_zcopy_put_abort(uarg, true);
+ if (uarg && !(uarg->flags & UARGFL_CALLER_PINNED))
+ net_zcopy_put_abort(uarg, true);
err = sk_stream_error(sk, flags, err);
/* make sure we wake any epoll edge trigger waiter */
if (unlikely(tcp_rtx_and_write_queues_empty(sk) && err == -EAGAIN)) {
--
2.37.0
next prev parent reply other threads:[~2022-08-10 15:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-10 15:49 [RFC net-next io_uring 00/11] improve io_uring's ubuf_info refcounting Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 01/11] net: introduce struct ubuf_info_msgzc Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 02/11] xen/netback: use " Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 03/11] vhost/net: " Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 04/11] net: shrink struct ubuf_info Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 05/11] net: rename ubuf_info's flags Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 06/11] net: add flags for controlling ubuf_info Pavel Begunkov
2022-08-10 15:49 ` Pavel Begunkov [this message]
2022-08-10 15:49 ` [RFC net-next io_uring 08/11] net: let callers provide ->msg_ubuf refs Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 09/11] io_uring/notif: add helper for flushing refs Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 10/11] io_uring/notif: mark notifs with UARGFL_CALLER_PINNED Pavel Begunkov
2022-08-10 15:49 ` [RFC net-next io_uring 11/11] io_uring/notif: add ubuf_info ref caching Pavel Begunkov
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=9a42187cdc9ce034fd23179c7b31d7cc6a54bd45.1660124059.git.asml.silence@gmail.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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