• Neil Brown's avatar
    [PATCH] PATCH 13/16: NFSD: TCP: Reserve space on sndbuf so we never block when writing · a87d7392
    Neil Brown authored
    Make sure there is alway adequate sndbuf space for replies.
    
    We keep track of how much space might be needed for replies
    and never dequeue a request unless there is adequate space
    for a maximal reply.  We assume each request will generate a maximal
    sized reply until the request is partly decoded.
    Each RPC program/procedure can specify the maximum size
    of a reply to the precedure (though they don't yet).
    
    The wspace callback is used to enqueue sockets that may be waiting
    for sndbuf space to become available.
    
    As there should always be enough buffer space to the full
    reply, the only reason that sock_sendmsg could block is due
    to a kmalloc delay.  As this is likely to be fairly quick (and if
    it isn't the server is clagged anyway) we remove the MSG_DONTWAIT
    flag, but set a 30 second timeout on waiting.  If the wait
    ever times out, we close the connection.  If it doesn't we can
    be sure that we did a complete write.
    
    
    When a request completes, we make sure that the space
    used for the reply does not exceed the space reserved.  This
    is an internal consistancy check.
    
    This patchs sets the sndbuf and rcvbuf sizes for all sockets
    used for rpc service.  This size if dependant on the servers bufsize (S) and
    partially on the number of threads (N).
    
    For UDP
        sndbuf == 5*S
        rcvbuf == (N+2)*S
    for TCP
        sndbuf == N*S
        rcvbuf == 3*S
    
    see code for rationale (in comments).
    a87d7392
svc.c 9.5 KB