Thread (3 messages) 3 messages, 2 authors, 2021-03-01

[PATCH] inetpeer: use else if instead of if to reduce judgment

flat view
STALE2066d

From: Yejune Deng <hidden>
Date: 2021-02-26 10:59:21
Also in: lkml
Subsystem: networking [general], networking [ipv4/ipv6], the rest · Maintainers: "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, David Ahern, Ido Schimmel, Linus Torvalds

In inet_initpeers(), if si.totalram <= (8192*1024)/PAGE_SIZE, it will
be judged three times. Use else if instead of if, it only needs to be
judged once.

Signed-off-by: Yejune Deng <redacted>
---
 net/ipv4/inetpeer.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
index ff327a62c9ce..07cd1f8204b3 100644
--- a/net/ipv4/inetpeer.c
+++ b/net/ipv4/inetpeer.c
@@ -81,12 +81,12 @@ void __init inet_initpeers(void)
 	 * <kuznet@ms2.inr.ac.ru>.  I don't have any opinion about the values
 	 * myself.  --SAW
 	 */
-	if (si.totalram <= (32768*1024)/PAGE_SIZE)
+	if (si.totalram <= (8192 * 1024) / PAGE_SIZE)
+		inet_peer_threshold >>= 4; /* about 128KB */
+	else if (si.totalram <= (16384 * 1024) / PAGE_SIZE)
+		inet_peer_threshold >>= 2; /* about 512KB */
+	else if (si.totalram <= (32768 * 1024) / PAGE_SIZE)
 		inet_peer_threshold >>= 1; /* max pool size about 1MB on IA32 */
-	if (si.totalram <= (16384*1024)/PAGE_SIZE)
-		inet_peer_threshold >>= 1; /* about 512KB */
-	if (si.totalram <= (8192*1024)/PAGE_SIZE)
-		inet_peer_threshold >>= 2; /* about 128KB */
 
 	peer_cachep = kmem_cache_create("inet_peer_cache",
 			sizeof(struct inet_peer),
-- 
2.29.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help