All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vlad Yasevich <vyasevich@gmail.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	linux-sctp@vger.kernel.org
Subject: Re: [PATCH] sctp: refactor sctp_packet_append_chunk and clenup some memory leaks
Date: Tue, 03 Jul 2012 14:39:36 +0000	[thread overview]
Message-ID: <4FF30428.6070403@gmail.com> (raw)
In-Reply-To: <1341259164-7396-1-git-send-email-nhorman@tuxdriver.com>

On 07/02/2012 03:59 PM, Neil Horman wrote:
> While doing some recent work on sctp sack bundling I noted that
> sctp_packet_append_chunk was pretty inefficient.  Specifially, it was called
> recursively while trying to bundle auth and sack chunks.  Because of that we
> call sctp_packet_bundle_sack and sctp_packet_bundle_auth a total of 4 times for
> every call to sctp_packet_append_chunk, knowing that at least 3 of those calls
> will do nothing.
>
> So lets refactor sctp_packet_bundle_auth to have an outer part that does the
> attempted bundling, and an inner part that just does the chunk appends.  This
> saves us several calls per iteration that we just don't need.
>
> Also, noticed that the auth and sack bundling fail to free the chunks they
> allocate if the append fails, so make sure we add that in
>
> Signed-off-by: Neil Horman<nhorman@tuxdriver.com>
> CC: Vlad Yasevich<vyasevich@gmail.com>

Acked-by: Vlad Yasevich <vyasevich@gmail.com>

-vlad

