From patchwork Thu Nov 1 16:02:24 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: 196267 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 86EE52C0348 for ; Fri, 2 Nov 2012 03:02:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964919Ab2KAQCk (ORCPT ); Thu, 1 Nov 2012 12:02:40 -0400 Received: from mail.us.es ([193.147.175.20]:37651 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964813Ab2KAQCj (ORCPT ); Thu, 1 Nov 2012 12:02:39 -0400 Received: (qmail 8742 invoked from network); 1 Nov 2012 17:02:38 +0100 Received: from unknown (HELO us.es) (192.168.2.12) by us.es with SMTP; 1 Nov 2012 17:02:38 +0100 Received: (qmail 26368 invoked by uid 507); 1 Nov 2012 16:02:38 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus2 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.97.6/15527. spamassassin: 3.3.2. Clear:RC:1(127.0.0.1):SA:0(-97.0/7.5):. Processed in 4.732394 secs); 01 Nov 2012 16:02:38 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on antivirus2 X-Spam-Level: X-Spam-Status: No, score=-97.0 required=7.5 tests=BAYES_50, RCVD_IN_BRBL_LASTEXT,RCVD_IN_PBL,RCVD_IN_SORBS_DUL,RDNS_DYNAMIC, USER_IN_WHITELIST autolearn=disabled version=3.3.2 X-Envelope-From: pablo@netfilter.org Received: from unknown (HELO antivirus2) (127.0.0.1) by us.es with SMTP; 1 Nov 2012 16:02:33 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus2 (F-Secure/fsigk_smtp/407/antivirus2); Thu, 01 Nov 2012 17:02:33 +0100 (CET) X-Virus-Status: clean(F-Secure/fsigk_smtp/407/antivirus2) Received: (qmail 1344 invoked from network); 1 Nov 2012 17:02:33 +0100 Received: from 69.190.220.87.dynamic.jazztel.es (HELO localhost.localdomain) (pneira@us.es@87.220.190.69) by us.es with SMTP; 1 Nov 2012 17:02:33 +0100 From: pablo@netfilter.org To: netfilter-devel@vger.kernel.org Cc: Tomasz Bursztyka Subject: [PATCH 2/2] netfilter: nf_tables: improve deletion performance Date: Thu, 1 Nov 2012 17:02:24 +0100 Message-Id: <1351785744-7492-3-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1351785744-7492-1-git-send-email-pablo@netfilter.org> References: <1351785744-7492-1-git-send-email-pablo@netfilter.org> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Pablo Neira Ayuso Simple solution: Use kfree_rcu instead of synchronize_rcu. This gets struct nft_rule fatter. Regarding caching issues, it would be good to place struct rcu_head at the end of struct nft_rule. However, the expression area of one rule has variable length. Signed-off-by: Pablo Neira Ayuso --- include/net/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 11 +---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h index 3289e0d..a179a6b 100644 --- a/include/net/netfilter/nf_tables.h +++ b/include/net/netfilter/nf_tables.h @@ -296,12 +296,14 @@ static inline void *nft_expr_priv(const struct nft_expr *expr) * struct nft_rule - nf_tables rule * * @list: used internally + * @rcu_head: used internally for rcu * @handle: rule handle * @dlen: length of expression data * @data: expression data */ struct nft_rule { struct list_head list; + struct rcu_head rcu_head; u64 handle; u16 dlen; unsigned char data[] diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index cfe6b85..5ed8b06 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -1289,7 +1289,7 @@ static void nf_tables_rule_destroy(const struct nft_ctx *ctx, nf_tables_expr_destroy(ctx, expr); expr = nft_expr_next(expr); } - kfree(rule); + kfree_rcu(rule, rcu_head); } #define NFT_RULE_MAXEXPRS 12 @@ -1391,9 +1391,6 @@ static int nf_tables_newrule(struct sock *nlsk, struct sk_buff *skb, list_replace_rcu(&old_rule->list, &rule->list); - // FIXME: this makes deletion performance *really* suck - synchronize_rcu(); - nf_tables_rule_notify(skb, nlh, table, chain, old_rule, NFT_MSG_DELRULE, nfmsg->nfgen_family); nf_tables_rule_destroy(&ctx, old_rule); @@ -1448,9 +1445,6 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb, /* List removal must be visible before destroying expressions */ list_del_rcu(&rule->list); - // FIXME: this makes deletion performance *really* suck - synchronize_rcu(); - nf_tables_rule_notify(skb, nlh, table, chain, rule, NFT_MSG_DELRULE, family); nft_ctx_init(&ctx, skb, nlh, afi, table, chain); @@ -1460,9 +1454,6 @@ static int nf_tables_delrule(struct sock *nlsk, struct sk_buff *skb, list_for_each_entry_safe(rule, tmp, &chain->rules, list) { list_del_rcu(&rule->list); - // FIXME: this makes deletion performance *really* suck - synchronize_rcu(); - nf_tables_rule_notify(skb, nlh, table, chain, rule, NFT_MSG_DELRULE, family);