Skip to contentSkip to conversation

net/ceph: Only clear SOCK_NOSPACE when there is sufficient space in the socket buffer

PATCH In review Jim Schutt 2 participants 5 messages Feb 1, 2012 – Feb 29, 2012 Ceph common code (libceph)

lore
Share & tools
lore

Jim Schutt

author
#0 lore raw

PATCH 1/1 net/ceph: Only clear SOCK_NOSPACE when there is sufficient space in the socket buffer

The Ceph messenger would sometimes queue multiple work items to write data to a socket when the socket buffer was full.

Fix this problem by making ceph_write_space() use SOCK_NOSPACE in the same way that net/core/stream.c:sk_stream_write_space() does, i.e., clearing it only when sufficient space is available in the socket buffer.

---
 net/ceph/messenger.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
net/ceph/messenger.c +12 -6
index 67973f0..a4df90b 100644
@@ -175,16 +175,22 @@ static void ceph_write_space(struct sock *sk)
 	struct ceph_connection *con =
 		(struct ceph_connection *)sk->sk_user_data;
 
-	/* only queue to workqueue if there is data we want to write. */
+	/* only queue to workqueue if there is data we want to write,
+	 * and there is sufficient space in the socket buffer to accept
+	 * more data.  clear SOCK_NOSPACE so that ceph_write_space()
+	 * doesn't get called again until try_write() fills the socket
+	 * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
+	 * and net/core/stream.c:sk_stream_write_space().
+	 */
 	if (test_bit(WRITE_PENDING, &con->state)) {
-		dout("ceph_write_space %p queueing write work\n", con);
-		queue_con(con);
+		if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
+			dout("ceph_write_space %p queueing write work\n", con);
+			clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
+			queue_con(con);
+		}
 	} else {
 		dout("ceph_write_space %p nothing to write\n", con);
 	}
-
-	/* since we have our own write_space, clear the SOCK_NOSPACE flag */
-	clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
 }
 
 /* socket's state has changed */
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jim Schutt

The Ceph messenger would sometimes queue multiple work items to write data to a socket when the socket buffer was full.

Fix this problem by making ceph_write_space() use SOCK_NOSPACE in the same way that net/core/stream.c:sk_stream_write_space() does, i.e., clearing it only when sufficient space is available in the socket buffer.

This looks good to me. You are avoiding queueing more messages if the amount of free space for writing is less than the minimum. And if not, you leave the SOCK_NOSPACE flag alone.

My only general thought on looking at this is that this is using instantaneous space available in a socket send buffer to make a decision on whether to add something to a workqueue, whose work item *may* put something into the send buffer. By the time the work item actually runs, the state of the socket may be very different.

Still, this is an improvement and at this point I am not in a position to suggest anything that would close the gap.

Quoted 37 lines
---
 net/ceph/messenger.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
net/ceph/messenger.c +12 -6
index 67973f0..a4df90b 100644
@@ -175,16 +175,22 @@ static void ceph_write_space(struct sock *sk)
 	struct ceph_connection *con =
 		(struct ceph_connection *)sk->sk_user_data;
 
-	/* only queue to workqueue if there is data we want to write. */
+	/* only queue to workqueue if there is data we want to write,
+	 * and there is sufficient space in the socket buffer to accept
+	 * more data.  clear SOCK_NOSPACE so that ceph_write_space()
+	 * doesn't get called again until try_write() fills the socket
+	 * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
+	 * and net/core/stream.c:sk_stream_write_space().
+	 */
 	if (test_bit(WRITE_PENDING, &con->state)) {
-		dout("ceph_write_space %p queueing write work\n", con);
-		queue_con(con);
+		if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
+			dout("ceph_write_space %p queueing write work\n", con);
+			clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
+			queue_con(con);
+		}
 	} else {
 		dout("ceph_write_space %p nothing to write\n", con);
 	}
-
-	/* since we have our own write_space, clear the SOCK_NOSPACE flag */
-	clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
 }
 
 /* socket's state has changed */
author
#2 lore raw

Hi Alex,

Quoted 23 lines · Alex Elder
Quoted 8 lines · Jim Schutt

