* [INET] Avoid an integer divide in rt_garbage_collect()
@ 2007-12-21 8:20 Eric Dumazet
2007-12-21 9:49 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2007-12-21 8:20 UTC (permalink / raw)
To: David S. Miller; +Cc: Linux Netdev List
[-- Attachment #1: Type: text/plain, Size: 189 bytes --]
Since 'goal' is a signed int, compiler may emit an integer divide
to compute goal/2.
Using a right shift is OK here and less expensive.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: route_divide.patch --]
[-- Type: text/plain, Size: 789 bytes --]
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index e35076e..10915bb 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -851,14 +851,14 @@ static int rt_garbage_collect(void)
equilibrium = ipv4_dst_ops.gc_thresh;
goal = atomic_read(&ipv4_dst_ops.entries) - equilibrium;
if (goal > 0) {
- equilibrium += min_t(unsigned int, goal / 2, rt_hash_mask + 1);
+ equilibrium += min_t(unsigned int, goal >> 1, rt_hash_mask + 1);
goal = atomic_read(&ipv4_dst_ops.entries) - equilibrium;
}
} else {
/* We are in dangerous area. Try to reduce cache really
* aggressively.
*/
- goal = max_t(unsigned int, goal / 2, rt_hash_mask + 1);
+ goal = max_t(unsigned int, goal >> 1, rt_hash_mask + 1);
equilibrium = atomic_read(&ipv4_dst_ops.entries) - goal;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [INET] Avoid an integer divide in rt_garbage_collect()
2007-12-21 8:20 [INET] Avoid an integer divide in rt_garbage_collect() Eric Dumazet
@ 2007-12-21 9:49 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2007-12-21 9:49 UTC (permalink / raw)
To: dada1; +Cc: netdev
From: Eric Dumazet <dada1@cosmosbay.com>
Date: Fri, 21 Dec 2007 09:20:50 +0100
> Since 'goal' is a signed int, compiler may emit an integer divide
> to compute goal/2.
>
> Using a right shift is OK here and less expensive.
>
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-12-21 9:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-21 8:20 [INET] Avoid an integer divide in rt_garbage_collect() Eric Dumazet
2007-12-21 9:49 ` David Miller
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).