@@ -4467,7 +4467,8 @@ static bool tcp_try_coalesce(struct sock *sk,
struct sk_buff *from,
bool *fragstolen)
{
- int delta, len = from->len;
+ int i, delta, len = from->len;
+ bool fastpath;
*fragstolen = false;
if (tcp_hdr(from)->fin)
@@ -4484,6 +4485,7 @@ merge:
if (skb_has_frag_list(to) || skb_has_frag_list(from))
return false;
+ fastpath = !from->cloned || atomic_read(&skb_shinfo(from)->dataref) == 1;
if (skb_headlen(from) == 0 &&
(skb_shinfo(to)->nr_frags +
skb_shinfo(from)->nr_frags <= MAX_SKB_FRAGS)) {
@@ -4497,7 +4499,13 @@ copyfrags:
skb_shinfo(from)->frags,
skb_shinfo(from)->nr_frags * sizeof(skb_frag_t));
skb_shinfo(to)->nr_frags += skb_shinfo(from)->nr_frags;
- skb_shinfo(from)->nr_frags = 0;
+
+ if (fastpath)
+ skb_shinfo(from)->nr_frags = 0;
+ else
+ for (i = 0; i < skb_shinfo(from)->nr_frags; i++)
+ skb_frag_ref(from, i);
+
to->truesize += delta;
atomic_add(delta, &sk->sk_rmem_alloc);
sk_mem_charge(sk, delta);
@@ -4515,7 +4523,9 @@ copyfrags:
offset = from->data - (unsigned char *)page_address(page);
skb_fill_page_desc(to, skb_shinfo(to)->nr_frags,
page, offset, skb_headlen(from));
- *fragstolen = true;
+ *fragstolen = fastpath;
+ if (!fastpath)
+ get_page(page);
delta = len; /* we dont know real truesize... */
goto copyfrags;
}