sctp: improve asoc streams management
Subsystems (3)
Xin Long
maintainercover sctp: improve asoc streams management
This patchset changes to define asoc->stream as an object, and also improve some codes to make it more clearly.
Xin Long (2):
sctp: define the member stream as an object instead of pointer in asoc
sctp: merge sctp_stream_new and sctp_stream_init
include/net/sctp/structs.h | 7 ++-- net/sctp/associola.c | 16 ++++---- net/sctp/chunk.c | 4 +- net/sctp/outqueue.c | 10 ++--- net/sctp/proc.c | 4 +- net/sctp/sm_make_chunk.c | 5 ++- net/sctp/sm_statefuns.c | 8 ++-- net/sctp/socket.c | 14 +++---- net/sctp/stream.c | 93 ++++++++++++++++++++-------------------------- net/sctp/ulpqueue.c | 8 ++-- 10 files changed, 78 insertions(+), 91 deletions(-)
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH 1/2 sctp: define the member stream as an object instead of pointer in asoc
As Marcelo's suggestion, stream is a fixed size member of asoc and would not grow with more streams. To avoid an allocation for it, this patch is to define it as an object instead of pointer and update the places using it, also create sctp_stream_update() called in sctp_assoc_update() to migrate the stream info from one stream to another.
--- include/net/sctp/structs.h | 3 +- net/sctp/associola.c | 13 ++++----- net/sctp/chunk.c | 4 +-- net/sctp/outqueue.c | 10 +++---- net/sctp/proc.c | 4 +-- net/sctp/sm_make_chunk.c | 2 +- net/sctp/sm_statefuns.c | 8 +++--- net/sctp/socket.c | 14 +++++----- net/sctp/stream.c | 68 ++++++++++++++++++++++------------------------ net/sctp/ulpqueue.c | 8 +++--- 10 files changed, 65 insertions(+), 69 deletions(-)
include/net/sctp/structs.h +2 -1
@@ -381,6 +381,7 @@ int sctp_stream_new(struct sctp_association *asoc, gfp_t gfp);int sctp_stream_init (struct sctp_association *asoc,gfp_t gfp);void sctp_stream_free (struct sctp_stream *stream);void sctp_stream_clear (struct sctp_stream *stream); +void sctp_stream_update (struct sctp_stream *stream,struct sctp_stream *new);/* What is the current SSN number for this stream? */ #define sctp_ssn_peek (stream, type, sid) \
@@ -1750,7 +1751,7 @@ struct sctp_association {__u32 default_rcv_context;/* Stream arrays */ -struct sctp_stream *stream; +struct sctp_stream stream;/* All outbound chunks go through this structure. */ struct sctp_outq outqueue;
net/sctp/associola.c +5 -8
@@ -291,7 +291,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *areturn asoc; stream_free: -sctp_stream_free (asoc->stream); +sctp_stream_free (&asoc->stream); fail_init:sock_put (asoc->base.sk);sctp_endpoint_put (asoc->ep);
@@ -365,7 +365,7 @@ void sctp_association_free(struct sctp_association *asoc)sctp_tsnmap_free (&asoc->peer.tsn_map);/* Free stream information. */ -sctp_stream_free (asoc->stream); +sctp_stream_free (&asoc->stream);if (asoc->strreset_chunk)sctp_chunk_free (asoc->strreset_chunk);
@@ -1151,7 +1151,7 @@ void sctp_assoc_update(struct sctp_association *asoc,/* Reinitialize SSN for both local streams * and peer's streams. */ -sctp_stream_clear (asoc->stream); +sctp_stream_clear (&asoc->stream);/* Flush the ULP reassembly and ordered queue. * Any data there will now be stale and will
@@ -1177,11 +1177,8 @@ void sctp_assoc_update(struct sctp_association *asoc, asoc->ctsn_ack_point = asoc->next_tsn -1 ; asoc->adv_peer_ack_point = asoc->ctsn_ack_point; -if (sctp_state (asoc,COOKIE_WAIT )) { -sctp_stream_free (asoc->stream); - asoc->stream = new->stream; - new->stream =NULL ; - } +if (sctp_state (asoc,COOKIE_WAIT )) +sctp_stream_update (&asoc->stream, &new->stream);if (!asoc->assoc_id) {/* get a new association id since we don't have one
net/sctp/chunk.c +2 -0
@@ -307,7 +307,7 @@ int sctp_chunk_abandoned(struct sctp_chunk *chunk)if (SCTP_PR_TTL_ENABLED (chunk->sinfo.sinfo_flags) &&time_after (jiffies, chunk->msg->expires_at)) { struct sctp_stream_out *streamout - &chunk->asoc->stream->out[chunk->sinfo.sinfo_stream]; + &chunk->asoc->stream.out[chunk->sinfo.sinfo_stream];if (chunk->sent_count) { chunk->asoc->abandoned_sent[SCTP_PR_INDEX (TTL )]++;
@@ -320,7 +320,7 @@ int sctp_chunk_abandoned(struct sctp_chunk *chunk) }else if (SCTP_PR_RTX_ENABLED (chunk->sinfo.sinfo_flags) && chunk->sent_count > chunk->sinfo.sinfo_timetolive) { struct sctp_stream_out *streamout - &chunk->asoc->stream->out[chunk->sinfo.sinfo_stream]; + &chunk->asoc->stream.out[chunk->sinfo.sinfo_stream]; chunk->asoc->abandoned_sent[SCTP_PR_INDEX (RTX )]++; streamout->abandoned_sent[SCTP_PR_INDEX (RTX )]++;
net/sctp/outqueue.c +5 -4
@@ -363,7 +363,7 @@ static int sctp_prsctp_prune_sent(struct sctp_association *asoc,sctp_insert_list (&asoc->outqueue.abandoned, &chk->transmitted_list); - streamout = &asoc->stream->out[chk->sinfo.sinfo_stream]; + streamout = &asoc->stream.out[chk->sinfo.sinfo_stream]; asoc->sent_cnt_removable--; asoc->abandoned_sent[SCTP_PR_INDEX (PRIO )]++; streamout->abandoned_sent[SCTP_PR_INDEX (PRIO )]++;
@@ -400,9 +400,9 @@ static int sctp_prsctp_prune_unsent(struct sctp_association *asoc, q->out_qlen -= chk->skb->len; asoc->sent_cnt_removable--; asoc->abandoned_unsent[SCTP_PR_INDEX (PRIO )]++; -if (chk->sinfo.sinfo_stream < asoc->stream->outcnt) { +if (chk->sinfo.sinfo_stream < asoc->stream.outcnt) { struct sctp_stream_out *streamout - &asoc->stream->out[chk->sinfo.sinfo_stream]; + &asoc->stream.out[chk->sinfo.sinfo_stream]; streamout->abandoned_unsent[SCTP_PR_INDEX (PRIO )]++; }
@@ -1036,7 +1036,7 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)/* RFC 2960 6.5 Every DATA chunk MUST carry a valid * stream identifier. */ -if (chunk->sinfo.sinfo_stream >= asoc->stream->outcnt) { +if (chunk->sinfo.sinfo_stream >= asoc->stream.outcnt) {/* Mark as failed send. */ sctp_chunk_fail (chunk,SCTP_ERROR_INV_STRM );
@@ -1054,7 +1054,7 @@ static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)continue ; } -if (asoc->stream->out[sid].state =SCTP_STREAM_CLOSED ) { +if (asoc->stream.out[sid].state =SCTP_STREAM_CLOSED ) {sctp_outq_head_data (q, chunk); goto sctp_flush_out; }
net/sctp/proc.c +2 -2
@@ -361,8 +361,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)sctp_seq_dump_remote_addrs (seq, assoc); seq_printf(seq, "\t%8lu %5d %5d %4d %4d %4d %8d " "%8d %8d %8d %8d", - assoc->hbinterval, assoc->stream->incnt, - assoc->stream->outcnt, assoc->max_retrans, + assoc->hbinterval, assoc->stream.incnt, + assoc->stream.outcnt, assoc->max_retrans, assoc->init_retries, assoc->shutdown_retries, assoc->rtx_data_chunks, atomic_read(&sk->sk_wmem_alloc),
net/sctp/sm_make_chunk.c +1 -1
@@ -1544,7 +1544,7 @@ void sctp_chunk_assign_ssn(struct sctp_chunk *chunk)/* All fragments will be on the same stream */ sid =ntohs (chunk->subh.data_hdr->stream); - stream = chunk->asoc->stream; + stream = &chunk->asoc->stream;/* Now assign the sequence number to the entire message. * All fragments must have the same stream sequence number.
net/sctp/sm_statefuns.c +4 -4
@@ -3958,7 +3958,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(struct net *net,/* Silently discard the chunk if stream-id is not valid */ sctp_walk_fwdtsn(skip, chunk) { -if (ntohs (skip->stream) >= asoc->stream->incnt) +if (ntohs (skip->stream) >= asoc->stream.incnt) goto discard_noforce; }
@@ -4029,7 +4029,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(/* Silently discard the chunk if stream-id is not valid */ sctp_walk_fwdtsn(skip, chunk) { -if (ntohs (skip->stream) >= asoc->stream->incnt) +if (ntohs (skip->stream) >= asoc->stream.incnt) goto gen_shutdown; }
@@ -6365,7 +6365,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,* and discard the DATA chunk. */ sid =ntohs (data_hdr->stream); -if (sid >= asoc->stream->incnt) { +if (sid >= asoc->stream.incnt) {/* Mark tsn as received even though we drop it */ sctp_add_cmd_sf (commands,SCTP_CMD_REPORT_TSN ,SCTP_U32 (tsn));
@@ -6387,7 +6387,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,* and is invalid. */ ssn =ntohs (data_hdr->ssn); -if (ordered &&SSN_lt (ssn,sctp_ssn_peek (asoc->stream, in, sid))) +if (ordered &&SSN_lt (ssn,sctp_ssn_peek (&asoc->stream, in, sid)))return SCTP_IERROR_PROTO_VIOLATION ;/* Send the data up to the user. Note: Schedule the
net/sctp/socket.c +7 -7
@@ -1920,7 +1920,7 @@ static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) }/* Check for invalid stream. */ -if (sinfo->sinfo_stream >= asoc->stream->outcnt) { +if (sinfo->sinfo_stream >= asoc->stream.outcnt) { err = -EINVAL ; goto out_free; }
@@ -4497,8 +4497,8 @@ int sctp_get_sctp_info(struct sock *sk, struct sctp_association *asoc, info->sctpi_rwnd = asoc->a_rwnd; info->sctpi_unackdata = asoc->unack_data; info->sctpi_penddata =sctp_tsnmap_pending (&asoc->peer.tsn_map); - info->sctpi_instrms = asoc->stream->incnt; - info->sctpi_outstrms = asoc->stream->outcnt; + info->sctpi_instrms = asoc->stream.incnt; + info->sctpi_outstrms = asoc->stream.outcnt;list_for_each (pos, &asoc->base.inqueue.in_chunk_list) info->sctpi_inqueue++;list_for_each (pos, &asoc->outqueue.out_chunk_list)
@@ -4727,8 +4727,8 @@ static int sctp_getsockopt_sctp_status(struct sock *sk, int len, status.sstat_unackdata = asoc->unack_data; status.sstat_penddata =sctp_tsnmap_pending (&asoc->peer.tsn_map); - status.sstat_instrms = asoc->stream->incnt; - status.sstat_outstrms = asoc->stream->outcnt; + status.sstat_instrms = asoc->stream.incnt; + status.sstat_outstrms = asoc->stream.outcnt; status.sstat_fragmentation_point = asoc->frag_point; status.sstat_primary.spinfo_assoc_id =sctp_assoc2id (transport->asoc); memcpy(&status.sstat_primary.spinfo_address, &transport->ipaddr,
@@ -6600,10 +6600,10 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len, goto out; asoc =sctp_id2assoc (sk, params.sprstat_assoc_id); -if (!asoc || params.sprstat_sid >= asoc->stream->outcnt) +if (!asoc || params.sprstat_sid >= asoc->stream.outcnt) goto out; - streamout = &asoc->stream->out[params.sprstat_sid]; + streamout = &asoc->stream.out[params.sprstat_sid];if (policy =SCTP_PR_SCTP_NONE ) { params.sprstat_abandoned_unsent =0 ; params.sprstat_abandoned_sent =0 ;
net/sctp/stream.c +33 -35
181 lines not on this page · raw message
net/sctp/ulpqueue.c +4 -4
@@ -764,7 +764,7 @@ static void sctp_ulpq_retrieve_ordered(struct sctp_ulpq *ulpq,__u16 sid, csid, cssn; sid = event->stream; - stream = ulpq->asoc->stream; + stream = &ulpq->asoc->stream; event_list = (struct sk_buff_head *)sctp_event2skb (event)->prev;
@@ -858,7 +858,7 @@ static struct sctp_ulpevent *sctp_ulpq_order(struct sctp_ulpq *ulpq,/* Note: The stream ID must be verified before this routine. */ sid = event->stream; ssn = event->ssn; - stream = ulpq->asoc->stream; + stream = &ulpq->asoc->stream;/* Is this the expected SSN for this stream ID? */ if (ssn !=sctp_ssn_peek (stream, in, sid)) {
@@ -893,7 +893,7 @@ static void sctp_ulpq_reap_ordered(struct sctp_ulpq *ulpq, __u16 sid)struct sk_buff_head *lobby = &ulpq->lobby;__u16 csid, cssn; - stream = ulpq->asoc->stream; + stream = &ulpq->asoc->stream;/* We are holding the chunks by stream, by SSN. */ skb_queue_head_init (&temp);
@@ -958,7 +958,7 @@ void sctp_ulpq_skip(struct sctp_ulpq *ulpq, __u16 sid, __u16 ssn)struct sctp_stream *stream;/* Note: The stream ID must be verified before this routine. */ - stream = ulpq->asoc->stream; + stream = &ulpq->asoc->stream;/* Is this an old SSN? If so ignore. */ if (SSN_lt (ssn,sctp_ssn_peek (stream, in, sid)))
Signature · 1 line
2.1.0
Xin Long
maintainerPATCH 2/2 sctp: merge sctp_stream_new and sctp_stream_init
Since last patch, sctp doesn't need to alloc memory for asoc->stream any more. sctp_stream_new and sctp_stream_init both are used to alloc memory for stream.in or stream.out, and their names are also confusing.
This patch is to merge them into sctp_stream_init, and only pass stream and streamcnt parameters into it, instead of the whole asoc.
--- include/net/sctp/structs.h | 4 ++-- net/sctp/associola.c | 3 ++- net/sctp/sm_make_chunk.c | 3 ++- net/sctp/stream.c | 33 +++++++++++---------------------- 4 files changed, 17 insertions(+), 26 deletions(-)
include/net/sctp/structs.h +2 -2
@@ -377,8 +377,8 @@ typedef struct sctp_sender_hb_info {__u64 hb_nonce; } sctp_sender_hb_info_t; -int sctp_stream_new (struct sctp_association *asoc,gfp_t gfp); -int sctp_stream_init (struct sctp_association *asoc,gfp_t gfp); +int sctp_stream_init (struct sctp_stream *stream,__u16 outcnt,__u16 incnt, +gfp_t gfp);void sctp_stream_free (struct sctp_stream *stream);void sctp_stream_clear (struct sctp_stream *stream);void sctp_stream_update (struct sctp_stream *stream,struct sctp_stream *new);
net/sctp/associola.c +2 -1
@@ -246,7 +246,8 @@ static struct sctp_association *sctp_association_init(struct sctp_association *aif (!sctp_ulpq_init (&asoc->ulpq, asoc)) goto fail_init; -if (sctp_stream_new (asoc, gfp)) +if (sctp_stream_init (&asoc->stream, asoc->c.sinit_num_ostreams, +0 , gfp)) goto fail_init;/* Assume that peer would support both address types unless we are
net/sctp/sm_make_chunk.c +2 -1
@@ -2454,7 +2454,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,* stream sequence number shall be set to 0. */ -if (sctp_stream_init (asoc, gfp)) +if (sctp_stream_init (&asoc->stream, asoc->c.sinit_num_ostreams, + asoc->c.sinit_max_instreams, gfp)) goto clean_up;if (!asoc->temp &&sctp_assoc_set_id (asoc, gfp))
net/sctp/stream.c +11 -22
@@ -35,47 +35,36 @@#include <net/sctp/sctp.h> #include <net/sctp/sm.h> -int sctp_stream_new (struct sctp_association *asoc,gfp_t gfp) +int sctp_stream_init (struct sctp_stream *stream,__u16 outcnt,__u16 incnt, +gfp_t gfp) { -struct sctp_stream *stream = &asoc->stream; -int i; - - stream->outcnt = asoc->c.sinit_num_ostreams; - stream->out =kcalloc (stream->outcnt,sizeof (*stream->out), gfp); -if (!stream->out) -return -ENOMEM ; - -for (i =0 ; i < stream->outcnt; i++) - stream->out[i].state =SCTP_STREAM_OPEN ; - -return 0 ; -} - -int sctp_stream_init (struct sctp_association *asoc,gfp_t gfp) -{ -struct sctp_stream *stream = &asoc->stream;int i;/* Initial stream->out size may be very big, so free it and alloc * a new one with new outcnt to save memory. */ kfree (stream->out); - stream->outcnt = asoc->c.sinit_num_ostreams; - stream->out =kcalloc (stream->outcnt,sizeof (*stream->out), gfp); + + stream->out =kcalloc (outcnt,sizeof (*stream->out), gfp);if (!stream->out)return -ENOMEM ; + stream->outcnt = outcnt;for (i =0 ; i < stream->outcnt; i++) stream->out[i].state =SCTP_STREAM_OPEN ; - stream->incnt = asoc->c.sinit_max_instreams; - stream->in =kcalloc (stream->incnt,sizeof (*stream->in), gfp); +if (!incnt) +return 0 ; + + stream->in =kcalloc (incnt,sizeof (*stream->in), gfp);if (!stream->in) {kfree (stream->out); stream->out =NULL ;return -ENOMEM ; } + stream->incnt = incnt; +return 0 ; }
Signature · 1 line
2.1.0
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Wed, 31 May 2017 16:36:30 +0800
Quoted 2 lines
This patchset changes to define
asoc->streamas an object, and also improve some codes to make it more clearly.
Series applied, thank you.