public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Scot Doyle <lkml@scotdoyle.com>, David Miller <davem@davemloft.net>
Cc: Stephen Hemminger <shemminger@vyatta.com>,
	Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>,
	netdev@vger.kernel.org
Subject: [PATCH] inetpeer: reduce stack usage
Date: Tue, 12 Apr 2011 10:39:40 +0200	[thread overview]
Message-ID: <1302597580.3233.14.camel@edumazet-laptop> (raw)
In-Reply-To: <1302593469.3603.44.camel@edumazet-laptop>

On 64bit arches, we use 752 bytes of stack when cleanup_once() is called
from inet_getpeer().

Lets share the avl stack to save ~376 bytes.

Before patch :

# objdump -d net/ipv4/inetpeer.o | scripts/checkstack.pl

0x000006c3 unlink_from_pool [inetpeer.o]:		376
0x00000721 unlink_from_pool [inetpeer.o]:		376
0x00000cb1 inet_getpeer [inetpeer.o]:			376
0x00000e6d inet_getpeer [inetpeer.o]:			376
0x0004 inet_initpeers [inetpeer.o]:			112
# size net/ipv4/inetpeer.o
   text	   data	    bss	    dec	    hex	filename
   5320	    432	     21	   5773	   168d	net/ipv4/inetpeer.o

After patch :

objdump -d net/ipv4/inetpeer.o | scripts/checkstack.pl 
0x00000c11 inet_getpeer [inetpeer.o]:			376
0x00000dcd inet_getpeer [inetpeer.o]:			376
0x00000ab9 peer_check_expire [inetpeer.o]:		328
0x00000b7f peer_check_expire [inetpeer.o]:		328
0x0004 inet_initpeers [inetpeer.o]:			112
# size net/ipv4/inetpeer.o
   text	   data	    bss	    dec	    hex	filename
   5163	    432	     21	   5616	   15f0	net/ipv4/inetpeer.o

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Scot Doyle <lkml@scotdoyle.com>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Cc: Hiroaki SHIMODA <shimoda.hiroaki@gmail.com>
---
 net/ipv4/inetpeer.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index dd1b20e..9df4e63 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -354,7 +354,8 @@ static void inetpeer_free_rcu(struct rcu_head *head)
 }
 
 /* May be called with local BH enabled. */
-static void unlink_from_pool(struct inet_peer *p, struct inet_peer_base *base)
+static void unlink_from_pool(struct inet_peer *p, struct inet_peer_base *base,
+			     struct inet_peer __rcu **stack[PEER_MAXDEPTH])
 {
 	int do_free;
 
@@ -368,7 +369,6 @@ static void unlink_from_pool(struct inet_peer *p, struct inet_peer_base *base)
 	 * We use refcnt=-1 to alert lockless readers this entry is deleted.
 	 */
 	if (atomic_cmpxchg(&p->refcnt, 1, -1) == 1) {
-		struct inet_peer __rcu **stack[PEER_MAXDEPTH];
 		struct inet_peer __rcu ***stackptr, ***delp;
 		if (lookup(&p->daddr, stack, base) != p)
 			BUG();
@@ -422,7 +422,7 @@ static struct inet_peer_base *peer_to_base(struct inet_peer *p)
 }
 
 /* May be called with local BH enabled. */
-static int cleanup_once(unsigned long ttl)
+static int cleanup_once(unsigned long ttl, struct inet_peer __rcu **stack[PEER_MAXDEPTH])
 {
 	struct inet_peer *p = NULL;
 
@@ -454,7 +454,7 @@ static int cleanup_once(unsigned long ttl)
 		 * happen because of entry limits in route cache. */
 		return -1;
 
-	unlink_from_pool(p, peer_to_base(p));
+	unlink_from_pool(p, peer_to_base(p), stack);
 	return 0;
 }
 
@@ -524,7 +524,7 @@ struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create)
 
 	if (base->total >= inet_peer_threshold)
 		/* Remove one less-recently-used entry. */
-		cleanup_once(0);
+		cleanup_once(0, stack);
 
 	return p;
 }
