Commit fb87bd4
net: Introduce sk_use_task_frag in struct sock.
Sockets that can be used while recursing into memory reclaim, like
those used by network block devices and file systems, mustn't use
current->task_frag: if the current process is already using it, then
the inner memory reclaim call would corrupt the task_frag structure.
To avoid this, sk_page_frag() uses ->sk_allocation to detect sockets
that mustn't use current->task_frag, assuming that those used during
memory reclaim had their allocation constraints reflected in
->sk_allocation.
This unfortunately doesn't cover all cases: in an attempt to remove all
usage of GFP_NOFS and GFP_NOIO, sunrpc stopped setting these flags in
->sk_allocation, and used memalloc_nofs critical sections instead.
This breaks the sk_page_frag() heuristic since the allocation
constraints are now stored in current->flags, which sk_page_frag()
can't read without risking triggering a cache miss and slowing down
TCP's fast path.
This patch creates a new field in struct sock, named sk_use_task_frag,
which sockets with memory reclaim constraints can set to false if they
can't safely use current->task_frag. In such cases, sk_page_frag() now
always returns the socket's page_frag (->sk_frag). The first user is
sunrpc, which needs to avoid using current->task_frag but can keep
->sk_allocation set to GFP_KERNEL otherwise.
Eventually, it might be possible to simplify sk_page_frag() by only
testing ->sk_use_task_frag and avoid relying on the ->sk_allocation
heuristic entirely (assuming other sockets will set ->sk_use_task_frag
according to their constraints in the future).
The new ->sk_use_task_frag field is placed in a hole in struct sock and
belongs to a cache line shared with ->sk_shutdown. Therefore it should
be hot and shouldn't have negative performance impacts on TCP's fast
path (sk_shutdown is tested just before the while() loop in
tcp_sendmsg_locked()).
Link: https://lore.kernel.org/netdev/b4d8cb09c913d3e34f853736f3f5628abfd7f4b6.1656699567.git.gnault@redhat.com/
Signed-off-by: Guillaume Nault <[email protected]>
Reviewed-by: Benjamin Coddington <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>1 parent b389a90 commit fb87bd4
2 files changed
+10
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
321 | 324 | | |
322 | 325 | | |
323 | 326 | | |
| |||
512 | 515 | | |
513 | 516 | | |
514 | 517 | | |
| 518 | + | |
515 | 519 | | |
516 | 520 | | |
517 | 521 | | |
| |||
2561 | 2565 | | |
2562 | 2566 | | |
2563 | 2567 | | |
2564 | | - | |
| 2568 | + | |
| 2569 | + | |
2565 | 2570 | | |
2566 | 2571 | | |
2567 | 2572 | | |
2568 | 2573 | | |
2569 | 2574 | | |
2570 | 2575 | | |
2571 | | - | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
2572 | 2579 | | |
2573 | 2580 | | |
2574 | 2581 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3390 | 3390 | | |
3391 | 3391 | | |
3392 | 3392 | | |
| 3393 | + | |
3393 | 3394 | | |
3394 | 3395 | | |
3395 | 3396 | | |
| |||
0 commit comments