From patchwork Mon May 14 08:21:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 158911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0D7EDB6EE7 for ; Mon, 14 May 2012 18:21:38 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753479Ab2ENIVg (ORCPT ); Mon, 14 May 2012 04:21:36 -0400 Received: from mail.us.es ([193.147.175.20]:38086 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753336Ab2ENIVf (ORCPT ); Mon, 14 May 2012 04:21:35 -0400 Received: (qmail 25598 invoked from network); 14 May 2012 10:21:33 +0200 Received: from unknown (HELO us.es) (192.168.2.12) by us.es with SMTP; 14 May 2012 10:21:33 +0200 Received: (qmail 18891 invoked by uid 507); 14 May 2012 08:21:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on antivirus2 X-Spam-Level: X-Spam-Status: No, score=-99.2 required=7.5 tests=BAYES_50,SPF_HELO_FAIL, USER_IN_WHITELIST autolearn=disabled version=3.3.1 Received: from 127.0.0.1 by antivirus2 (envelope-from , uid 501) with qmail-scanner-2.08 (clamdscan: 0.97.4/14915. Clear:RC:1(127.0.0.1):. Processed in 0.058385 secs); 14 May 2012 08:21:31 -0000 Received: from unknown (HELO antivirus2) (127.0.0.1) by us.es with SMTP; 14 May 2012 08:21:31 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus2 (F-Secure/fsigk_smtp/407/antivirus2); Mon, 14 May 2012 10:21:31 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/407/antivirus2) Received: (qmail 1344 invoked from network); 14 May 2012 10:21:50 +0200 Received: from 1984.lsi.us.es (HELO us.es) (1984lsi@150.214.188.80) by us.es with AES128-SHA encrypted SMTP; 14 May 2012 10:21:50 +0200 Date: Mon, 14 May 2012 10:21:31 +0200 From: Pablo Neira Ayuso To: David Miller Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH 0/5] netfilter updates for net-next (upcoming 3.5), batch 2 Message-ID: <20120514082131.GA9524@1984> References: <1336563188-6720-1-git-send-email-pablo@netfilter.org> <20120509.181119.549113304045405166.davem@davemloft.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120509.181119.549113304045405166.davem@davemloft.net> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org On Wed, May 09, 2012 at 06:11:19PM -0400, David Miller wrote: > From: pablo@netfilter.org > Date: Wed, 9 May 2012 13:33:03 +0200 > > > This is a second batch of netfilter updates for net-next, they contain: > > > > * The new HMARK target from Hans Schillstrom. It took lots of spins > > to get this into shape. This target provides a hash-based packet / flow > > pre-classifier for iptables that can be used to distribute packets > > / flows between uplinks and backend servers. It provides to modes, one > > that relies on conntrack, and one that is stateless per-packet. > > > > * Byte-based cost calculation for the hashlimit match, to detect when > > a host consumes more bandwidth than expected. This patch from Florian > > Westphal. > > > > You can pull these changes from: > > > > git://1984.lsi.us.es/net-next > > Pulled. > > Two suggested improvements: > > 1) The HMARK hash is quite expensive, because it uses a modulus. > > Consider adjusting it to use the usual trick: > > ((u64)(HASH_VAL * HASH_SIZE)) >> 32 > > so that this can be a multiply instead of a modulus. I'll enqueue the patch attached for this. Thanks for spotting this. From 3b81af711d639cdcf820836bad6b4ac0f5a761fa Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 14 May 2012 02:01:46 +0200 Subject: [PATCH] netfilter: xt_HMARK: modulus is expensive for hash calculation Use: ((u64)(HASH_VAL * HASH_SIZE)) >> 32 as suggested by David S. Miller. Signed-off-by: Pablo Neira Ayuso --- net/netfilter/xt_HMARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/xt_HMARK.c b/net/netfilter/xt_HMARK.c index 5817d03..0a96a43 100644 --- a/net/netfilter/xt_HMARK.c +++ b/net/netfilter/xt_HMARK.c @@ -109,7 +109,7 @@ hmark_hash(struct hmark_tuple *t, const struct xt_hmark_info *info) hash = jhash_3words(t->src, t->dst, t->uports.v32, info->hashrnd); hash = hash ^ (t->proto & info->proto_mask); - return (hash % info->hmodulus) + info->hoffset; + return (((u64)hash * info->hmodulus) >> 32) + info->hoffset; } static void -- 1.7.10