Skip to contentSkip to conversation

pskb_extract() helper function.

RFC PATCH In review Sowmini Varadhan 2 participants 4 messages Apr 18, 2016

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

RFC PATCH 1/2 skbuff: Add pskb_extract() helper function

In reply to Sowmini Varadhan

A pattern of skb usage seen in modules such as RDS-TCP is to extract to_copy' bytes from the received TCP segment, starting at some offset off' into a new skb `clone'. This is done in the ->data_ready callback, where the clone skb is queued up for rx on the PF_RDS socket, while the parent TCP segment is returned unchanged back to the TCP engine.

The existing code uses the sequence

	clone = skb_clone(..);
	pskb_pull(clone, off, ..);
	pskb_trim(clone, to_copy, ..);

with the intention of discarding the first `off' bytes. However, skb_clone() + pskb_pull() implies pksb_expand_head(), which ends up doing a redundant memcpy of bytes that will then get discarded in __pskb_pull_tail().

To avoid this inefficiency, this commit adds pskb_extract() that creates the clone, and memcpy's only the relevant header/frag/frag_list to the start of `clone'. pskb_trim() is then invoked to trim clone down to the requested to_copy bytes.

---
 include/linux/skbuff.h |    2 +
 net/core/skbuff.c      |  248 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 250 insertions(+), 0 deletions(-)
include/linux/skbuff.h +2 -0
index da0ace3..a1ce639 100644
@@ -2986,6 +2986,8 @@ struct sk_buff *skb_vlan_untag(struct sk_buff *skb);
 int skb_ensure_writable(struct sk_buff *skb, int write_len);
 int skb_vlan_pop(struct sk_buff *skb);
 int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
+struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,
+			     gfp_t gfp);
 
 static inline int memcpy_from_msg(void *data, struct msghdr *msg, int len)
 {
net/core/skbuff.c +248 -0

251 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

RFC PATCH 2/2 RDS: TCP: Call pskb_extract() helper function

In reply to Sowmini Varadhan

rds-stress experiments with request size 256 bytes, 8K acks, using 16 threads show a 40% improvment when pskb_extract() replaces the {skb_clone(..); pskb_pull(..); pskb_trim(..);} pattern in the Rx path, so we leverage the perf gain with this commit.

---
 net/rds/tcp_recv.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)
net/rds/tcp_recv.c +3 -11
index 27a9921..d75d8b5 100644
@@ -207,22 +207,14 @@ static int rds_tcp_data_recv(read_descriptor_t *desc, struct sk_buff *skb,
 		}
 
 		if (left && tc->t_tinc_data_rem) {
-			clone = skb_clone(skb, arg->gfp);
+			to_copy = min(tc->t_tinc_data_rem, left);
+
+			clone = pskb_extract(skb, offset, to_copy, arg->gfp);
 			if (!clone) {
 				desc->error = -ENOMEM;
 				goto out;
 			}
 
-			to_copy = min(tc->t_tinc_data_rem, left);
-			if (!pskb_pull(clone, offset) ||
-			    pskb_trim(clone, to_copy)) {
-				pr_warn("rds_tcp_data_recv: pull/trim failed "
-					"left %zu data_rem %zu skb_len %d\n",
-					left, tc->t_tinc_data_rem, skb->len);
-				kfree_skb(clone);
-				desc->error = -ENOMEM;
-				goto out;
-			}
 			skb_queue_tail(&tinc->ti_skb_list, clone);
 
 			rdsdebug("skb %p data %p len %d off %u to_copy %zu -> "
Signature · 1 line
1.7.1
#0 lore raw

cover pskb_extract() helper function.

This patchset follows up on the discussion in
https://www.mail-archive.com/[email protected]/msg105090.html

For RDS-TCP, we have to deal with the full gamut of nonlinear sk_buffs, including all the frag_list variants. Also, the parent skb has to remain unchanged, while the clone is queued for Rx on the PF_RDS socket.

Patch 1 of this patchset adds a pskb_extract() function that does all this without the redundant memcpy's in pskb_expand_head() and __pskb_pull_tail().

A further optimization is also possible by inlining pskb_trim() itself into pskb_carve() and thus avoiding the needless copy of trailer frags/pages that will then get trimmed away. I am deferring that optimization for the next iteration, and would like to get feedback on this first pass, which by itself gives a noticeable perf boost.

Sowmini Varadhan (2):
Add pskb_extract() helper function
Call pskb_extract() helper function

 include/linux/skbuff.h |    2 +
 net/core/skbuff.c      |  248 ++++++++++++++++++++++++++++++++++++++++++++++++
 net/rds/tcp_recv.c     |   14 +--
 3 files changed, 253 insertions(+), 11 deletions(-)
#3 lore raw
Quoted 12 lines · Sowmini Varadhan

This patchset follows up on the discussion in
https://www.mail-archive.com/[email protected]/msg105090.html

For RDS-TCP, we have to deal with the full gamut of nonlinear sk_buffs, including all the frag_list variants. Also, the parent skb has to remain unchanged, while the clone is queued for Rx on the PF_RDS socket.

Patch 1 of this patchset adds a pskb_extract() function that does all this without the redundant memcpy's in pskb_expand_head() and __pskb_pull_tail().

Quoted 6 lines

A further optimization is also possible by inlining pskb_trim() itself into pskb_carve() and thus avoiding the needless copy of trailer frags/pages that will then get trimmed away. I am deferring that optimization for the next iteration, and would like to get feedback on this first pass, which by itself gives a noticeable perf boost.

I like this idea. We can also make use of it in SCTP.

Marcelo