Skip to content

Commit

Permalink
drbd: TCP: use sk_set_memalloc and sk_allocation ATOMIC
Browse files Browse the repository at this point in the history
We used to "only" set NOIO. But we are a block device, we are
in the write-out path, we may need to tap into the "reserves"
to facilitate memory reclaim.

If you expect to have serious memory pressure,
we recommend to generously increase sysctl min_free_kbytes.
  • Loading branch information
lge committed Feb 12, 2025
1 parent c1bc9aa commit 4bb47c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion drbd/drbd_transport_lb-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,13 @@ static void dtl_setup_socket(struct dtl_transport *dtl_transport, struct socket
long timeout = HZ;

socket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */
socket->sk->sk_allocation = GFP_NOIO;
/* We are a block device, we are in the write-out path,
* we may need memory to facilitate memory reclaim
*/
socket->sk->sk_use_task_frag = false;
socket->sk->sk_allocation = GFP_ATOMIC;
sk_set_memalloc(socket->sk);

socket->sk->sk_priority = use_for_data ? TC_PRIO_INTERACTIVE_BULK : TC_PRIO_INTERACTIVE;
tcp_sock_set_nodelay(socket->sk);

Expand Down
10 changes: 8 additions & 2 deletions drbd/drbd_transport_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1322,12 +1322,18 @@ static int dtt_connect(struct drbd_transport *transport)
dsocket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */
csocket->sk->sk_reuse = SK_CAN_REUSE; /* SO_REUSEADDR */

dsocket->sk->sk_allocation = GFP_NOIO;
csocket->sk->sk_allocation = GFP_NOIO;
/* We are a block device, we are in the write-out path,
* we may need memory to facilitate memory reclaim
*/
dsocket->sk->sk_allocation = GFP_ATOMIC;
csocket->sk->sk_allocation = GFP_ATOMIC;

dsocket->sk->sk_use_task_frag = false;
csocket->sk->sk_use_task_frag = false;

sk_set_memalloc(dsocket->sk);
sk_set_memalloc(csocket->sk);

dsocket->sk->sk_priority = TC_PRIO_INTERACTIVE_BULK;
csocket->sk->sk_priority = TC_PRIO_INTERACTIVE;

Expand Down

0 comments on commit 4bb47c9

Please sign in to comment.