netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <jdb@comx.dk>
To: Netfilter Developers <netfilter-devel@vger.kernel.org>,
	Harald Welte <laforge@netfilter.org>
Cc: "Paul C. Diem" <PCDiem@FoxValley.net>,
	Martin Josefsson <gandalf@netfilter.org>
Subject: [PATCH 1/2] iptables/libiptc perf issue: Sorting chain during pull-out
Date: Mon, 26 Nov 2007 14:56:37 +0100	[thread overview]
Message-ID: <1196085397.3866.58.camel@localhost.localdomain> (raw)


Performance optimize scalability issue:
  Sorting chain during pull-out give worst-case runtime O(Chains^2).

When pulling out the blob, every chain name is inserted alphabetically
into a linked list (by function iptc_insert_chain()).  The problem
with this approach is that the chain names delivered in the blob is
already sorted (as we push it back to the kernel sorted).

This cause chain parsing to always process every element in the chain
list and finish with a tail add.  Causing worst-case runtime O(C^2/2)
for alphabetically sorting of chains.

The patch solves this by only calling iptc_insert_chain() when
creating new chains.

Signed-off-by: Jesper Dangaard Brouer <hawk@comx.dk>
---
 libiptc/libiptc.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index 472b81e..e7ffb01 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -420,8 +420,8 @@ static void __iptcc_p_add_chain(TC_HANDLE_T h, struct chain_head *c,
 	c->head_offset = offset;
 	c->index = *num;
 
-	iptc_insert_chain(h, c);
-	
+	list_add_tail(&c->list, &h->chains); /* Its already sorted */
+
 	h->chain_iterator_cur = c;
 }
 
@@ -1791,7 +1791,7 @@ TC_CREATE_CHAIN(const IPT_CHAINLABEL chain, TC_HANDLE_T *handle)
 	}
 
 	DEBUGP("Creating chain `%s'\n", chain);
-	list_add_tail(&c->list, &(*handle)->chains);
+	iptc_insert_chain(*handle, c); /* Insert sorted */
 
 	set_changed(*handle);
 


             reply	other threads:[~2007-11-26 13:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-26 13:56 Jesper Dangaard Brouer [this message]
2007-11-28  8:32 ` [PATCH 1/2] iptables/libiptc perf issue: Sorting chain during pull-out Patrick McHardy

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=1196085397.3866.58.camel@localhost.localdomain \
    --to=jdb@comx.dk \
    --cc=PCDiem@FoxValley.net \
    --cc=gandalf@netfilter.org \
    --cc=laforge@netfilter.org \
    --cc=netfilter-devel@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;
as well as URLs for NNTP newsgroup(s).