]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[SOCK] Avoid divides in sk_stream_pages() and __sk_stream_mem_reclaim()
authorEric Dumazet <dada1@cosmosbay.com>
Tue, 25 Dec 2007 04:57:56 +0000 (20:57 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 28 Jan 2008 23:00:05 +0000 (15:00 -0800)
sk_forward_alloc being signed, we should take care of divides by
SK_STREAM_MEM_QUANTUM we do in sk_stream_pages() and
__sk_stream_mem_reclaim()

This patchs introduces SK_STREAM_MEM_QUANTUM_SHIFT, defined
as ilog2(SK_STREAM_MEM_QUANTUM), to be able to use right
shifts instead of plain divides.

This should help compiler to choose right shifts instead of
expensive divides (as seen with CONFIG_CC_OPTIMIZE_FOR_SIZE=y on x86)

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/sock.h
net/core/stream.c

index e178b49eefbb9c26fe47b0e01fc9df54760c614d..d27ba6fdd03971e8512f37fe691c6c57da8f3aca 100644 (file)
@@ -716,10 +716,11 @@ extern void __sk_stream_mem_reclaim(struct sock *sk);
 extern int sk_stream_mem_schedule(struct sock *sk, int size, int kind);
 
 #define SK_STREAM_MEM_QUANTUM ((int)PAGE_SIZE)
+#define SK_STREAM_MEM_QUANTUM_SHIFT ilog2(SK_STREAM_MEM_QUANTUM)
 
 static inline int sk_stream_pages(int amt)
 {
-       return DIV_ROUND_UP(amt, SK_STREAM_MEM_QUANTUM);
+       return (amt + SK_STREAM_MEM_QUANTUM - 1) >> SK_STREAM_MEM_QUANTUM_SHIFT;
 }
 
 static inline void sk_stream_mem_reclaim(struct sock *sk)
index 5586879bb9b3815f8e021a8907d03ce04059bb50..bf188ffdbdbe9137cfe78c7041e8e482f43df37b 100644 (file)
@@ -196,7 +196,7 @@ EXPORT_SYMBOL(sk_stream_error);
 
 void __sk_stream_mem_reclaim(struct sock *sk)
 {
-       atomic_sub(sk->sk_forward_alloc / SK_STREAM_MEM_QUANTUM,
+       atomic_sub(sk->sk_forward_alloc >> SK_STREAM_MEM_QUANTUM_SHIFT,
                   sk->sk_prot->memory_allocated);
        sk->sk_forward_alloc &= SK_STREAM_MEM_QUANTUM - 1;
        if (*sk->sk_prot->memory_pressure &&