Skip to content

Commit 1033990

Browse files
lxindavem330
authored andcommitted
sctp: implement memory accounting on tx path
Now when sending packets, sk_mem_charge() and sk_mem_uncharge() have been used to set sk_forward_alloc. We just need to call sk_wmem_schedule() to check if the allocated should be raised, and call sk_mem_reclaim() to check if the allocated should be reduced when it's under memory pressure. If sk_wmem_schedule() returns false, which means no memory is allowed to allocate, it will block and wait for memory to become available. Note different from tcp, sctp wait_for_buf happens before allocating any skb, so memory accounting check is done with the whole msg_len before it too. Reported-by: Matteo Croce <[email protected]> Tested-by: Matteo Croce <[email protected]> Acked-by: Neil Horman <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 93144b0 commit 1033990

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

net/sctp/socket.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,10 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
19131913
if (sctp_wspace(asoc) < (int)msg_len)
19141914
sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc));
19151915

1916-
if (sctp_wspace(asoc) <= 0) {
1916+
if (sk_under_memory_pressure(sk))
1917+
sk_mem_reclaim(sk);
1918+
1919+
if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) {
19171920
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
19181921
err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
19191922
if (err)
@@ -8930,7 +8933,10 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
89308933
goto do_error;
89318934
if (signal_pending(current))
89328935
goto do_interrupted;
8933-
if ((int)msg_len <= sctp_wspace(asoc))
8936+
if (sk_under_memory_pressure(sk))
8937+
sk_mem_reclaim(sk);
8938+
if ((int)msg_len <= sctp_wspace(asoc) &&
8939+
sk_wmem_schedule(sk, msg_len))
89348940
break;
89358941

89368942
/* Let another process have a go. Since we are going

0 commit comments

Comments
 (0)