Thread (18 messages) 18 messages, 5 authors, 2019-04-04

[RFC 3/4] net/fib: Check budget before should_{inflate,halve}()

From: Dmitry Safonov <hidden>
Date: 2019-03-26 15:30:39
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

Those functions are compute-costly, if we're out of budget - better
omit additional computations.

Signed-off-by: Dmitry Safonov <redacted>
---
 net/ipv4/fib_trie.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index d90cf9dfd443..2ce2739e7693 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -868,7 +868,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn,
 	/* Double as long as the resulting node has a number of
 	 * nonempty nodes that are above the threshold.
 	 */
-	while (should_inflate(tp, tn) && *budget) {
+	while (*budget && should_inflate(tp, tn)) {
 		tp = inflate(t, tn, budget);
 		if (!tp) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
@@ -894,7 +894,7 @@ static struct key_vector *resize(struct trie *t, struct key_vector *tn,
 	/* Halve as long as the number of empty children in this
 	 * node is above threshold.
 	 */
-	while (should_halve(tp, tn) && *budget) {
+	while (*budget && should_halve(tp, tn)) {
 		tp = halve(t, tn, budget);
 		if (!tp) {
 #ifdef CONFIG_IP_FIB_TRIE_STATS
-- 
2.21.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