Commit 8798bdf
committed
netstacklat: Exclude TCP reads for HOL blocked segments
The 'tcp-socket-read' currently reports the latency for the skb
containing the last TCP segment read from the socket. However, this
segment might have been head of line (HOL) blocked by a previous
segment missing. In this case, netstacklat's reported latency will
include HOL blocking periods that is dependent on external
factors (such as network packet loss, and network latency impacts
retransmission time). As netstacklat is primarily intended to identify
issues within the local host (in the network stack or receiving
applications), filter out any socket reads were the last read SKB
might have experienced HOL-blocking.
To exclude HOL-blocked reads, track whenever a TCP segment arrives
out-of-order (ooo), i.e. ahead of the expected next sequence. These
segments are kept in a separate ooo-queue and later merged back into
the socket receive queue once the missing segment gap has been
filled. The ooo-segments are therefore the only segments that may
experience HOL blocking (as non ooo-segments are immediately added to
the socket receive queue). Specifically, track the right edge (the
maximum) of the ooo sequence range. If the final byte of any socket
read is lower than right edge of the ooo sequence range, filter it out
as potentially HOL blocked. If the last read byte is ahead of the
ooo-range, the last byte must have been read from a segment that
arrived in-order and therefore haven't experienced HOL-blocking, so
it's safe to include the latency measurement. Furthermore, also
invalidate the ooo-range when the last read byte is ahead to prevent
an old ooo-range value sticking around until the sequence number wraps
around.
There are some scenarios that may cause this ooo-filtering to fail.
- If the program is started in the middle of an ongoing flow, there
may be ooo segments that arrived before we could record them in the
the tracked ooo-range. This may cause the latency for some initial
HOL-blocked reads to be reported.
- If multiple reads are done to the socket concurrently, we may not
correctly track the last read byte. The kernel does not keep a lock
on the TCP socket at the time our hooked function
tcp_recv_timestamp() runs. If two reads are done in parallel, it's
therefore possible that for both reads we will check the last read
byte (tcp_sock.copied_seq) after the second read has updated it. We
may then incorrectly conclude that the first read was ahead of the
ooo-range when it was not, and record its latency when we should
have excluded it. In practice I belive this issue should be quite
rare, as most applications will probably not attempt to perform
multiple concurrent reads to a single connected TCP socket in
parallel (as then you cannot know which part of the payload the
parallel reads will return).
- The tracked ooo-range may concurrently be updated at
tcp_data_queue_ofo() and and tcp_recv_timestamp(), leading to
inconsitent state.
The last of these issue will be addressed in a later commit that adds
bpf spin locks.
Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>1 parent cc17c68 commit 8798bdf
File tree
3 files changed
+175
-1
lines changed- headers/vmlinux
- netstacklat
3 files changed
+175
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
164 | 193 | | |
165 | 194 | | |
166 | 195 | | |
| |||
202 | 231 | | |
203 | 232 | | |
204 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
205 | 281 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
| |||
66 | 76 | | |
67 | 77 | | |
68 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
69 | 95 | | |
70 | 96 | | |
71 | 97 | | |
| |||
328 | 354 | | |
329 | 355 | | |
330 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
331 | 411 | | |
332 | 412 | | |
333 | 413 | | |
| |||
393 | 473 | | |
394 | 474 | | |
395 | 475 | | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
396 | 481 | | |
397 | 482 | | |
398 | 483 | | |
| |||
407 | 492 | | |
408 | 493 | | |
409 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
| 261 | + | |
| 262 | + | |
262 | 263 | | |
263 | 264 | | |
264 | 265 | | |
| |||
0 commit comments