From: Eric Dumazet <dada1@cosmosbay.com>
To: "David S. Miller" <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>
Subject: [SOCK] Avoid integer divides where not necessary in include/net/sock.h
Date: Fri, 21 Dec 2007 07:18:40 +0100 [thread overview]
Message-ID: <476B5AC0.9060604@cosmosbay.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 368 bytes --]
Because sk_wmem_queued, sk_sndbuf are signed, a divide per two
forces compiler to use an integer divide. We can instead use
a right shift.
SK_STREAM_MEM_QUANTUM deserves to be declared as an unsigned
quantity, so that sk_stream_pages() and __sk_stream_mem_reclaim()
can use right shifts instead of integer divides.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
[-- Attachment #2: sock_h.patch --]
[-- Type: text/plain, Size: 1480 bytes --]
diff --git a/include/net/sock.h b/include/net/sock.h
index 803d8f2..6da08fc 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -445,7 +445,7 @@ static inline int sk_acceptq_is_full(struct sock *sk)
*/
static inline int sk_stream_min_wspace(struct sock *sk)
{
- return sk->sk_wmem_queued / 2;
+ return sk->sk_wmem_queued >> 1;
}
static inline int sk_stream_wspace(struct sock *sk)
@@ -715,7 +715,7 @@ static inline struct inode *SOCK_INODE(struct socket *socket)
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 ((unsigned int)PAGE_SIZE)
static inline int sk_stream_pages(int amt)
{
@@ -1187,7 +1187,7 @@ static inline void sk_wake_async(struct sock *sk, int how, int band)
static inline void sk_stream_moderate_sndbuf(struct sock *sk)
{
if (!(sk->sk_userlocks & SOCK_SNDBUF_LOCK)) {
- sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued / 2);
+ sk->sk_sndbuf = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1);
sk->sk_sndbuf = max(sk->sk_sndbuf, SOCK_MIN_SNDBUF);
}
}
@@ -1211,7 +1211,7 @@ static inline struct page *sk_stream_alloc_page(struct sock *sk)
*/
static inline int sock_writeable(const struct sock *sk)
{
- return atomic_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf / 2);
+ return atomic_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1);
}
static inline gfp_t gfp_any(void)
next reply other threads:[~2007-12-21 6:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-21 6:18 Eric Dumazet [this message]
2007-12-21 9:55 ` [SOCK] Avoid integer divides where not necessary in include/net/sock.h David Miller
2007-12-21 10:40 ` Eric Dumazet
2007-12-21 11:06 ` David Miller
2007-12-21 12:58 ` Herbert Xu
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=476B5AC0.9060604@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).