Skip to contentSkip to conversation

sctp: delay calls to sk_data_ready() as much as possible

PATCH Superseded Marcelo Ricardo Leitner 4 participants 8 messages Apr 6, 2016 – Apr 7, 2016

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marcelo Ricardo Leitner

author maintainer
#0 lore raw

v2 cover sctp: delay calls to sk_data_ready() as much as possible

1st patch is a preparation for the 2nd. The idea is to not call ->sk_data_ready() for every data chunk processed while processing packets but only once before releasing the socket.

v2: patchset re-checked, small changelog fixes

Marcelo Ricardo Leitner (2):
sctp: compress bit-wide flags to a bitfield on sctp_sock
sctp: delay calls to sk_data_ready() as much as possible

 include/net/sctp/structs.h | 13 +++++++------
 net/sctp/sm_sideeffect.c   |  5 +++++
 net/sctp/ulpqueue.c        |  4 ++--
 3 files changed, 14 insertions(+), 8 deletions(-)
Signature · 1 line
2.5.0
author maintainer
#1 lore raw

PATCH v2 1/2 sctp: compress bit-wide flags to a bitfield on sctp_sock

It wastes space and gets worse as we add new flags, so convert bit-wide flags to a bitfield.

Currently it already saves 4 bytes in sctp_sock, which are left as holes in it for now. The whole struct needs packing, which should be done in another patch.

Note that do_auto_asconf cannot be merged, as explained in the comment before it.

---
 include/net/sctp/structs.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