@@ -540,6 +540,7 @@ static void peer_check_expire(unsigned long dummy)
 {
 	unsigned long now = jiffies;
 	int ttl, total;
+	struct inet_peer __rcu **stack[PEER_MAXDEPTH];
 
 	total = compute_total();
 	if (total >= inet_peer_threshold)
@@ -548,7 +549,7 @@ static void peer_check_expire(unsigned long dummy)
 		ttl = inet_peer_maxttl
 				- (inet_peer_maxttl - inet_peer_minttl) / HZ *
 					total / inet_peer_threshold * HZ;
-	while (!cleanup_once(ttl)) {
+	while (!cleanup_once(ttl, stack)) {
 		if (jiffies != now)
 			break;
 	}



  reply	other threads:[~2011-04-12  8:39 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-08  1:20 Kernel panic when using bridge Scot Doyle
2011-04-08 13:49 ` Sebastian Nickel
2011-04-08 14:57   ` Scot Doyle
2011-04-08 19:12     ` Pallai Roland
2011-04-08 19:17 ` Stephen Hemminger
2011-04-09  4:51   ` Scot Doyle
2011-04-09  7:19     ` Hiroaki SHIMODA
2011-04-11 23:48       ` Scot Doyle
2011-04-12  1:31         ` Stephen Hemminger
2011-04-12  3:47           ` Scot Doyle
2011-04-12  4:09             ` Eric Dumazet
2011-04-12  4:22               ` Eric Dumazet
2011-04-12  5:17                 ` Scot Doyle
2011-04-12  5:51                   ` Eric Dumazet
2011-04-12  7:02                     ` Scot Doyle
2011-04-12  7:31                       ` Eric Dumazet
2011-04-12  8:39                         ` Eric Dumazet [this message]
2011-04-12 14:51                           ` [PATCH] inetpeer: reduce stack usage Hiroaki SHIMODA
2011-04-12 14:55                             ` Eric Dumazet
2011-04-12 20:58                               ` David Miller
2011-04-12 11:49                       ` Kernel panic when using bridge Eric Dumazet
2011-04-12 13:02                         ` Jan Lübbe
2011-04-12 13:15                           ` Eric Dumazet
2011-04-12 14:19                             ` Jan Lübbe
2011-04-12 14:49                               ` Eric Dumazet
2011-04-12 15:13                                 ` Jan Lübbe
2011-04-12 16:14                                   ` Eric Dumazet
2011-04-12 16:20                                     ` Stephen Hemminger
2011-04-12 16:35                                       ` Eric Dumazet
2011-04-12 16:45                                         ` Bandan Das
2011-04-12 16:54                                           ` Eric Dumazet
2011-04-12 17:18                                             ` [PATCH] bridge: reset IPCB in br_parse_ip_options Eric Dumazet
2011-04-12 20:39                                               ` David Miller
2011-04-12 23:55                                               ` Scot Doyle
2011-04-13  4:12                                                 ` Scot Doyle
2011-04-13 15:10                                                   ` Scot Doyle
2011-04-13 15:24                                                     ` Stephen Hemminger
2011-04-13 15:54                                                       ` Scot Doyle
2011-04-13 15:28                                                     ` Eric Dumazet
2011-04-13 21:48                                                       ` David Miller
2011-04-14  0:03                                                         ` Stephen Hemminger
2011-04-14  0:05                                                           ` David Miller
2011-04-14  0:08                                                             ` Stephen Hemminger
2011-04-14  2:31                                                         ` Eric Dumazet
2011-04-14  2:54                                                           ` Stephen Hemminger
2011-04-14  3:03                                                             ` [PATCH] ip: ip_options_compile() resilient to NULL skb route Eric Dumazet
2011-04-14  3:30                                                               ` Hiroaki SHIMODA
2011-04-14  3:37                                                                 ` Eric Dumazet
2011-04-14  4:15                                                                   ` Hiroaki SHIMODA
2011-04-14 13:34                                                                     ` Scot Doyle
2011-04-14 15:55                                                                 ` [PATCH v2] " Eric Dumazet
2011-04-14 22:02                                                                   ` Scot Doyle
2011-04-14 22:04                                                                     ` David Miller
2011-04-14 23:20                                                                   ` Hiroaki SHIMODA
2011-04-15  6:26                                                                     ` David Miller
2011-04-12 16:32                                     ` Kernel panic when using bridge Bandan Das

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=1302597580.3233.14.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=lkml@scotdoyle.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    --cc=shimoda.hiroaki@gmail.com \
    /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