The Ceph messenger would sometimes queue multiple work items to write data to a socket when the socket buffer was full.

Fix this problem by making ceph_write_space() use SOCK_NOSPACE in the same way that net/core/stream.c:sk_stream_write_space() does, i.e., clearing it only when sufficient space is available in the socket buffer.

This looks good to me. You are avoiding queueing more messages if the amount of free space for writing is less than the minimum. And if not, you leave the SOCK_NOSPACE flag alone.

My only general thought on looking at this is that this is using instantaneous space available in a socket send buffer to make a decision on whether to add something to a workqueue, whose work item *may* put something into the send buffer. By the time the work item actually runs, the state of the socket may be very different.

Quoted 5 lines

Still, this is an improvement and at this point I am not in a position to suggest anything that would close the gap.

Do you think this is worth sending upstream?

Do I need to to something more, or are you willing to add it to your ceph-client for-review branch?

Thanks -- Jim

Quoted 44 lines
Quoted 39 lines

---
  net/ceph/messenger.c |   18 ++++++++++++------
  1 files changed, 12 insertions(+), 6 deletions(-)
net/ceph/messenger.c +12 -6
index 67973f0..a4df90b 100644
@@ -175,16 +175,22 @@ static void ceph_write_space(struct sock *sk)
  	struct ceph_connection *con =
  		(struct ceph_connection *)sk->sk_user_data;
 
-	/* only queue to workqueue if there is data we want to write. */
+	/* only queue to workqueue if there is data we want to write,
+	 * and there is sufficient space in the socket buffer to accept
+	 * more data.  clear SOCK_NOSPACE so that ceph_write_space()
+	 * doesn't get called again until try_write() fills the socket
+	 * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
+	 * and net/core/stream.c:sk_stream_write_space().
+	 */
  	if (test_bit(WRITE_PENDING,&con->state)) {
-		dout("ceph_write_space %p queueing write work\n", con);
-		queue_con(con);
+		if (sk_stream_wspace(sk)>= sk_stream_min_wspace(sk)) {
+			dout("ceph_write_space %p queueing write work\n", con);
+			clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
+			queue_con(con);
+		}
  	} else {
  		dout("ceph_write_space %p nothing to write\n", con);
  	}
-
-	/* since we have our own write_space, clear the SOCK_NOSPACE flag */
-	clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
  }
 
  /* socket's state has changed */
#3 lore raw
Quoted 31 lines · Jim Schutt

Hi Alex,

Quoted 28 lines · Alex Elder
Quoted 9 lines · Jim Schutt

The Ceph messenger would sometimes queue multiple work items to write data to a socket when the socket buffer was full.

Fix this problem by making ceph_write_space() use SOCK_NOSPACE in the same way that net/core/stream.c:sk_stream_write_space() does, i.e., clearing it only when sufficient space is available in the socket buffer.

This looks good to me. You are avoiding queueing more messages if the amount of free space for writing is less than the minimum. And if not, you leave the SOCK_NOSPACE flag alone.

My only general thought on looking at this is that this is using instantaneous space available in a socket send buffer to make a decision on whether to add something to a workqueue, whose work item *may* put something into the send buffer. By the time the work item actually runs, the state of the socket may be very different.

Still, this is an improvement and at this point I am not in a position to suggest anything that would close the gap.

Quoted 6 lines
Quoted 1 line

Do you think this is worth sending upstream?

Do I need to to something more, or are you willing to add it to your ceph-client for-review branch?

Sorry about that Jim. I forgot to include it.

But it's ready to go. I'm going to be updating the master branch in the next day or two with reviewed patches and will include your patch.

I'll talk to Sage about whether he thinks it should go to Linus later this morning.

Again, sorry I dropped the ball on this.

-Alex

Quoted 52 lines

Thanks -- Jim

Quoted 38 lines
Quoted 38 lines

---
net/ceph/messenger.c | 18 ++++++++++++------

1 files changed, 12 insertions(+), 6 deletions(-)
net/ceph/messenger.c +0 -0
index 67973f0..a4df90b 100644
@@ -175,16 +175,22 @@ static void ceph_write_space(struct sock *sk)

struct ceph_connection *con =
(struct ceph_connection *)sk->sk_user_data;

