mptcp: refactor xmit path
Subsystems (2)
Paolo Abeni
cover mptcp: refactor xmit path
This series refactor the mptcp xmit path trying to make sendmsg behavior more consistent, memory efficent and improve its performances.
This is an early draft, only lightly tested, shared early to avoid codying conflict in this area.
The code is also available here:
https://github.com/pabeni/mptcp/tree/mptcp-proposal-devel
Paolo Abeni (4):
mptcp: use sk_page_frag() in sendmsg
mptcp: sendmsg() do spool all the provided data
mptcp: move tpext data_len initialization at option creation time
mptcp: allow collapsing consecutive sendpages on the same substream
include/net/mptcp.h | 1 + net/mptcp/options.c | 2 + net/mptcp/protocol.c | 160 ++++++++++++++++++++++++++----------------- 3 files changed, 100 insertions(+), 63 deletions(-)
Signature · 1 line
2.20.1
Paolo Abeni
RFC PATCH 1/4 mptcp: use sk_page_frag() in sendmsg
This clean-up a bit the send path, and allows better performances.
---
iv1 -> iv2
- ret != 0 -> !ret
- goto put_out -> goto release_out; - when we error out under lock
--- net/mptcp/protocol.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-)
net/mptcp/protocol.c +19 -22
@@ -52,7 +52,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct mptcp_sock *msk =mptcp_sk (sk);int mss_now, size_goal, poffset, ret;struct mptcp_ext *mpext =NULL ; -struct page *page =NULL ; +struct page_frag *pfrag;struct sk_buff *skb;struct sock *ssk;size_t psize;
@@ -80,33 +80,32 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) goto put_out; } -/* Initial experiment: new page per send. Real code will -* maintain list of active pages and DSS mappings, append to the -* end and honor zerocopy -*/ - page =alloc_page (GFP_KERNEL ); -if (!page) { - ret = -ENOMEM ; - goto put_out; +lock_sock (sk); +lock_sock (ssk); + +/* use the subflow page cache so that memory accounting is coherent */ + pfrag =sk_page_frag (ssk); +if (!sk_page_frag_refill (ssk, pfrag)) { +long timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); + + ret =sk_stream_wait_memory (sk, &timeo); +if (ret) + goto release_out; }/* Copy to page */ - poffset =0 ; + poffset = pfrag->offset;pr_debug ("left=%zu" ,msg_data_left (msg)); - psize =copy_page_from_iter (page, poffset, + psize =copy_page_from_iter (pfrag->page, poffset,min_t (size_t,msg_data_left (msg), -PAGE_SIZE ), + pfrag->size - poffset), &msg->msg_iter);pr_debug ("left=%zu" ,msg_data_left (msg)); -if (!psize) { ret = -EINVAL ; - goto put_out; + goto release_out; } -lock_sock (sk); -lock_sock (ssk); -/* Mark the end of the previous write so the beginning of the * next write (with its own mptcp skb extension data) is not * collapsed.
@@ -116,8 +115,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)TCP_SKB_CB (skb)->eor =1 ; mss_now =tcp_send_mss (ssk, &size_goal, msg->msg_flags); - - ret =do_tcp_sendpages (ssk, page, poffset,min_t (int, size_goal, psize), + psize =min_t (int, size_goal, psize); + ret =do_tcp_sendpages (ssk, pfrag->page, poffset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 ) goto release_out;
@@ -143,6 +142,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) mpext->checksum, mpext->dsn64); }/* TODO: else fallback */ + pfrag->offset += ret; msk->write_seq += ret;subflow_ctx (ssk)->rel_write_seq += ret;
@@ -153,9 +153,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)release_sock (sk); put_out: -if (page) -put_page (page); -sock_put (ssk);return ret; }
Signature · 1 line
2.20.1
Mat Martineau
Re: [MPTCP] [RFC PATCH 1/4] mptcp: use sk_page_frag() in sendmsg
Quoted 1 line · Paolo Abeni
This clean-up a bit the send path, and allows better performances.
Paolo -
Thanks for going over the sendmsg code in detail and working to enhance it. Some parts of the design were intentionally inefficient, since they were intermediate steps toward something more complex. Other parts I may have simply chosen the wrong tool for the job - so I appreciate the improvements to the code.
I'll comment on the design choices in context below:
Quoted 24 lines
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
iv1 -> iv2
- ret != 0 -> !ret
- gotoput_out-> gotorelease_out; - when we error out under lock
---net/mptcp/protocol.c| 41 +++++++++++++++++++----------------------1 file changed, 19 insertions(+), 22 deletions(-)net/mptcp/protocol.c +1
-1@@ -52,7 +52,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)struct mptcp_sock *msk =mptcp_sk (sk);int mss_now, size_goal, poffset, ret;struct mptcp_ext *mpext =NULL ; -struct page *page =NULL ; +struct page_frag *pfrag;struct sk_buff *skb;struct sock *ssk;size_t psize;
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 8 lines
net/mptcp/protocol.c +0
-5@@ -80,33 +80,32 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) goto put_out; } -/* Initial experiment: new page per send. Real code will -* maintain list of active pages and DSS mappings, append to the -* end and honor zerocopy -*/ - page =alloc_page (GFP_KERNEL );
Allocating a new page per send is very inefficient for small sends, but was a placeholder for managing an MPTCP-level send buffer.
For each connection, we have one MPTCP-level socket, and some number of subflow sockets that it controls. Sent data needs to be stored by the MPTCP-level socket until it sees a relevant MPTCP DATA_ACK from any one of the subflows and can purge the ack'd data.
To meet that requirement, the idea was to have the MPTCP-level socket buffer the send data in a set of pages. Each sendmsg() call would append to the current page while space is available, so each page would fill with contiguous data (in the MPTCP sequence space). If data was sent with MSG_ZEROCOPY the userspace-provided pages would be used instead. The buffered data could then be sent (or resent) on multiple subflows by using do_tcp_sendpages() to create independent skbs referencing the one MPTCP-level copy of the data.
For example:
* Userspace sends 1024 bytes of data
* MPTCP-level socket copies 1024 bytes to a page
* Four separate skbs are built, referencing the same page and offset for
the 1024 bytes
* Each of the four skbs is near-simultaneously queued on a separate
subflow
* One subflow is faster than the others, and gets the data sent and
DATA_ACK'd quickly
* MPTCP-level socket releases the buffer page (but the data might still
be referenced by a queued skb on a slow subflow)
As a first step with a single subflow, I kept it simple by allocating one page per send and not keeping track of that page in the MPTCP-level socket.
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 8 lines
net/mptcp/protocol.c +5
-3-if (!page) { - ret = -ENOMEM ; - goto put_out; +lock_sock (sk); +lock_sock (ssk); + +/* use the subflow page cache so that memory accounting is coherent */ + pfrag =sk_page_frag (ssk);
Given the plan to keep the paged data buffered by the MPTCP-level socket, is sk_page_frag() the best way to get a page that might be used for skbs in multiple subflows?
Can memory accounting work properly if the page frag comes from sk (the MPTCP-level socket) instead of ssk?
Regards,
Mat
Quoted 58 lines
net/mptcp/protocol.c +13
-10+if (!sk_page_frag_refill (ssk, pfrag)) { +long timeo =sock_sndtimeo (sk, msg->msg_flags &MSG_DONTWAIT ); + + ret =sk_stream_wait_memory (sk, &timeo); +if (ret) + goto release_out; }/* Copy to page */ - poffset =0 ; + poffset = pfrag->offset;pr_debug ("left=%zu" ,msg_data_left (msg)); - psize =copy_page_from_iter (page, poffset, + psize =copy_page_from_iter (pfrag->page, poffset,min_t (size_t,msg_data_left (msg), -PAGE_SIZE ), + pfrag->size - poffset), &msg->msg_iter);pr_debug ("left=%zu" ,msg_data_left (msg)); -if (!psize) { ret = -EINVAL ; - goto put_out; + goto release_out; } -lock_sock (sk); -lock_sock (ssk); -/* Mark the end of the previous write so the beginning of the * next write (with its own mptcp skb extension data) is not * collapsed. @@ -116,8 +115,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)TCP_SKB_CB (skb)->eor =1 ; mss_now =tcp_send_mss (ssk, &size_goal, msg->msg_flags); - - ret =do_tcp_sendpages (ssk, page, poffset,min_t (int, size_goal, psize), + psize =min_t (int, size_goal, psize); + ret =do_tcp_sendpages (ssk, pfrag->page, poffset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 ) goto release_out;@@ -143,6 +142,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) mpext->checksum, mpext->dsn64); }/* TODO: else fallback */ + pfrag->offset += ret; msk->write_seq += ret;subflow_ctx (ssk)->rel_write_seq += ret;@@ -153,9 +153,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)release_sock (sk);
put_out:net/mptcp/protocol.c +0
-3-if (page) -put_page (page); -
Quoted 11 lines
sock_put(ssk); return ret; }Signature · 6 lines
2.20.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
--
Mat Martineau
Intel
Paolo Abeni
Re: [MPTCP] [RFC PATCH 1/4] mptcp: use sk_page_frag() in sendmsg
Hi,
Quoted 42 lines · Mat Martineau
(quoted diff) +0
-0@@ -80,33 +80,32 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) > goto put_out; > }net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 6 lines
net/mptcp/protocol.c +0
-5-/* Initial experiment: new page per send. Real code will -* maintain list of active pages and DSS mappings, append to the -* end and honor zerocopy -*/ - page =alloc_page (GFP_KERNEL );Allocating a new page per send is very inefficient for small sends, but was a placeholder for managing an MPTCP-level send buffer.
For each connection, we have one MPTCP-level socket, and some number of subflow sockets that it controls. Sent data needs to be stored by the MPTCP-level socket until it sees a relevant MPTCP
DATA_ACKfrom any one of the subflows and can purge the ack'd data.To meet that requirement, the idea was to have the MPTCP-level socket buffer the send data in a set of pages. Each
sendmsg()call would append to the current page while space is available, so each page would fill with contiguous data (in the MPTCP sequence space). If data was sent withMSG_ZEROCOPYthe userspace-provided pages would be used instead. The buffered data could then be sent (or resent) on multiple subflows by usingdo_tcp_sendpages()to create independent skbs referencing the one MPTCP-level copy of the data.For example:
* Userspace sends 1024 bytes of data
* MPTCP-level socket copies 1024 bytes to a page
* Four separate skbs are built, referencing the same page and offset for
the 1024 bytes* Each of the four skbs is near-simultaneously queued on a separate
subflow* One subflow is faster than the others, and gets the data sent and
DATA_ACK'd quickly
Quoted 6 lines
* MPTCP-level socket releases the buffer page (but the data might still
be referenced by a queued skb on a slow subflow)As a first step with a single subflow, I kept it simple by allocating one page per send and keeping track of that page in the MPTCP-level socket.
Thank you for the detailed feedback.
To double check I'm no the same page: most/all of the above infrastructure and features are missing in the current code base.
I *think* they could be added on top of this series with some changes...
Quoted 4 lines
Quoted 4 lines
net/mptcp/protocol.c +1
-3-if (!page) { - ret = -ENOMEM ; - goto put_out; +lock_sock (sk);
Quoted 8 lines
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 4 lines
net/mptcp/protocol.c +4
-0+lock_sock (ssk); + +/* use the subflow page cache so that memory accounting is coherent */ + pfrag =sk_page_frag (ssk);Given the plan to keep the paged data buffered by the MPTCP-level socket, is
sk_page_frag()the best way to get a page that might be used for skbs in multiple subflows?
... but some additional data structure would be needed (RB-tree for the pending page fragments ?!?) ...
Quoted 2 lines
Can memory accounting work properly if the page frag comes from sk (the MPTCP-level socket) instead of ssk?
AFAICS, it should. I have not tested it.
Yep, using sk's page frag should be better.
I'll try to give it a spin, unless you prefer a different approach.
Thanks,
Paolo
Mat Martineau
Re: [MPTCP] [RFC PATCH 1/4] mptcp: use sk_page_frag() in sendmsg
Quoted 48 lines · Paolo Abeni
Hi,
Quoted 45 lines · Mat Martineau
(quoted diff) +0
-0@@ -80,33 +80,32 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) > goto put_out; > }net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 6 lines
net/mptcp/protocol.c +0
-5-/* Initial experiment: new page per send. Real code will -* maintain list of active pages and DSS mappings, append to the -* end and honor zerocopy -*/ - page =alloc_page (GFP_KERNEL );Allocating a new page per send is very inefficient for small sends, but was a placeholder for managing an MPTCP-level send buffer.
For each connection, we have one MPTCP-level socket, and some number of subflow sockets that it controls. Sent data needs to be stored by the MPTCP-level socket until it sees a relevant MPTCP
DATA_ACKfrom any one of the subflows and can purge the ack'd data.To meet that requirement, the idea was to have the MPTCP-level socket buffer the send data in a set of pages. Each
sendmsg()call would append to the current page while space is available, so each page would fill with contiguous data (in the MPTCP sequence space). If data was sent withMSG_ZEROCOPYthe userspace-provided pages would be used instead. The buffered data could then be sent (or resent) on multiple subflows by usingdo_tcp_sendpages()to create independent skbs referencing the one MPTCP-level copy of the data.For example:
* Userspace sends 1024 bytes of data
* MPTCP-level socket copies 1024 bytes to a page
* Four separate skbs are built, referencing the same page and offset for
the 1024 bytes* Each of the four skbs is near-simultaneously queued on a separate
subflow* One subflow is faster than the others, and gets the data sent and
DATA_ACK'd quickly* MPTCP-level socket releases the buffer page (but the data might still
be referenced by a queued skb on a slow subflow)
Quoted 7 lines
Quoted 3 lines
As a first step with a single subflow, I kept it simple by allocating one page per send and keeping track of that page in the MPTCP-level socket.
Thank you for the detailed feedback.
To double check I'm no the same page: most/all of the above infrastructure and features are missing in the current code base.
That's correct.
Quoted 3 lines
I *think* they could be added on top of this series with some changes...
Ok, good! I was hoping the additional background would help make design choices at this stage rather than after you have done a lot more work.
Quoted 14 lines
Quoted 13 lines
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 87
Quoted 9 lines
net/mptcp/protocol.c +5
-3-if (!page) { - ret = -ENOMEM ; - goto put_out; +lock_sock (sk); +lock_sock (ssk); + +/* use the subflow page cache so that memory accounting is coherent */ + pfrag =sk_page_frag (ssk);Given the plan to keep the paged data buffered by the MPTCP-level socket, is
sk_page_frag()the best way to get a page that might be used for skbs in multiple subflows?
Quoted 2 lines
... but some additional data structure would be needed (RB-tree for the pending page fragments ?!?) ...
Right.
Quoted 10 lines
Quoted 3 lines
Can memory accounting work properly if the page frag comes from sk (the MPTCP-level socket) instead of ssk?
AFAICS, it should. I have not tested it.
Yep, using sk's page frag should be better.
I'll try to give it a spin, unless you prefer a different approach.
This looks like a good approach to me. Thanks!
--
Mat Martineau
Intel
Paolo Abeni
RFC PATCH 2/4 mptcp: sendmsg() do spool all the provided data
In reply to Paolo AbeniThis makes mptcp sendmsg() behaviour more consistent and improves xmit performances.
--- net/mptcp/protocol.c | 85 ++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 35 deletions(-)
net/mptcp/protocol.c +50 -35
@@ -47,42 +47,16 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)return NULL ; } -static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +static int mptcp_sendmsg_frag (struct sock *sk,struct sock *ssk, +struct msghdr *msg) {struct mptcp_sock *msk =mptcp_sk (sk);int mss_now, size_goal, poffset, ret;struct mptcp_ext *mpext =NULL ;struct page_frag *pfrag;struct sk_buff *skb; -struct sock *ssk;size_t psize; -pr_debug ("msk=%p" , msk); -if (msk->subflow) { -pr_debug ("fallback passthrough" ); -return sock_sendmsg (msk->subflow, msg); - } - - ssk =mptcp_subflow_get_ref (msk); -if (!ssk) -return -ENOTCONN ; - -if (!msg_data_left (msg)) { -pr_debug ("empty send" ); - ret =sock_sendmsg (ssk->sk_socket, msg); - goto put_out; - } - -pr_debug ("conn_list->subflow=%p" , ssk); - -if (msg->msg_flags & ~(MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL )) { - ret = -ENOTSUPP ; - goto put_out; - } - -lock_sock (sk); -lock_sock (ssk); -/* use the subflow page cache so that memory accounting is coherent */ pfrag =sk_page_frag (ssk);if (!sk_page_frag_refill (ssk, pfrag)) {
@@ -90,7 +64,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ret =sk_stream_wait_memory (sk, &timeo);if (ret) - goto release_out; +return ret; }/* Copy to page */
@@ -101,10 +75,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) pfrag->size - poffset), &msg->msg_iter);pr_debug ("left=%zu" ,msg_data_left (msg)); -if (!psize) { - ret = -EINVAL ; - goto release_out; - } +if (!psize) +return -EINVAL ;/* Mark the end of the previous write so the beginning of the * next write (with its own mptcp skb extension data) is not
@@ -119,7 +91,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ret =do_tcp_sendpages (ssk, pfrag->page, poffset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 ) - goto release_out; +return ret;if (skb ==tcp_write_queue_tail (ssk))pr_err ("no new skb %p/%p" , sk, ssk);
@@ -147,8 +119,51 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)subflow_ctx (ssk)->rel_write_seq += ret;tcp_push (ssk, msg->msg_flags, mss_now,tcp_sk (ssk)->nonagle, size_goal); +return ret; +} + +static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +size_t copied =0 ; +struct sock *ssk; +int ret =0 ; + +pr_debug ("msk=%p" , msk); +if (msk->subflow) { +pr_debug ("fallback passthrough" ); +return sock_sendmsg (msk->subflow, msg); + } + + ssk =mptcp_subflow_get_ref (msk); +if (!ssk) +return -ENOTCONN ; + +if (!msg_data_left (msg)) { +pr_debug ("empty send" ); + ret =sock_sendmsg (ssk->sk_socket, msg); + goto put_out; + } + +pr_debug ("conn_list->subflow=%p" , ssk); + +if (msg->msg_flags & ~(MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL )) { + ret = -ENOTSUPP ; + goto put_out; + } + +lock_sock (sk); +lock_sock (ssk); +while (msg_data_left (msg)) { + ret =mptcp_sendmsg_frag (sk, ssk, msg); +if (ret <0 ) +break ; + + copied += ret; + } +if (copied >0 ) + ret = copied; -release_out:release_sock (ssk);release_sock (sk);
Signature · 1 line
2.20.1
Mat Martineau
Re: [MPTCP] [RFC PATCH 2/4] mptcp: sendmsg() do spool all the provided data
Quoted 2 lines · Paolo Abeni
This makes mptcp
sendmsg()behaviour more consistent and improves xmit performances.
Thanks for improving this code.
Mat
Quoted 147 lines
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
net/mptcp/protocol.c| 85 ++++++++++++++++++++++++++------------------1 file changed, 50 insertions(+), 35 deletions(-)net/mptcp/protocol.c +50
-35@@ -47,42 +47,16 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)return NULL ; } -static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +static int mptcp_sendmsg_frag (struct sock *sk,struct sock *ssk, +struct msghdr *msg) {struct mptcp_sock *msk =mptcp_sk (sk);int mss_now, size_goal, poffset, ret;struct mptcp_ext *mpext =NULL ;struct page_frag *pfrag;struct sk_buff *skb; -struct sock *ssk;size_t psize; -pr_debug ("msk=%p" , msk); -if (msk->subflow) { -pr_debug ("fallback passthrough" ); -return sock_sendmsg (msk->subflow, msg); - } - - ssk =mptcp_subflow_get_ref (msk); -if (!ssk) -return -ENOTCONN ; - -if (!msg_data_left (msg)) { -pr_debug ("empty send" ); - ret =sock_sendmsg (ssk->sk_socket, msg); - goto put_out; - } - -pr_debug ("conn_list->subflow=%p" , ssk); - -if (msg->msg_flags & ~(MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL )) { - ret = -ENOTSUPP ; - goto put_out; - } - -lock_sock (sk); -lock_sock (ssk); -/* use the subflow page cache so that memory accounting is coherent */ pfrag =sk_page_frag (ssk);if (!sk_page_frag_refill (ssk, pfrag)) {@@ -90,7 +64,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ret =sk_stream_wait_memory (sk, &timeo);if (ret) - goto release_out; +return ret; }/* Copy to page */ @@ -101,10 +75,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) pfrag->size - poffset), &msg->msg_iter);pr_debug ("left=%zu" ,msg_data_left (msg)); -if (!psize) { - ret = -EINVAL ; - goto release_out; - } +if (!psize) +return -EINVAL ;/* Mark the end of the previous write so the beginning of the * next write (with its own mptcp skb extension data) is not @@ -119,7 +91,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ret =do_tcp_sendpages (ssk, pfrag->page, poffset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 ) - goto release_out; +return ret;if (skb ==tcp_write_queue_tail (ssk))pr_err ("no new skb %p/%p" , sk, ssk);@@ -147,8 +119,51 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)subflow_ctx (ssk)->rel_write_seq += ret;tcp_push (ssk, msg->msg_flags, mss_now,tcp_sk (ssk)->nonagle, size_goal); +return ret; +} + +static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) +{ +struct mptcp_sock *msk =mptcp_sk (sk); +size_t copied =0 ; +struct sock *ssk; +int ret =0 ; + +pr_debug ("msk=%p" , msk); +if (msk->subflow) { +pr_debug ("fallback passthrough" ); +return sock_sendmsg (msk->subflow, msg); + } + + ssk =mptcp_subflow_get_ref (msk); +if (!ssk) +return -ENOTCONN ; + +if (!msg_data_left (msg)) { +pr_debug ("empty send" ); + ret =sock_sendmsg (ssk->sk_socket, msg); + goto put_out; + } + +pr_debug ("conn_list->subflow=%p" , ssk); + +if (msg->msg_flags & ~(MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL )) { + ret = -ENOTSUPP ; + goto put_out; + } + +lock_sock (sk); +lock_sock (ssk); +while (msg_data_left (msg)) { + ret =mptcp_sendmsg_frag (sk, ssk, msg); +if (ret <0 ) +break ; + + copied += ret; + } +if (copied >0 ) + ret = copied; -release_out:release_sock (ssk);release_sock (sk);Signature · 6 lines
2.20.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
--
Mat Martineau
Intel
Paolo Abeni
RFC PATCH 3/4 mptcp: move tpext data_len initialization at option creation time
In reply to Paolo AbeniSo that we can cope easily with skb coalescing
--- net/mptcp/options.c | 2 ++ net/mptcp/protocol.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-)
net/mptcp/options.c +2 -0
@@ -335,6 +335,8 @@ void mptcp_write_option_header(__be32 *ptr, struct sk_buff *skb, } mpext =mptcp_get_ext (skb); +if (mpext) + mpext->data_len = skb->len -tcp_hdrlen (skb);if ((OPTION_MPTCP_DSS_MAP |OPTION_MPTCP_DSS_ACK ) & opts->suboptions) {
net/mptcp/protocol.c +0 -1
@@ -104,7 +104,6 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,memset (mpext,0 ,sizeof (*mpext)); mpext->data_seq = msk->write_seq; mpext->subflow_seq =subflow_ctx (ssk)->rel_write_seq; - mpext->data_len = ret; mpext->checksum =0xbeef ; mpext->use_map =1 ; mpext->dsn64 =1 ;
Signature · 1 line
2.20.1
Mat Martineau
Re: [MPTCP] [RFC PATCH 3/4] mptcp: move tpext data_len initialization at option creation time
Quoted 2 lines · Paolo Abeni
So that we can cope easily with skb coalescing
Paolo -
It's not necessarily the case that one skb corresponds to one MPTCP mapping (represented by the data_seq, subflow_seq, and data_len fields of mpext). If a large chunk of data is available for the MPTCP-level socket to send on a subflow, it might create one large mapping (covering up to 64k of the sequence space) that would cover a number of skbs. This approach can reduce MPTCP's TCP option header overhead.
It seems like the next patch tries to maintain the skb boundaries by setting 'eor', aligning the skb with the intended MPTCP mapping. The MPTCP-level socket needs to know where one mapping ends in order to set up the next mapping, so I'm not sure we gain a lot by deferring the mpext->data_len assignment until the header is written. Since skbs getting coalesced would all be in the tcp write queue, couldn't the mptcp_sendmsg_frag code update mpext->data_len on the coalesced skb before calling tcp_push()?
Mat
Quoted 39 lines
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
net/mptcp/options.c| 2 ++net/mptcp/protocol.c| 1 -2 files changed, 2 insertions(+), 1 deletion(-)net/mptcp/options.c +2
-0@@ -335,6 +335,8 @@ void mptcp_write_option_header(__be32 *ptr, struct sk_buff *skb, } mpext =mptcp_get_ext (skb); +if (mpext) + mpext->data_len = skb->len -tcp_hdrlen (skb);if ((OPTION_MPTCP_DSS_MAP |OPTION_MPTCP_DSS_ACK ) & opts->suboptions) {net/mptcp/protocol.c +0
-1@@ -104,7 +104,6 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,memset (mpext,0 ,sizeof (*mpext)); mpext->data_seq = msk->write_seq; mpext->subflow_seq =subflow_ctx (ssk)->rel_write_seq; - mpext->data_len = ret; mpext->checksum =0xbeef ; mpext->use_map =1 ; mpext->dsn64 =1 ;Signature · 6 lines
2.20.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
--
Mat Martineau
Intel
Paolo Abeni
RFC PATCH 4/4 mptcp: allow collapsing consecutive sendpages on the same substream
In reply to Paolo AbeniIf the current sendmsg() lands on the same subflow we used last, we can try to collapse the data.
--- include/net/mptcp.h | 1 + net/mptcp/protocol.c | 57 +++++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 17 deletions(-)
include/net/mptcp.h +1 -0
@@ -50,6 +50,7 @@ struct mptcp_sock {spinlock_t conn_list_lock;struct hlist_head conn_list;struct socket *subflow;/* outgoing connect/listener/!mp_capable */ +struct sock *last; };#define mptcp_for_each_subflow (__msk, __subflow) \
net/mptcp/protocol.c +40 -17
115 lines not on this page · raw message
Signature · 1 line
2.20.1
Mat Martineau
Re: [MPTCP] [RFC PATCH 4/4] mptcp: allow collapsing consecutive sendpages on the same substream
Hi Paolo,
Quoted 26 lines · Paolo Abeni
If the current
sendmsg()lands on the same subflow we used last, we can try to collapse the data.Signed-off-by Paolo Abeni <pabeni(a)redhat.com>---
include/net/mptcp.h| 1 +net/mptcp/protocol.c| 57 +++++++++++++++++++++++++++++++-------------2 files changed, 41 insertions(+), 17 deletions(-)include/net/mptcp.h +1
-0@@ -50,6 +50,7 @@ struct mptcp_sock {spinlock_t conn_list_lock;struct hlist_head conn_list;struct socket *subflow;/* outgoing connect/listener/!mp_capable */ +struct sock *last; };#define mptcp_for_each_subflow (__msk, __subflow) \net/mptcp/protocol.c +0
-0
net/mptcp/protocol.c static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk) · line 54
Quoted 8 lines
net/mptcp/protocol.c +5
-0@@ -47,11 +47,19 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)return NULL ; } +static inline bool mptcp_skb_can_collapse_to (const struct mptcp_sock *msk, +const struct sock *ssk, +const struct sk_buff *skb) +{ +return tcp_skb_can_collapse_to (skb) && (msk->last == ssk);
Even if the last send was on a particular subflow, that doesn't guarantee the next send can be collapsed on that subflow. There are other cases like MPTCP-level resends or sending duplicate data on different subflows.
I think it would have to make sure the MPTCP-level sequence numbers are contiguous before collapsing.
Quoted 24 lines
net/mptcp/protocol.c +8
-6+} +static int mptcp_sendmsg_frag (struct sock *sk,struct sock *ssk, -struct msghdr *msg) +struct msghdr *msg,int *pmss_now,int *ps_goal) { +int mss_now, avail_size, size_goal, poffset, ret;struct mptcp_sock *msk =mptcp_sk (sk); -int mss_now, size_goal, poffset, ret; +bool collapsed, can_collapse = false;struct mptcp_ext *mpext =NULL ;struct page_frag *pfrag;struct sk_buff *skb;@@ -78,25 +86,35 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,if (!psize)return -EINVAL ; -/* Mark the end of the previous write so the beginning of the -* next write (with its own mptcp skb extension data) is not -* collapsed. -*/ + mss_now =tcp_send_mss (ssk, &size_goal, msg->msg_flags); + *pmss_now = mss_now; + *ps_goal = size_goal;
net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 99
Quoted 10 lines
net/mptcp/protocol.c +7
-2+ avail_size = size_goal; skb =tcp_write_queue_tail (ssk); -if (skb) -TCP_SKB_CB (skb)->eor =1 ; +if (skb) { + can_collapse =mptcp_skb_can_collapse_to (msk, ssk, skb); +if (!can_collapse) +TCP_SKB_CB (skb)->eor =1 ; +else if (size_goal - skb->len >0 ) + avail_size = size_goal + size_goal - skb->len;
Can you comment more on the calculation for avail_size here - is this how you "allocate at most a new skb" as you mention below?
Quoted 12 lines
net/mptcp/protocol.c +6
-2+ } - mss_now =tcp_send_mss (ssk, &size_goal, msg->msg_flags); - psize =min_t (int, size_goal, psize); +/* be sure that we are going to allocate at most a new skb, and +* tell the tcp stack to delay the push so that we can safely +* access the skb after the sendpages call +*/ + psize =min_t (int, avail_size, psize); ret =do_tcp_sendpages (ssk, pfrag->page, poffset, psize, msg->msg_flags |MSG_SENDPAGE_NOTLAST );if (ret <=0 )
net/mptcp/protocol.c static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, · line 117
Quoted 10 lines
net/mptcp/protocol.c +4
-2return ret; -if (skb ==tcp_write_queue_tail (ssk)) -pr_err ("no new skb %p/%p" , sk, ssk); + collapsed = skb ==tcp_write_queue_tail (ssk); +BUG_ON (collapsed && !can_collapse); skb =tcp_write_queue_tail (ssk); +if (collapsed) + goto out;
Without the previous commit (moving mpext->data_len assignment), could you instead update the existing mpext in the "collapsed == true" case?
Mat
Quoted 62 lines
net/mptcp/protocol.c +10
-5mpext =skb_ext_add (skb,SKB_EXT_MPTCP );@@ -109,24 +127,25 @@ static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk, mpext->dsn64 =1 ;pr_debug ("data_seq=%llu subflow_seq=%u data_len=%u checksum=%u, dsn64=%d" , - mpext->data_seq, mpext->subflow_seq, mpext->data_len, + mpext->data_seq, mpext->subflow_seq, skb->len, mpext->checksum, mpext->dsn64); }/* TODO: else fallback */ +out: pfrag->offset += ret; + msk->last = ssk; msk->write_seq += ret;subflow_ctx (ssk)->rel_write_seq += ret; -tcp_push (ssk, msg->msg_flags, mss_now,tcp_sk (ssk)->nonagle, size_goal);return ret; }static int mptcp_sendmsg (struct sock *sk,struct msghdr *msg,size_t len) {struct mptcp_sock *msk =mptcp_sk (sk); +int mss_now =0 , size_goal =0 , ret =0 ;size_t copied =0 ;struct sock *ssk; -int ret =0 ;pr_debug ("msk=%p" , msk);if (msk->subflow) {@@ -153,15 +172,19 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)lock_sock (sk);lock_sock (ssk); +while (msg_data_left (msg)) { - ret =mptcp_sendmsg_frag (sk, ssk, msg); + ret =mptcp_sendmsg_frag (sk, ssk, msg, &mss_now, &size_goal);if (ret <0 )break ; copied += ret; } -if (copied >0 ) +if (copied) { ret = copied; +tcp_push (ssk, msg->msg_flags, mss_now,tcp_sk (ssk)->nonagle, + size_goal); + }release_sock (ssk);release_sock (sk);Signature · 6 lines
2.20.1 _______________________________________________ mptcp mailing list mptcp(a)lists.01.org https://lists.01.org/mailman/listinfo/mptcp
--
Mat Martineau
Intel
Paolo Abeni
Re: [MPTCP] [RFC PATCH 4/4] mptcp: allow collapsing consecutive sendpages on the same substream
Quoted 9 lines · Mat Martineau
Quoted 8 lines · Paolo Abeni
net/mptcp/protocol.c +0
-0@@ -47,11 +47,19 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)return NULL ; }
Quoted 9 lines
net/mptcp/protocol.c static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk) · line 54
Quoted 5 lines
net/mptcp/protocol.c +5
-0+static inline bool mptcp_skb_can_collapse_to (const struct mptcp_sock *msk, +const struct sock *ssk, +const struct sk_buff *skb) +{ +return tcp_skb_can_collapse_to (skb) && (msk->last == ssk);Even if the last send was on a particular subflow, that doesn't guarantee the next send can be collapsed on that subflow. There are other cases like MPTCP-level resends or sending duplicate data on different subflows.
uhmm... I thought a bit more about the above and the code in the patch still LGTM: msk->last references the last subflow we enqueued new data to, that is, the subflow with the higher/newer MPTCP write_seq...
Quoted 2 lines
I think it would have to make sure the MPTCP-level sequence numbers are contiguous before collapsing.
... so this condition always held, when (msk->last == ssk).
Am I missing something?
Thanks,
Paolo
Mat Martineau
Re: [MPTCP] [RFC PATCH 4/4] mptcp: allow collapsing consecutive sendpages on the same substream
Quoted 24 lines · Paolo Abeni
Quoted 9 lines · Mat Martineau
Quoted 8 lines · Paolo Abeni
net/mptcp/protocol.c +0
-0@@ -47,11 +47,19 @@ static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk)return NULL ; }Quoted 9 lines
net/mptcp/protocol.c static struct sock *mptcp_subflow_get_ref(const struct mptcp_sock *msk) · line 54
Quoted 5 lines
net/mptcp/protocol.c +5
-0+static inline bool mptcp_skb_can_collapse_to (const struct mptcp_sock *msk, +const struct sock *ssk, +const struct sk_buff *skb) +{ +return tcp_skb_can_collapse_to (skb) && (msk->last == ssk);Even if the last send was on a particular subflow, that doesn't guarantee the next send can be collapsed on that subflow. There are other cases like MPTCP-level resends or sending duplicate data on different subflows.
uhmm... I thought a bit more about the above and the code in the patch still LGTM:
msk->lastreferences the last subflow we enqueued new data to, that is, the subflow with the higher/newer MPTCPwrite_seq...
Quoted 7 lines
Quoted 2 lines
I think it would have to make sure the MPTCP-level sequence numbers are contiguous before collapsing.
... so this condition always held, when (
msk->last== ssk).Am I missing something?
Resends will be a problem with the "last subflow written to" assumption.
In a case where you have multiple subflows S1 and S2, you might have a scenario like this (sequence numbers are in the 64-bit MPTCP sequence space):
1. Send bytes 0-99 on S1
2. Send bytes 100-199 on S2
3. <time passes: S2 connection has a problem and data does not get through>
4. Send bytes 200-299 on S1
5. MPTCP-level resend 100-199 on S1
6. Send bytes 300-399 on S1
When you get to step 6, the "last" send was on S1, but you need a new MPTCP mapping header for bytes 300-399 because the previous byte in the S1 stream is 199. It's important to know where the earlier mappings end so you can create a new one without leaving a gap in the MPTCP sequence space.
--
Mat Martineau
Intel
Paolo Abeni
Re: [MPTCP] [RFC PATCH 4/4] mptcp: allow collapsing consecutive sendpages on the same substream
Quoted 30 lines · Mat Martineau
Quoted 11 lines · Paolo Abeni
uhmm... I thought a bit more about the above and the code in the patch still LGTM:
msk->lastreferences the last subflow we enqueued new data to, that is, the subflow with the higher/newer MPTCPwrite_seq...Quoted 2 lines
I think it would have to make sure the MPTCP-level sequence numbers are contiguous before collapsing.
... so this condition always held, when (
msk->last== ssk).Am I missing something?
Resends will be a problem with the "last subflow written to" assumption.
In a case where you have multiple subflows S1 and S2, you might have a scenario like this (sequence numbers are in the 64-bit MPTCP sequence space):
1. Send bytes 0-99 on S1
2. Send bytes 100-199 on S2
3. <time passes: S2 connection has a problem and data does not get through>
4. Send bytes 200-299 on S1
5. MPTCP-level resend 100-199 on S1
Quoted 8 lines
6. Send bytes 300-399 on S1
When you get to step 6, the "last" send was on S1, but you need a new MPTCP mapping header for bytes 300-399 because the previous byte in the S1 stream is 199. It's important to know where the earlier mappings end so you can create a new one without leaving a gap in the MPTCP sequence space.
Ah, now I see! thank you for the detailed example!
I'll take care in the next iteration, but I doubt I'll be able to send a new version before the next mtg, because I'm travelling with no/very limited time avail.
Thank you,
Paolo