Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57b55a7e authored by Alexander Duyck's avatar Alexander Duyck Committed by David S. Miller
Browse files

tcp: Move code related to head frag in tcp_try_coalesce



This change reorders the code related to the use of an skb->head_frag so it
is placed before we check the rest of the frags.  This allows the code to
read more linearly instead of like some sort of loop.

Signed-off-by: default avatarAlexander Duyck <alexander.h.duyck@intel.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c73c3d9c
Loading
Loading
Loading
Loading
+25 −17
Original line number Diff line number Diff line
@@ -4562,9 +4562,31 @@ static bool tcp_try_coalesce(struct sock *sk,
	if (skb_has_frag_list(to) || skb_has_frag_list(from))
		return false;

	if (skb_headlen(from) == 0 &&
	    (skb_shinfo(to)->nr_frags +
	     skb_shinfo(from)->nr_frags <= MAX_SKB_FRAGS)) {
	if (skb_headlen(from) != 0) {
		struct page *page;
		unsigned int offset;

		if (skb_shinfo(to)->nr_frags +
		    skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS)
			return false;

		if (!from->head_frag || skb_cloned(from))
			return false;

		delta = from->truesize - SKB_DATA_ALIGN(sizeof(struct sk_buff));

		page = virt_to_head_page(from->head);
		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;
		goto copyfrags;
	} else {
		if (skb_shinfo(to)->nr_frags +
		    skb_shinfo(from)->nr_frags > MAX_SKB_FRAGS)
			return false;

		delta = from->truesize -
			SKB_TRUESIZE(skb_end_pointer(from) - from->head);
copyfrags:
@@ -4587,20 +4609,6 @@ static bool tcp_try_coalesce(struct sock *sk,
		to->data_len += len;
		goto merge;
	}
	if (from->head_frag && !skb_cloned(from)) {
		struct page *page;
		unsigned int offset;

		if (skb_shinfo(to)->nr_frags + skb_shinfo(from)->nr_frags >= MAX_SKB_FRAGS)
			return false;
		page = virt_to_head_page(from->head);
		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;
		delta = from->truesize - SKB_DATA_ALIGN(sizeof(struct sk_buff));
		goto copyfrags;
	}
	return false;
}