• Kuniyuki Iwashima's avatar
    udp: Improve load balancing for SO_REUSEPORT. · 325ac51b
    Kuniyuki Iwashima authored
    [ Upstream commit efc6b6f6 ]
    
    Currently, SO_REUSEPORT does not work well if connected sockets are in a
    UDP reuseport group.
    
    Then reuseport_has_conns() returns true and the result of
    reuseport_select_sock() is discarded. Also, unconnected sockets have the
    same score, hence only does the first unconnected socket in udp_hslot
    always receive all packets sent to unconnected sockets.
    
    So, the result of reuseport_select_sock() should be used for load
    balancing.
    
    The noteworthy point is that the unconnected sockets placed after
    connected sockets in sock_reuseport.socks will receive more packets than
    others because of the algorithm in reuseport_select_sock().
    
        index | connected | reciprocal_scale | result
        ---------------------------------------------
        0     | no        | 20%              | 40%
        1     | no        | 20%              | 20%
        2     | yes       | 20%              | 0%
        3     | no        | 20%              | 40%
        4     | yes       | 20%              | 0%
    
    If most of the sockets are connected, this can be a problem, but it still
    works better than now.
    
    Fixes: acdcecc6 ("udp: correct reuseport selection with connected sockets")
    CC: Willem de Bruijn <willemb@google.com>
    Reviewed-by: default avatarBenjamin Herrenschmidt <benh@amazon.com>
    Signed-off-by: default avatarKuniyuki Iwashima <kuniyu@amazon.co.jp>
    Acked-by: default avatarWillem de Bruijn <willemb@google.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    325ac51b
udp.c 41.7 KB