Netdev List
 help / color / mirror / Atom feed
From: Gerrit Renker <gerrit@erg.abdn.ac.uk>
To: acme@redhat.com
Cc: dccp@vger.kernel.org, netdev@vger.kernel.org,
	Gerrit Renker <gerrit@erg.abdn.ac.uk>
Subject: [PATCH 05/14] [ACKVEC]: Smaller allocation/deallocation routines
Date: Wed, 19 Dec 2007 14:25:46 +0000	[thread overview]
Message-ID: <1198074355-18842-6-git-send-email-gerrit@erg.abdn.ac.uk> (raw)
In-Reply-To: <1198074355-18842-5-git-send-email-gerrit@erg.abdn.ac.uk>

This patch removes redundant bits, implementing the same functionality with less code.

The details are:
  * The INIT_LIST_HEAD in dccp_ackvec_record_new was redundant, since the list pointers
    were later overwritten when the node was added via list_add().

  * dccp_ackvec_record_new() was called only in one instance in the entire ackvec code.

  * The calls to list_del_init() before calling dccp_ackvec_record_delete() were redundant,
    since subsequently the entire element was freed anyway.

  * Similarly, since all calls to dccp_ackvec_record_delete() were preceded to a call to
    list_del_init(), the WARN_ON test would never evaluate to true.

  * Also, since all calls to dccp_ackvec_record_delete() were made from within list_for
    each_entry_safe(), the test for avr == NULL was redundant.

  * The list_empty() test in ackvec_free was redundant, since the same condition is
    embedded in the loop condition of the subsequent list_for_each_entry_safe().

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
---
 net/dccp/ackvec.c |   78 +++++++++++++++++++----------------------------------
 1 files changed, 28 insertions(+), 50 deletions(-)

--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c
@@ -24,24 +24,34 @@
 static struct kmem_cache *dccp_ackvec_slab;
 static struct kmem_cache *dccp_ackvec_record_slab;
 
-static struct dccp_ackvec_record *dccp_ackvec_record_new(void)
+struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
 {
-	struct dccp_ackvec_record *avr =
-			kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC);
+	struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority);
+
+	if (av != NULL) {
+		av->av_buf_head	 = DCCPAV_MAX_ACKVEC_LEN - 1;
+		av->av_vec_len	 = 0;
+		memset(av->av_buf_nonce, 0, sizeof(av->av_buf_nonce));
+		INIT_LIST_HEAD(&av->av_records);
+	}
+	return av;
+}
 
-	if (avr != NULL)
-		INIT_LIST_HEAD(&avr->avr_node);
+static void dccp_ackvec_purge_records(struct dccp_ackvec *av)
+{
+	struct dccp_ackvec_record *cur, *next;
 
-	return avr;
+	list_for_each_entry_safe(cur, next, &av->av_records, avr_node)
+		kmem_cache_free(dccp_ackvec_record_slab, cur);
+	INIT_LIST_HEAD(&av->av_records);
 }
 
-static void dccp_ackvec_record_delete(struct dccp_ackvec_record *avr)
+void dccp_ackvec_free(struct dccp_ackvec *av)
 {
-	if (unlikely(avr == NULL))
-		return;
-	/* Check if deleting a linked record */
-	WARN_ON(!list_empty(&avr->avr_node));
-	kmem_cache_free(dccp_ackvec_record_slab, avr);
+	if (likely(av != NULL)) {
+		dccp_ackvec_purge_records(av);
+		kmem_cache_free(dccp_ackvec_slab, av);
+	}
 }
 
 static void dccp_ackvec_insert_avr(struct dccp_ackvec *av,
@@ -85,7 +95,7 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
 		return -1;
 	}
 
-	avr = dccp_ackvec_record_new();
+	avr = kmem_cache_alloc(dccp_ackvec_record_slab, GFP_ATOMIC);
 	if (avr == NULL)
 		return -1;
 
@@ -147,37 +157,6 @@ int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb)
 	return 0;
 }
 
-struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority)
-{
-	struct dccp_ackvec *av = kmem_cache_alloc(dccp_ackvec_slab, priority);
-
-	if (av != NULL) {
-		av->av_buf_head	 = DCCPAV_MAX_ACKVEC_LEN - 1;
-		av->av_vec_len	 = 0;
-		memset(av->av_buf_nonce, 0, sizeof(av->av_buf_nonce));
-		INIT_LIST_HEAD(&av->av_records);
-	}
-
-	return av;
-}
-
-void dccp_ackvec_free(struct dccp_ackvec *av)
-{
-	if (unlikely(av == NULL))
-		return;
-
-	if (!list_empty(&av->av_records)) {
-		struct dccp_ackvec_record *avr, *next;
-
-		list_for_each_entry_safe(avr, next, &av->av_records, avr_node) {
-			list_del_init(&avr->avr_node);
-			dccp_ackvec_record_delete(avr);
-		}
-	}
-
-	kmem_cache_free(dccp_ackvec_slab, av);
-}
-
 /*
  * If several packets are missing, the HC-Receiver may prefer to enter multiple
  * bytes with run length 0, rather than a single byte with a larger run length;
@@ -321,8 +300,8 @@ static void dccp_ackvec_throw_record(struct dccp_ackvec *av,
 
 	/* free records */
 	list_for_each_entry_safe_from(avr, next, &av->av_records, avr_node) {
-		list_del_init(&avr->avr_node);
-		dccp_ackvec_record_delete(avr);
+		list_del(&avr->avr_node);
+		kmem_cache_free(dccp_ackvec_record_slab, avr);
 	}
 }
 
@@ -431,10 +410,9 @@ int __init dccp_ackvec_init(void)
 	if (dccp_ackvec_slab == NULL)
 		goto out_err;
 
-	dccp_ackvec_record_slab =
-			kmem_cache_create("dccp_ackvec_record",
-					  sizeof(struct dccp_ackvec_record),
-					  0, SLAB_HWCACHE_ALIGN, NULL);
+	dccp_ackvec_record_slab = kmem_cache_create("dccp_ackvec_record",
+					     sizeof(struct dccp_ackvec_record),
+					     0, SLAB_HWCACHE_ALIGN, NULL);
 	if (dccp_ackvec_record_slab == NULL)
 		goto out_destroy_slab;
 
-- 
1.5.3.GIT


  reply	other threads:[~2007-12-19 14:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-19 14:25 [DCCP] [RFC] [Patch 0/14]: Ack Vector implementation + fixes Gerrit Renker
2007-12-19 14:25 ` [PATCH 01/14] [CCID2]: Ack Vectors can happen on most packets Gerrit Renker
2007-12-19 14:25   ` [PATCH 02/14] [ACKVEC]: Update Ack Vector fields Gerrit Renker
2007-12-19 14:25     ` [PATCH 03/14] [ACKVEC]: Use Elapsed Time separately Gerrit Renker
2007-12-19 14:25       ` [PATCH 04/14] [ACKVEC]: Inlines for run length and state Gerrit Renker
2007-12-19 14:25         ` Gerrit Renker [this message]
2007-12-19 14:25           ` [PATCH 06/14] [ACKVEC]: Simplify adding Ack Vector records, split option-specific code Gerrit Renker
2007-12-19 14:25             ` [PATCH 07/14] [ACKVEC]: Unnecessary to parse Ack Vectors when clearing HC-receiver state Gerrit Renker
2007-12-19 14:25               ` [PATCH 08/14] [ACKVEC]: Use enum to enumerate Ack Vector states Gerrit Renker
2007-12-19 14:25                 ` [PATCH 09/14] [ACKVEC]: Support for circular Ack Vector buffer with overflow handling Gerrit Renker
2007-12-19 14:25                   ` [PATCH 10/14] [ACKVEC]: Determine buffer length dynamically Gerrit Renker
2007-12-19 14:25                     ` [PATCH 11/14] [ACKVEC]: Implement algorithm to update buffer state Gerrit Renker
2007-12-19 14:25                       ` [PATCH 12/14] [ACKVEC]: Update Ack Vector input routine Gerrit Renker
2007-12-19 14:25                         ` [PATCH 13/14] [ACKVEC]: Aggregate Ack-Vector related processing into single function Gerrit Renker
2007-12-19 14:25                           ` [PATCH 14/14] [ACKVEC]: Remove old infrastructure Gerrit Renker

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=1198074355-18842-6-git-send-email-gerrit@erg.abdn.ac.uk \
    --to=gerrit@erg.abdn.ac.uk \
    --cc=acme@redhat.com \
    --cc=dccp@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox