Skip to contentSkip to conversation

nbd: use TCP_NODELAY

PATCH Applied Stefan Hajnoczi 3 participants 6 messages Apr 15, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

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
#2 lore raw

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
index 662df16..485bbf0 100644
@@ -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
#3 lore raw

PATCH 3/3 nbd: set TCP_NODELAY

In reply to Stefan Hajnoczi

Disable 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
index 485bbf0..d9dc454 100644
@@ -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
#1 lore raw

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
index eff683c..662df16 100644
@@ -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
Tested-by on the v1 series
#4 lore raw
In reply to Stefan Hajnoczi
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 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.

Quoted 8 lines

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(-)

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

#5 lore raw
In reply to Stefan Hajnoczi

Il 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 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.

Quoted 8 lines

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(-)

Thanks, applied all to nbd-next.

I also marked patch 1 for stable branches.

Paolo