> CC: "David S. Miller"<davem@davemloft.net>
> CC: linux-sctp@vger.kernel.org
> ---
>   net/sctp/output.c |   80 +++++++++++++++++++++++++++++++++++------------------
>   1 files changed, 53 insertions(+), 27 deletions(-)
>
> diff --git a/net/sctp/output.c b/net/sctp/output.c
> index 0de6cd5..0b62f6c 100644
> --- a/net/sctp/output.c
> +++ b/net/sctp/output.c
> @@ -64,6 +64,8 @@
>   #include<net/sctp/checksum.h>
>
>   /* Forward declarations for private helpers. */
> +static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
> +					      struct sctp_chunk *chunk);
>   static sctp_xmit_t sctp_packet_can_append_data(struct sctp_packet *packet,
>   					   struct sctp_chunk *chunk);
>   static void sctp_packet_append_data(struct sctp_packet *packet,
> @@ -224,7 +226,10 @@ static sctp_xmit_t sctp_packet_bundle_auth(struct sctp_packet *pkt,
>   	if (!auth)
>   		return retval;
>
> -	retval = sctp_packet_append_chunk(pkt, auth);
> +	retval = __sctp_packet_append_chunk(pkt, auth);
> +
> +	if (retval != SCTP_XMIT_OK)
> +		sctp_chunk_free(auth);
>
>   	return retval;
>   }
> @@ -256,48 +261,31 @@ static sctp_xmit_t sctp_packet_bundle_sack(struct sctp_packet *pkt,
>   			asoc->a_rwnd = asoc->rwnd;
>   			sack = sctp_make_sack(asoc);
>   			if (sack) {
> -				retval = sctp_packet_append_chunk(pkt, sack);
> +				retval = __sctp_packet_append_chunk(pkt, sack);
> +				if (retval != SCTP_XMIT_OK) {
> +					sctp_chunk_free(sack);
> +					goto out;
> +				}
>   				asoc->peer.sack_needed = 0;
>   				if (del_timer(timer))
>   					sctp_association_put(asoc);
>   			}
>   		}
>   	}
> +out:
>   	return retval;
>   }
>
> +
>   /* Append a chunk to the offered packet reporting back any inability to do
>    * so.
>    */
> -sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
> -				     struct sctp_chunk *chunk)
> +static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
> +					      struct sctp_chunk *chunk)
>   {
>   	sctp_xmit_t retval = SCTP_XMIT_OK;
>   	__u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
>
> -	SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __func__, packet,
> -			  chunk);
> -
> -	/* Data chunks are special.  Before seeing what else we can
> -	 * bundle into this packet, check to see if we are allowed to
> -	 * send this DATA.
> -	 */
> -	if (sctp_chunk_is_data(chunk)) {
> -		retval = sctp_packet_can_append_data(packet, chunk);
> -		if (retval != SCTP_XMIT_OK)
> -			goto finish;
> -	}
> -
> -	/* Try to bundle AUTH chunk */
> -	retval = sctp_packet_bundle_auth(packet, chunk);
> -	if (retval != SCTP_XMIT_OK)
> -		goto finish;
> -
> -	/* Try to bundle SACK chunk */
> -	retval = sctp_packet_bundle_sack(packet, chunk);
> -	if (retval != SCTP_XMIT_OK)
> -		goto finish;
> -
>   	/* Check to see if this chunk will fit into the packet */
>   	retval = sctp_packet_will_fit(packet, chunk, chunk_len);
>   	if (retval != SCTP_XMIT_OK)
> @@ -339,6 +327,44 @@ finish:
>   	return retval;
>   }
>
> +/* Append a chunk to the offered packet reporting back any inability to do
> + * so.
> + */
> +sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
> +				     struct sctp_chunk *chunk)
> +{
> +	sctp_xmit_t retval = SCTP_XMIT_OK;
> +	__u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
> +
> +	SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __func__, packet,
> +			  chunk);
> +
> +	/* Data chunks are special.  Before seeing what else we can
> +	 * bundle into this packet, check to see if we are allowed to
> +	 * send this DATA.
> +	 */
> +	if (sctp_chunk_is_data(chunk)) {
> +		retval = sctp_packet_can_append_data(packet, chunk);
> +		if (retval != SCTP_XMIT_OK)
> +			goto finish;
> +	}
> +
> +	/* Try to bundle AUTH chunk */
> +	retval = sctp_packet_bundle_auth(packet, chunk);
> +	if (retval != SCTP_XMIT_OK)
> +		goto finish;
> +
> +	/* Try to bundle SACK chunk */
> +	retval = sctp_packet_bundle_sack(packet, chunk);
> +	if (retval != SCTP_XMIT_OK)
> +		goto finish;
> +
> +	retval = __sctp_packet_append_chunk(packet, chunk);
> +
> +finish:
> +	return retval;
> +}
> +
>   /* All packets are sent to the network through this function from
>    * sctp_outq_tail().
>    *


WARNING: multiple messages have this Message-ID (diff)
From: Vlad Yasevich <vyasevich@gmail.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	linux-sctp@vger.kernel.org
Subject: Re: [PATCH] sctp: refactor sctp_packet_append_chunk and clenup some memory leaks
Date: Tue, 03 Jul 2012 10:39:36 -0400	[thread overview]
Message-ID: <4FF30428.6070403@gmail.com> (raw)
In-Reply-To: <1341259164-7396-1-git-send-email-nhorman@tuxdriver.com>

On 07/02/2012 03:59 PM, Neil Horman wrote:
> While doing some recent work on sctp sack bundling I noted that
> sctp_packet_append_chunk was pretty inefficient.  Specifially, it was called
> recursively while trying to bundle auth and sack chunks.  Because of that we
> call sctp_packet_bundle_sack and sctp_packet_bundle_auth a total of 4 times for
> every call to sctp_packet_append_chunk, knowing that at least 3 of those calls
> will do nothing.
>
> So lets refactor sctp_packet_bundle_auth to have an outer part that does the
> attempted bundling, and an inner part that just does the chunk appends.  This
> saves us several calls per iteration that we just don't need.
>
> Also, noticed that the auth and sack bundling fail to free the chunks they
> allocate if the append fails, so make sure we add that in
>
> Signed-off-by: Neil Horman<nhorman@tuxdriver.com>
> CC: Vlad Yasevich<vyasevich@gmail.com>

Acked-by: Vlad Yasevich <vyasevich@gmail.com>

-vlad

> CC: "David S. Miller"<davem@davemloft.net>
> CC: linux-sctp@vger.kernel.org
> ---
>   net/sctp/output.c |   80 +++++++++++++++++++++++++++++++++++------------------
>   1 files changed, 53 insertions(+), 27 deletions(-)
>
> diff --git a/net/sctp/output.c b/net/sctp/output.c
> index 0de6cd5..0b62f6c 100644
> --- a/net/sctp/output.c
> +++ b/net/sctp/output.c
> @@ -64,6 +64,8 @@
>   #include<net/sctp/checksum.h>
>
>   /* Forward declarations for private helpers. */
> +static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
> +					      struct sctp_chunk *chunk);
>   static sctp_xmit_t sctp_packet_can_append_data(struct sctp_packet *packet,
>   					   struct sctp_chunk *chunk);
>   static void sctp_packet_append_data(struct sctp_packet *packet,
> @@ -224,7 +226,10 @@ static sctp_xmit_t sctp_packet_bundle_auth(struct sctp_packet *pkt,
>   	if (!auth)
>   		return retval;
>
> -	retval = sctp_packet_append_chunk(pkt, auth);
> +	retval = __sctp_packet_append_chunk(pkt, auth);
> +
> +	if (retval != SCTP_XMIT_OK)
> +		sctp_chunk_free(auth);
>
>   	return retval;
>   }
> @@ -256,48 +261,31 @@ static sctp_xmit_t sctp_packet_bundle_sack(struct sctp_packet *pkt,
>   			asoc->a_rwnd = asoc->rwnd;
>   			sack = sctp_make_sack(asoc);
>   			if (sack) {
> -				retval = sctp_packet_append_chunk(pkt, sack);
> +				retval = __sctp_packet_append_chunk(pkt, sack);
> +				if (retval != SCTP_XMIT_OK) {
> +					sctp_chunk_free(sack);
> +					goto out;
> +				}
>   				asoc->peer.sack_needed = 0;
>   				if (del_timer(timer))
>   					sctp_association_put(asoc);
>   			}
>   		}
>   	}
> +out:
>   	return retval;
>   }
>
> +
>   /* Append a chunk to the offered packet reporting back any inability to do
>    * so.
>    */
> -sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
> -				     struct sctp_chunk *chunk)
> +static sctp_xmit_t __sctp_packet_append_chunk(struct sctp_packet *packet,
> +					      struct sctp_chunk *chunk)
>   {
>   	sctp_xmit_t retval = SCTP_XMIT_OK;
>   	__u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
>
> -	SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __func__, packet,
> -			  chunk);
> -
> -	/* Data chunks are special.  Before seeing what else we can
> -	 * bundle into this packet, check to see if we are allowed to
> -	 * send this DATA.
> -	 */
> -	if (sctp_chunk_is_data(chunk)) {
> -		retval = sctp_packet_can_append_data(packet, chunk);
> -		if (retval != SCTP_XMIT_OK)
> -			goto finish;
> -	}
> -
> -	/* Try to bundle AUTH chunk */
> -	retval = sctp_packet_bundle_auth(packet, chunk);
> -	if (retval != SCTP_XMIT_OK)
> -		goto finish;
> -
> -	/* Try to bundle SACK chunk */
> -	retval = sctp_packet_bundle_sack(packet, chunk);
> -	if (retval != SCTP_XMIT_OK)
> -		goto finish;
> -
>   	/* Check to see if this chunk will fit into the packet */
>   	retval = sctp_packet_will_fit(packet, chunk, chunk_len);
>   	if (retval != SCTP_XMIT_OK)
> @@ -339,6 +327,44 @@ finish:
>   	return retval;
>   }
>
> +/* Append a chunk to the offered packet reporting back any inability to do
> + * so.
> + */
> +sctp_xmit_t sctp_packet_append_chunk(struct sctp_packet *packet,
> +				     struct sctp_chunk *chunk)
> +{
> +	sctp_xmit_t retval = SCTP_XMIT_OK;
> +	__u16 chunk_len = WORD_ROUND(ntohs(chunk->chunk_hdr->length));
> +
> +	SCTP_DEBUG_PRINTK("%s: packet:%p chunk:%p\n", __func__, packet,
> +			  chunk);
> +
> +	/* Data chunks are special.  Before seeing what else we can
> +	 * bundle into this packet, check to see if we are allowed to
> +	 * send this DATA.
> +	 */
> +	if (sctp_chunk_is_data(chunk)) {
> +		retval = sctp_packet_can_append_data(packet, chunk);
> +		if (retval != SCTP_XMIT_OK)
> +			goto finish;
> +	}
> +
> +	/* Try to bundle AUTH chunk */
> +	retval = sctp_packet_bundle_auth(packet, chunk);
> +	if (retval != SCTP_XMIT_OK)
> +		goto finish;
> +
> +	/* Try to bundle SACK chunk */
> +	retval = sctp_packet_bundle_sack(packet, chunk);
> +	if (retval != SCTP_XMIT_OK)
> +		goto finish;
> +
> +	retval = __sctp_packet_append_chunk(packet, chunk);
> +
> +finish:
> +	return retval;
> +}
> +
>   /* All packets are sent to the network through this function from
>    * sctp_outq_tail().
>    *

  reply	other threads:[~2012-07-03 14:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-02 19:59 [PATCH] sctp: refactor sctp_packet_append_chunk and clenup some memory leaks Neil Horman
2012-07-02 19:59 ` Neil Horman
2012-07-03 14:39 ` Vlad Yasevich [this message]
2012-07-03 14:39   ` Vlad Yasevich
2012-07-09  6:54   ` David Miller
2012-07-09  6:54     ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FF30428.6070403@gmail.com \
    --to=vyasevich@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.