nbd: use TCP_NODELAY
cover nbd: use TCP_NODELAY
The nbd block driver should use TCP_NODELAY. Nick Thomas <[email protected]> measured a 40 millisecond latency added by the Naggle algorithm.
This series turns on TCP_NODELAY. This requires that we use TCP_CORK to efficiently send NBD requests that contain a payload after the header.
Finally, fix a bug where we forget to unlock a mutex when sending fails.
Stefan Hajnoczi (3):
nbd: unlock mutex in nbd_co_send_request() error path
nbd: use TCP_CORK in nbd_co_send_request()
nbd: set TCP_NODELAY
block/nbd.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.1.4
PATCH 2/3 nbd: use TCP_CORK in nbd_co_send_request()
Use TCP_CORK to defer packet transmission until both the header and the payload have been written.
--- block/nbd.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
block/nbd.c +16 -6
@@ -334,13 +334,23 @@ static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request, s->send_coroutine =qemu_coroutine_self ();qemu_aio_set_fd_handler (s->sock, nbd_reply_ready, nbd_restart_write, nbd_have_request, s); - rc =nbd_send_request (s->sock, request); -if (rc >=0 && qiov) { - ret =qemu_co_sendv (s->sock, qiov->iov, qiov->niov, - offset, request->len); -if (ret != request->len) { - rc = -EIO ; +if (qiov) { +if (!s->is_unix) { +socket_set_cork (s->sock,1 ); } + rc =nbd_send_request (s->sock, request); +if (rc >=0 ) { + ret =qemu_co_sendv (s->sock, qiov->iov, qiov->niov, + offset, request->len); +if (ret != request->len) { + rc = -EIO ; + } + } +if (!s->is_unix) { +socket_set_cork (s->sock,0 ); + } + }else { + rc =nbd_send_request (s->sock, request); }qemu_aio_set_fd_handler (s->sock, nbd_reply_ready,NULL , nbd_have_request, s);
Signature · 1 line
1.8.1.4
PATCH 3/3 nbd: set TCP_NODELAY
In reply to Stefan HajnocziDisable the Nagle algorithm to reduce latency. Note this means we must also use TCP_CORK when sending header followed by payload to avoid fragmenting lots of little packets. The previous patch took care of that.
--- block/nbd.c | 3 +++ 1 file changed, 3 insertions(+)
block/nbd.c +3 -0
@@ -406,6 +406,9 @@ static int nbd_establish_connection(BlockDriverState *bs) sock =unix_socket_outgoing (qemu_opt_get (s->socket_opts,"path" )); }else { sock =tcp_socket_outgoing_opts (s->socket_opts); +if (sock >=0 ) { +socket_set_nodelay (sock); + } }/* Failed to establish connection */
Signature · 1 line
1.8.1.4
PATCH 1/3 nbd: unlock mutex in nbd_co_send_request() error path
In reply to Stefan Hajnoczi--- block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/nbd.c +1 -1
@@ -339,7 +339,7 @@ static int nbd_co_send_request(BDRVNBDState *s, struct nbd_request *request, ret =qemu_co_sendv (s->sock, qiov->iov, qiov->niov, offset, request->len);if (ret != request->len) { -return -EIO ; + rc = -EIO ; } } qemu_aio_set_fd_handler(s->sock, nbd_reply_ready, NULL,
Signature · 1 line
1.8.1.4
Quoted 8 lines · Stefan Hajnoczi
The nbd block driver should use
TCP_NODELAY. Nick Thomas <[email protected]> measured a 40 millisecond latency added by the Naggle algorithm.This series turns on
TCP_NODELAY. This requires that we useTCP_CORKto efficiently send NBD requests that contain a payload after the header.Finally, fix a bug where we forget to unlock a mutex when sending fails.
Quoted 8 lines
Stefan Hajnoczi (3):
nbd: unlock mutex innbd_co_send_request()error path
nbd: useTCP_CORKinnbd_co_send_request()
nbd: setTCP_NODELAYblock/nbd.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
Running "dd if=/dev/zero of=/dev/hda bs=4096 count=1" - latency is reduced from ~40ms to ~0.2ms. The entire NBD write request ends up in a single ethernet frame, where mtu supports it (verified with wireshark).
Thanks!
/Nick
Paolo Bonzini
AppliedIl 15/04/2013 16:14, Stefan Hajnoczi ha scritto:
Quoted 8 lines
The nbd block driver should use
TCP_NODELAY. Nick Thomas <[email protected]> measured a 40 millisecond latency added by the Naggle algorithm.This series turns on
TCP_NODELAY. This requires that we useTCP_CORKto efficiently send NBD requests that contain a payload after the header.Finally, fix a bug where we forget to unlock a mutex when sending fails.
Quoted 8 lines
Stefan Hajnoczi (3):
nbd: unlock mutex innbd_co_send_request()error path
nbd: useTCP_CORKinnbd_co_send_request()
nbd: setTCP_NODELAYblock/nbd.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
Thanks, applied all to nbd-next.
I also marked patch 1 for stable branches.
Paolo