- /* only queue to workqueue if there is data we want to write. */
+ /* only queue to workqueue if there is data we want to write,
+ * and there is sufficient space in the socket buffer to accept
+ * more data. clear SOCK_NOSPACE so that ceph_write_space()
+ * doesn't get called again until try_write() fills the socket
+ * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
+ * and net/core/stream.c:sk_stream_write_space().
+ */
if (test_bit(WRITE_PENDING,&con->state)) {
- dout("ceph_write_space %p queueing write work\n", con);
- queue_con(con);
+ if (sk_stream_wspace(sk)>= sk_stream_min_wspace(sk)) {
+ dout("ceph_write_space %p queueing write work\n", con);
+ clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
+ queue_con(con);
+ }
} else {
dout("ceph_write_space %p nothing to write\n", con);
}
-
- /* since we have our own write_space, clear the SOCK_NOSPACE flag */
- clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
}

Quoted 6 lines
Quoted 1 line

/* socket's state has changed */

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
Quoted 36 lines · Alex Elder
Quoted 35 lines · Jim Schutt

Hi Alex,

Quoted 24 lines · Alex Elder
Quoted 9 lines · Jim Schutt

The Ceph messenger would sometimes queue multiple work items to write data to a socket when the socket buffer was full.

Fix this problem by making ceph_write_space() use SOCK_NOSPACE in the same way that net/core/stream.c:sk_stream_write_space() does, i.e., clearing it only when sufficient space is available in the socket buffer.

This looks good to me. You are avoiding queueing more messages if the amount of free space for writing is less than the minimum. And if not, you leave the SOCK_NOSPACE flag alone.

My only general thought on looking at this is that this is using instantaneous space available in a socket send buffer to make a decision on whether to add something to a workqueue, whose work item *may* put something into the send buffer. By the time the work item actually runs, the state of the socket may be very different.

Quoted 5 lines

Still, this is an improvement and at this point I am not in a position to suggest anything that would close the gap.

Do you think this is worth sending upstream?

Quoted 8 lines
Quoted 2 lines

Do I need to to something more, or are you willing to add it to your ceph-client for-review branch?

Sorry about that Jim. I forgot to include it.

But it's ready to go. I'm going to be updating the master branch in the next day or two with reviewed patches and will include your patch.

Great, thanks!

Quoted 5 lines

I'll talk to Sage about whether he thinks it should go to Linus later this morning.

Again, sorry I dropped the ball on this.

Really, not a problem.

-- Jim

Quoted 59 lines

-Alex

Quoted 52 lines

Thanks -- Jim

Quoted 38 lines
Quoted 38 lines

---
net/ceph/messenger.c | 18 ++++++++++++------

1 files changed, 12 insertions(+), 6 deletions(-)
net/ceph/messenger.c +0 -0
index 67973f0..a4df90b 100644
@@ -175,16 +175,22 @@ static void ceph_write_space(struct sock *sk)

struct ceph_connection *con =
(struct ceph_connection *)sk->sk_user_data;

- /* only queue to workqueue if there is data we want to write. */
+ /* only queue to workqueue if there is data we want to write,
+ * and there is sufficient space in the socket buffer to accept
+ * more data. clear SOCK_NOSPACE so that ceph_write_space()
+ * doesn't get called again until try_write() fills the socket
+ * buffer. See net/ipv4/tcp_input.c:tcp_check_space()
+ * and net/core/stream.c:sk_stream_write_space().
+ */
if (test_bit(WRITE_PENDING,&con->state)) {
- dout("ceph_write_space %p queueing write work\n", con);
- queue_con(con);
+ if (sk_stream_wspace(sk)>= sk_stream_min_wspace(sk)) {
+ dout("ceph_write_space %p queueing write work\n", con);
+ clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
+ queue_con(con);
+ }
} else {
dout("ceph_write_space %p nothing to write\n", con);
}
-
- /* since we have our own write_space, clear the SOCK_NOSPACE flag */
- clear_bit(SOCK_NOSPACE,&sk->sk_socket->flags);
}

Quoted 6 lines
Quoted 1 line

/* socket's state has changed */

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html