include/net/sctp/structs.h +6 -6
index 6df1ce7a411c548bda4163840a90578b6e1b4cfe..1a6a626904bba4223b7921bbb4be41c2550271a7 100644
@@ -210,14 +210,14 @@ struct sctp_sock {
 	int user_frag;
 
 	__u32 autoclose;
-	__u8 nodelay;
-	__u8 disable_fragments;
-	__u8 v4mapped;
-	__u8 frag_interleave;
 	__u32 adaptation_ind;
 	__u32 pd_point;
-	__u8 recvrcvinfo;
-	__u8 recvnxtinfo;
+	__u16	nodelay:1,
+		disable_fragments:1,
+		v4mapped:1,
+		frag_interleave:1,
+		recvrcvinfo:1,
+		recvnxtinfo:1;
 
 	atomic_t pd_mode;
 	/* Receive to here while partial delivery is in effect. */
Signature · 1 line
2.5.0
#2 lore raw

Re: [PATCH v2 1/2] sctp: compress bit-wide flags to a bitfield on sctp_sock

Quoted 7 lines · Marcelo Ricardo Leitner

It wastes space and gets worse as we add new flags, so convert bit-wide flags to a bitfield.

Currently it already saves 4 bytes in sctp_sock, which are left as holes in it for now. The whole struct needs packing, which should be done in another patch.

Quoted 5 lines

Note that do_auto_asconf cannot be merged, as explained in the comment before it.

---

[]

include/net/sctp/structs.h

Quoted 1 line
include/net/sctp/structs.h +0 -0

[]

Quoted 10 lines
include/net/sctp/structs.h +0 -0
@@ -210,14 +210,14 @@ struct sctp_sock {
  	int user_frag;


  __u32 autoclose;

include/net/sctp/structs.h +0 -4
-	__u8 nodelay;
-	__u8 disable_fragments;
-	__u8 v4mapped;
-	__u8 frag_interleave;

  __u32 adaptation_ind;
  __u32 pd_point;

include/net/sctp/structs.h struct sctp_sock { · line 220

Quoted 8 lines
include/net/sctp/structs.h +6 -2
-	__u8 recvrcvinfo;
-	__u8 recvnxtinfo;
+	__u16	nodelay:1,
+		disable_fragments:1,
+		v4mapped:1,
+		frag_interleave:1,
+		recvrcvinfo:1,
+		recvnxtinfo:1;

Might as well make this __u32 as the next field would be aligned on an atomic_t

It might be better if these fields didn't use the __ prefix.

maintainer
#3 lore raw

Re: [PATCH v2 1/2] sctp: compress bit-wide flags to a bitfield on sctp_sock

From: Joe Perches <[email protected]>
Date: Wed, 06 Apr 2016 12:53:24 -0700

Quoted 38 lines · Marcelo Ricardo Leitner
Quoted 7 lines

It wastes space and gets worse as we add new flags, so convert bit-wide flags to a bitfield.

Currently it already saves 4 bytes in sctp_sock, which are left as holes in it for now. The whole struct needs packing, which should be done in another patch.

Quoted 5 lines

Note that do_auto_asconf cannot be merged, as explained in the comment before it.

---

[]

include/net/sctp/structs.h

Quoted 1 line
include/net/sctp/structs.h +0 -0

[]

Quoted 10 lines
include/net/sctp/structs.h +0 -0
@@ -210,14 +210,14 @@ struct sctp_sock {
  	int user_frag;


  __u32 autoclose;

include/net/sctp/structs.h +0 -4
-	__u8 nodelay;
-	__u8 disable_fragments;
-	__u8 v4mapped;
-	__u8 frag_interleave;

  __u32 adaptation_ind;
  __u32 pd_point;

include/net/sctp/structs.h struct sctp_sock { · line 220

Quoted 8 lines
include/net/sctp/structs.h +6 -2
-	__u8 recvrcvinfo;
-	__u8 recvnxtinfo;
+	__u16	nodelay:1,
+		disable_fragments:1,
+		v4mapped:1,
+		frag_interleave:1,
+		recvrcvinfo:1,
+		recvnxtinfo:1;

Might as well make this __u32 as the next field would be aligned on an atomic_t

Quoted 1 line

It might be better if these fields didn't use the __ prefix.

Indeed, this isn't in a UAPI file so __ prefixed types really aren't appropriate.

author maintainer
#4 lore raw

Re: [PATCH v2 1/2] sctp: compress bit-wide flags to a bitfield on sctp_sock

Quoted 40 lines · David Miller

From: Joe Perches <[email protected]>
Date: Wed, 06 Apr 2016 12:53:24 -0700

Quoted 37 lines · Marcelo Ricardo Leitner
Quoted 7 lines

It wastes space and gets worse as we add new flags, so convert bit-wide flags to a bitfield.

Currently it already saves 4 bytes in sctp_sock, which are left as holes in it for now. The whole struct needs packing, which should be done in another patch.

Quoted 5 lines

Note that do_auto_asconf cannot be merged, as explained in the comment before it.

---

[]

include/net/sctp/structs.h

Quoted 1 line
include/net/sctp/structs.h +0 -0

[]

Quoted 10 lines
include/net/sctp/structs.h +0 -0
@@ -210,14 +210,14 @@ struct sctp_sock {
  	int user_frag;


  __u32 autoclose;

include/net/sctp/structs.h +0 -4
-	__u8 nodelay;
-	__u8 disable_fragments;
-	__u8 v4mapped;
-	__u8 frag_interleave;

  __u32 adaptation_ind;
  __u32 pd_point;

include/net/sctp/structs.h struct sctp_sock { · line 220

Quoted 8 lines
include/net/sctp/structs.h +6 -2
-	__u8 recvrcvinfo;
-	__u8 recvnxtinfo;
+	__u16	nodelay:1,
+		disable_fragments:1,
+		v4mapped:1,
+		frag_interleave:1,
+		recvrcvinfo:1,
+		recvnxtinfo:1;

Might as well make this __u32 as the next field would be aligned on an atomic_t

On changelog I meant that this (re-)ordering will happen in another patch. The hole is already there today and there are others to be considered/fixed too. Please consider this patch as a preparation for the other one.

After this patch, pahole gives for this struct:

        /* size: 1272, cachelines: 20, members: 40 */
        /* sum members: 1250, holes: 7, sum holes: 18 */
        /* bit holes: 1, sum bit holes: 9 bits */
        /* padding: 4 */
        /* paddings: 1, sum paddings: 2 */
        /* last cacheline: 56 bytes */

Quite some work todo :-)

Quoted 4 lines
Quoted 1 line

It might be better if these fields didn't use the __ prefix.

Indeed, this isn't in a UAPI file so __ prefixed types really aren't appropriate.

The whole file is using __ prefixed types. I can remove them in another patch instead if that's okay with you.
It's also present in other files not under UAPI:

$ git grep -wl '\(__u32\|__u16\)' include/net/sctp/
include/net/sctp/auth.h
include/net/sctp/checksum.h
include/net/sctp/command.h
include/net/sctp/constants.h
include/net/sctp/sctp.h
include/net/sctp/sm.h
include/net/sctp/structs.h
include/net/sctp/tsnmap.h
include/net/sctp/ulpevent.h
include/net/sctp/ulpqueue.h

We can start changing it progressively but I think it would be better if we replace them all at once.

Marcelo

author maintainer
#5 lore raw

PATCH v2 2/2 sctp: delay calls to sk_data_ready() as much as possible

In reply to Marcelo Ricardo Leitner

Currently, the processing of multiple chunks in a single SCTP packet leads to multiple calls to sk_data_ready, causing multiple wake up signals which are costly and doesn't make it wake up any faster.

With this patch it will notice that the wake up is pending and will do it before leaving the state machine interpreter, latest place possible to do it realiably and cleanly.

Note that sk_data_ready events are not dependent on asocs, unlike waking up writers.

---
 include/net/sctp/structs.h | 3 ++-
 net/sctp/sm_sideeffect.c   | 5 +++++
 net/sctp/ulpqueue.c        | 4 ++--
 3 files changed, 9 insertions(+), 3 deletions(-)
include/net/sctp/structs.h +2 -1
index 1a6a626904bba4223b7921bbb4be41c2550271a7..21cb11107e378b4da1e7efde22fab4349496e35a 100644
@@ -217,7 +217,8 @@ struct sctp_sock {
 		v4mapped:1,
 		frag_interleave:1,
 		recvrcvinfo:1,
-		recvnxtinfo:1;
+		recvnxtinfo:1,
+		pending_data_ready:1;
 
 	atomic_t pd_mode;
 	/* Receive to here while partial delivery is in effect. */
net/sctp/sm_sideeffect.c +5 -0
index 7fe56d0acabf66cfd8fe29dfdb45f7620b470ac7..e7042f9ce63b0cfca50cae252f51b60b68cb5731 100644
@@ -1742,6 +1742,11 @@ out:
 			error = sctp_outq_uncork(&asoc->outqueue, gfp);
 	} else if (local_cork)
 		error = sctp_outq_uncork(&asoc->outqueue, gfp);
+
+	if (sctp_sk(ep->base.sk)->pending_data_ready) {
+		ep->base.sk->sk_data_ready(ep->base.sk);
+		sctp_sk(ep->base.sk)->pending_data_ready = 0;
+	}
 	return error;
 nomem:
 	error = -ENOMEM;
net/sctp/ulpqueue.c +2 -2
index ce469d648ffbe166f9ae1c5650f481256f31a7f8..72e5b3e41cddf9d79371de8ab01484e4601b97b6 100644
@@ -264,7 +264,7 @@ int sctp_ulpq_tail_event(struct sctp_ulpq *ulpq, struct sctp_ulpevent *event)
 		sctp_ulpq_clear_pd(ulpq);
 
 	if (queue = &sk->sk_receive_queue)
-		sk->sk_data_ready(sk);
+		sctp_sk(sk)->pending_data_ready = 1;
 	return 1;
 
 out_free:
@@ -1140,5 +1140,5 @@ void sctp_ulpq_abort_pd(struct sctp_ulpq *ulpq, gfp_t gfp)
 
 	/* If there is data waiting, send it up the socket now. */
 	if (sctp_ulpq_clear_pd(ulpq) || ev)
-		sk->sk_data_ready(sk);
+		sctp_sk(sk)->pending_data_ready = 1;
 }
Signature · 1 line
2.5.0
#6 lore raw
Quoted 13 lines · Marcelo Ricardo Leitner

Currently, the processing of multiple chunks in a single SCTP packet leads to multiple calls to sk_data_ready, causing multiple wake up signals which are costly and doesn't make it wake up any faster.

With this patch it will notice that the wake up is pending and will do it before leaving the state machine interpreter, latest place possible to do it realiably and cleanly.

Note that sk_data_ready events are not dependent on asocs, unlike waking up writers.

---

[...]

Quoted 6 lines
net/sctp/sm_sideeffect.c +0 -0
index 7fe56d0acabf66cfd8fe29dfdb45f7620b470ac7..e7042f9ce63b0cfca50cae252f51b60b68cb5731 100644
@@ -1742,6 +1742,11 @@ out:
 			error = sctp_outq_uncork(&asoc->outqueue, gfp);

net/sctp/sm_sideeffect.c out: · line 1752

Quoted 10 lines
net/sctp/sm_sideeffect.c +5 -0
 	} else if (local_cork)
 		error = sctp_outq_uncork(&asoc->outqueue, gfp);
+
+	if (sctp_sk(ep->base.sk)->pending_data_ready) {
+		ep->base.sk->sk_data_ready(ep->base.sk);
+		sctp_sk(ep->base.sk)->pending_data_ready = 0;
+	}
 	return error;
 nomem:
 	error = -ENOMEM;

Would it make sense to introduce a local variable for ep->base.sk (and make this function 535+1 lines long ;-)

      struct sock *sk = ep->base.sk;

... like sctp_ulpq_tail_event() does?

Thanks,
Jakub

author maintainer
#7 lore raw
Quoted 37 lines · Jakub Sitnicki
Quoted 13 lines · Marcelo Ricardo Leitner

Currently, the processing of multiple chunks in a single SCTP packet leads to multiple calls to sk_data_ready, causing multiple wake up signals which are costly and doesn't make it wake up any faster.

With this patch it will notice that the wake up is pending and will do it before leaving the state machine interpreter, latest place possible to do it realiably and cleanly.

Note that sk_data_ready events are not dependent on asocs, unlike waking up writers.

---

[...]

Quoted 6 lines
net/sctp/sm_sideeffect.c +0 -0
index 7fe56d0acabf66cfd8fe29dfdb45f7620b470ac7..e7042f9ce63b0cfca50cae252f51b60b68cb5731 100644
@@ -1742,6 +1742,11 @@ out:
 			error = sctp_outq_uncork(&asoc->outqueue, gfp);

net/sctp/sm_sideeffect.c out: · line 1752

Quoted 10 lines
net/sctp/sm_sideeffect.c +5 -0
 	} else if (local_cork)
 		error = sctp_outq_uncork(&asoc->outqueue, gfp);
+
+	if (sctp_sk(ep->base.sk)->pending_data_ready) {
+		ep->base.sk->sk_data_ready(ep->base.sk);
+		sctp_sk(ep->base.sk)->pending_data_ready = 0;
+	}
 	return error;
 nomem:
 	error = -ENOMEM;

Would it make sense to introduce a local variable for ep->base.sk (and make this function 535+1 lines long ;-)

Quoted 3 lines
      struct sock *sk = ep->base.sk;

... like sctp_ulpq_tail_event() does?

I guess so, yes. Same for sctp_sk() cast then. I´ll post a new version later, thanks.

Marcelo