• Eric Dumazet's avatar
    tcp: avoid looping in tcp_send_fin() · b5635e45
    Eric Dumazet authored
    [ Upstream commit 845704a5 ]
    
    Presence of an unbound loop in tcp_send_fin() had always been hard
    to explain when analyzing crash dumps involving gigantic dying processes
    with millions of sockets.
    
    Lets try a different strategy :
    
    In case of memory pressure, try to add the FIN flag to last packet
    in write queue, even if packet was already sent. TCP stack will
    be able to deliver this FIN after a timeout event. Note that this
    FIN being delivered by a retransmit, it also carries a Push flag
    given our current implementation.
    
    By checking sk_under_memory_pressure(), we anticipate that cooking
    many FIN packets might deplete tcp memory.
    
    In the case we could not allocate a packet, even with __GFP_WAIT
    allocation, then not sending a FIN seems quite reasonable if it allows
    to get rid of this socket, free memory, and not block the process from
    eventually doing other useful work.
    Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
    b5635e45
tcp_output.c 97.1 KB