Skip to content

tcp: Prevent tcp_collapse() from bloating queue.

Kuniyuki Iwashima mptcp netdev 3 versions – Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest7 patches 6 repliesApplied 7/7
  2. v27 patches 3 repliesSuperseded
  3. v18 patches 15 repliesSuperseded

Changes in v3 from the cover letter

* Patch 3:
* Remove fully-overlapping skb in the 2nd loop
* Skip range on overlapping unmergeable ofo skb
* Update tcp_collapse() comment
* Patch 4:
* Remove redundant kmalloc_size_roundup()
* Rename helper with skb_ prefix
* Declare {old,new}_truesize as unsigned int
* Patch 5:
* Make TCP_COLLAPSE_MAX_TOTAL_SIZE hard-limit for multiple skbs

Patches in v3 All 7 applied

#Subject and filesSizeRepliesApplied
1/7tcp: Refactor the first loop in tcp_collapse().net/ipv4/tcp_input.c+10 -180 repliesApplied
2/7tcp: Don't collapse high density skb.net/ipv4/tcp_input.c+20 -40 repliesApplied
3/7tcp: Stop collapsing if not bloated.net/ipv4/tcp_input.c+53 -302 repliesApplied
4/7tcp: Skip collapsing if collapsed skb is less-dense.include/linux/skbuff.h net/core/skbuff.c net/ipv4/tcp_input.c+40 -41 replyApplied
5/7tcp: Allocate all new skb before collapsing.net/ipv4/tcp_input.c+32 -92 repliesApplied
6/7tcp: Batch memory accounting in tcp_collapse().net/ipv4/tcp_input.c+30 -50 repliesApplied
7/7selftest: packetdrill: Add test for tcp_collapse().tools/testing/selftests/net/packetdrill/ksft_runner.sh tools/testing/selftests/net/packetdrill/tcp_rcv_collapse_bloated.pkt+144 -01 replyApplied

Reviews trailers per patch

All 7 patches have a Reviewed-by or Acked-by.

PatchEric DumazetMatthieu Baerts (NGI0)
1/7R-b
2/7R-b
3/7R-b A-b
4/7R-b
5/7R-b
6/7R-b
7/7R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 net-next 0/7] tcp: Prevent tcp_collapse() from bloating queue.

This is a follow-up for commit 031c403d13e5 ("tcp: do not let tcp_collapse() drive sk_forward_alloc negative").

The core algorithm in tcp_collapse() is so simple and has not been changed since commit 1da177e4c3f4 ("Linux-2.6.12-rc2"); finding a collapsible skb and repacking it into up-to-SKB_MAX_ORDER() skb.

Now that we use 4K MSS and tp->scaling_ratio, the simple algorithm does not work well, and it could even end up consuming more memory contrary to the intention.

For example, the scaling ratio of SKB_MAX_ORDER() is 222, but typically tp->scaling_ratio for 4K MSS flow is 252, and repacking data rather bloats high-density skb.

Also, once a low-density skb starts collapsing, it drags all the following skbs into collapsing regardless of the density.

This series changes the algorithm so that it skips high-density skb and a single low-density skb between high-density skbs, batches memory accounting at the end, and removes sk_forced_mem_schedule().

This series still keeps linear SKB_MAX_ORDER(0, 0) skbs as the collapse target, and Eric is working on a follow-up patch to store the collapsed payload in order-0 page frags instead.

https://lore.kernel.org/netdev/CAL4WiiqekjxZw3EoDYXLc0Phd3i0GStE2ZHWQkH2iAkSM5D8TQ@mail.gmail.com/

Changes:
v3:
* Patch 3:
* Remove fully-overlapping skb in the 2nd loop
* Skip range on overlapping unmergeable ofo skb
* Update tcp_collapse() comment
* Patch 4:
* Remove redundant kmalloc_size_roundup()
* Rename helper with skb_ prefix
* Declare {old,new}_truesize as unsigned int
* Patch 5:
* Make TCP_COLLAPSE_MAX_TOTAL_SIZE hard-limit for multiple skbs

v2: https://lore.kernel.org/netdev/[email protected]/
* Patch 1: Describe SYN/FIN behaviour change
* Patch 3: Describe behavioural change for MPTCP
* Patch 4: Add compute_skb_truesize() instead of macro
* Patch 7: Rename test to tcp_rcv_collapse_bloated.pkt

v1: https://lore.kernel.org/netdev/[email protected]/

Kuniyuki Iwashima (7):
tcp: Refactor the first loop in tcp_collapse().
tcp: Don't collapse high density skb.
tcp: Stop collapsing if not bloated.
tcp: Skip collapsing if collapsed skb is less-dense.
tcp: Allocate all new skb before collapsing.
tcp: Batch memory accounting in tcp_collapse().
selftest: packetdrill: Add test for tcp_collapse().

 include/linux/skbuff.h                        |   2 +
 net/core/skbuff.c                             |  27 ++-
 net/ipv4/tcp_input.c                          | 190 +++++++++++++-----
 .../selftests/net/packetdrill/ksft_runner.sh  |   9 +
 .../packetdrill/tcp_rcv_collapse_bloated.pkt  | 135 +++++++++++++
 5 files changed, 311 insertions(+), 52 deletions(-)
 create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcv_collapse_bloated.pkt
Signature · 1 line
2.56.1.708.g77570a6a1d-goog