From patchwork Wed Oct 12 09:49:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihai Maruseac X-Patchwork-Id: 119174 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3DEBBB6F6B for ; Wed, 12 Oct 2011 20:49:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751725Ab1JLJta (ORCPT ); Wed, 12 Oct 2011 05:49:30 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:63482 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857Ab1JLJt2 (ORCPT ); Wed, 12 Oct 2011 05:49:28 -0400 Received: by ywb5 with SMTP id 5so499790ywb.19 for ; Wed, 12 Oct 2011 02:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=290y2qNYd8Cw4TtOlI9H7NeES3zGWyqHXhf7G0Ci5Uc=; b=P5w6fIYxCkpyOWK33iCUOknLVbmcY/MB8Wq0polAm1D1RApTpQhdS126ySCOAEHheK IDTATPgLGzhATUmSUQJMouyoxJc5InmUnKhcMe4TJAS1z2OUoOmQzeaMbWDzNJSzmCPS Ut6V56dCLeyBPyojqudrg2ruwUUmk2fFkDB+Q= Received: by 10.223.85.134 with SMTP id o6mr45642324fal.8.1318412967560; Wed, 12 Oct 2011 02:49:27 -0700 (PDT) Received: from localhost.localdomain (ixro-out-rtc.ixiacom.com. [92.87.192.98]) by mx.google.com with ESMTPS id a7sm3160742fam.22.2011.10.12.02.49.25 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Oct 2011 02:49:26 -0700 (PDT) From: Mihai Maruseac To: davem@davemloft.net Cc: eric.dumazet@gmail.com, mirq-linux@rere.qmqm.pl, therbert@google.com, jpirko@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dbaluta@ixiacom.com, Mihai Maruseac Subject: [PATCH] dev: use ifindex hash for dev_seq_ops Date: Wed, 12 Oct 2011 12:49:10 +0300 Message-Id: <1318412950-22014-1-git-send-email-mmaruseac@ixiacom.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1318000849-2531-1-git-send-email-mmaruseac@ixiacom.com> References: <1318000849-2531-1-git-send-email-mmaruseac@ixiacom.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Instead of using the dev->next chain and trying to resync at each call to dev_seq_start, use the ifindex, keeping the last index in seq->private field. Tests revealed the following results for ifconfig > /dev/null * 1000 interfaces: * 0.114s without patch * 0.089s with patch * 3000 interfaces: * 0.489s without patch * 0.110s with patch * 5000 interfaces: * 1.363s without patch * 0.250s with patch * 128000 interfaces (other setup): * ~100s without patch * ~30s with patch --- net/core/dev.c | 53 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 32 insertions(+), 21 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 70ecb86..3ca0df8 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -4041,6 +4041,35 @@ static int dev_ifconf(struct net *net, char __user *arg) } #ifdef CONFIG_PROC_FS + +struct dev_iter_state { + struct seq_net_private p; + int ifindex; +}; + +static inline struct net_device* next_dev(struct seq_file *seq, loff_t *pos) +{ + struct dev_iter_state *state = seq->private; + struct net *net = seq_file_net(seq); + struct net_device *dev = NULL; + loff_t off; + + ++*pos; + dev = dev_get_by_index_rcu(net, state->ifindex); + state->ifindex++; + if (likely(dev)) + return dev; + + off = 1; + for_each_netdev_rcu(net, dev) + if (off++ == *pos) { + state->ifindex = dev->ifindex + 1; + return dev; + } + + return NULL; +} + /* * This is invoked by the /proc filesystem handler to display a device * in detail. @@ -4048,33 +4077,15 @@ static int dev_ifconf(struct net *net, char __user *arg) void *dev_seq_start(struct seq_file *seq, loff_t *pos) __acquires(RCU) { - struct net *net = seq_file_net(seq); - loff_t off; - struct net_device *dev; - rcu_read_lock(); if (!*pos) return SEQ_START_TOKEN; - - off = 1; - for_each_netdev_rcu(net, dev) - if (off++ == *pos) - return dev; - - return NULL; + return next_dev(seq, pos); } void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) { - struct net_device *dev = v; - - if (v == SEQ_START_TOKEN) - dev = first_net_device_rcu(seq_file_net(seq)); - else - dev = next_net_device_rcu(dev); - - ++*pos; - return dev; + return next_dev(seq, pos); } void dev_seq_stop(struct seq_file *seq, void *v) @@ -4173,7 +4184,7 @@ static const struct seq_operations dev_seq_ops = { static int dev_seq_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &dev_seq_ops, - sizeof(struct seq_net_private)); + sizeof(struct dev_iter_state)); } static const struct file_operations dev_seq_fops = {