From: Eric Dumazet <hidden> Date: 2008-01-12 11:16:24
Stephen Hemminger a écrit :
Make FIB TRIE go through sparse checker without warnings.
Signed-off-by: Stephen Hemminger <redacted>
Hi Stephen
While reviewing your patches (and fib code) I had some questions :
1) I was wondering isn't trie_collect_stats() a potential cpu hog
(big latency) ?
2) struct tnode layout
If tnode->bits is large enough, we allocate a big area
of memory but roughly use only first half of it.
We could use a better scheme with an extra indirection. For small
nodes, we use space right after tnode, but for big nodes, we allocate
a power of two set of pages, to exactly match the memory need.
3) 'pos' and 'bits' fields of 'struct tnode' might be converted to
plain uchar, instead of 5-bits fields, to reduce complexity for
generated code.
4) full_children & empty_children being 'unsigned short',
we probably are limited to 2^15 elements, but I could not
find this limit enforced somewhere.
[FIB]: Reduce text size of net/ipv4/fib_trie.o
In struct tnode, we use two fields of 5 bits for 'pos' and 'bits'.
Switching to plain 'unsigned char' (8 bits) take the same space
because of compiler alignments, and reduce text size by 435 bytes
on i386.
On i386 :
$ size net/ipv4/fib_trie.o.before_patch net/ipv4/fib_trie.o
text data bss dec hex filename
13714 4 64 13782 35d6 net/ipv4/fib_trie.o.before
13279 4 64 13347 3423 net/ipv4/fib_trie.o
Signed-off-by: Eric Dumazet <redacted>
From: David Miller <davem@davemloft.net> Date: 2008-01-12 11:28:01
From: Eric Dumazet <redacted>
Date: Sat, 12 Jan 2008 12:16:13 +0100
We could use a better scheme with an extra indirection.
Unfortunately, indirection will likely have a negative
impact upon performance. We go only as fast as the
number of memory references made by this code.
3) 'pos' and 'bits' fields of 'struct tnode' might be converted to
plain uchar, instead of 5-bits fields, to reduce complexity for
generated code.
From: Stephen Hemminger <hidden> Date: 2008-01-12 21:10:58
On Sat, 12 Jan 2008 12:16:13 +0100
Eric Dumazet [off-list ref] wrote:
Stephen Hemminger a écrit :
quoted
Make FIB TRIE go through sparse checker without warnings.
Signed-off-by: Stephen Hemminger <redacted>
Hi Stephen
While reviewing your patches (and fib code) I had some questions :
1) I was wondering isn't trie_collect_stats() a potential cpu hog
(big latency) ?
2) struct tnode layout
If tnode->bits is large enough, we allocate a big area
of memory but roughly use only first half of it.
We could use a better scheme with an extra indirection. For small
nodes, we use space right after tnode, but for big nodes, we allocate
a power of two set of pages, to exactly match the memory need.
3) 'pos' and 'bits' fields of 'struct tnode' might be converted to
plain uchar, instead of 5-bits fields, to reduce complexity for
generated code.
4) full_children & empty_children being 'unsigned short',
we probably are limited to 2^15 elements, but I could not
find this limit enforced somewhere.
Remember that the code should be optimized for lookup, not management
operations. We ran into this during testing (the test suite was looking
for number of routes), thats why I put in the size field.
The existing dump code is really slow:
1) FIB_TRIE Under KVM:
load 164393 routes 12.436 sec
ip route | wc -l 12.569 sec
grep /proc/net/route 25.357 sec
99% of the cpu time is spent in nextleaf() during these dump operations.
2) FIB_HASH Under KVM:
load 164393 routes 10.833 sec
ip route | wc -l 1.981 sec
grep /proc/net/route 0.204 sec
--
Stephen Hemminger [off-list ref]
From: Stephen Hemminger <hidden> Date: 2008-01-12 21:12:21
On Sat, 12 Jan 2008 12:16:13 +0100
Eric Dumazet [off-list ref] wrote:
Stephen Hemminger a écrit :
quoted
Make FIB TRIE go through sparse checker without warnings.
Signed-off-by: Stephen Hemminger <redacted>
Hi Stephen
While reviewing your patches (and fib code) I had some questions :
1) I was wondering isn't trie_collect_stats() a potential cpu hog
(big latency) ?
2) struct tnode layout
If tnode->bits is large enough, we allocate a big area
of memory but roughly use only first half of it.
We could use a better scheme with an extra indirection. For small
nodes, we use space right after tnode, but for big nodes, we allocate
a power of two set of pages, to exactly match the memory need.
3) 'pos' and 'bits' fields of 'struct tnode' might be converted to
plain uchar, instead of 5-bits fields, to reduce complexity for
generated code.
4) full_children & empty_children being 'unsigned short',
we probably are limited to 2^15 elements, but I could not
find this limit enforced somewhere.
[FIB]: Reduce text size of net/ipv4/fib_trie.o
In struct tnode, we use two fields of 5 bits for 'pos' and 'bits'.
Switching to plain 'unsigned char' (8 bits) take the same space
because of compiler alignments, and reduce text size by 435 bytes
on i386.
On i386 :
$ size net/ipv4/fib_trie.o.before_patch net/ipv4/fib_trie.o
text data bss dec hex filename
13714 4 64 13782 35d6 net/ipv4/fib_trie.o.before
13279 4 64 13347 3423 net/ipv4/fib_trie.o
Signed-off-by: Eric Dumazet <redacted>
I agree they should not have been bitfields in the first place.
--
Stephen Hemminger [off-list ref]
From: David Miller <davem@davemloft.net> Date: 2008-01-13 05:28:01
From: Stephen Hemminger <redacted>
Date: Sat, 12 Jan 2008 13:09:46 -0800
On Sat, 12 Jan 2008 12:16:13 +0100
Eric Dumazet [off-list ref] wrote:
quoted
[FIB]: Reduce text size of net/ipv4/fib_trie.o
In struct tnode, we use two fields of 5 bits for 'pos' and 'bits'.
Switching to plain 'unsigned char' (8 bits) take the same space
because of compiler alignments, and reduce text size by 435 bytes
on i386.
On i386 :
$ size net/ipv4/fib_trie.o.before_patch net/ipv4/fib_trie.o
text data bss dec hex filename
13714 4 64 13782 35d6 net/ipv4/fib_trie.o.before
13279 4 64 13347 3423 net/ipv4/fib_trie.o
Signed-off-by: Eric Dumazet <redacted>
I agree they should not have been bitfields in the first place.
From: Eric Dumazet <hidden> Date: 2008-01-13 18:30:36
Eric Dumazet a écrit :
4) full_children & empty_children being 'unsigned short',
we probably are limited to 2^15 elements, but I could not
find this limit enforced somewhere.
Hi David
In my testings, I found that once a tnode is built with 2^16 slots (or more),
it cannot be freed.
Extract of /proc/net/fib_triestat
Main:
Aver depth: 1.50
Max depth: 2
Leaves: 2
Internal nodes: 3
1: 1 2: 1 17: 1
Pointers: 131078
Null ptrs: 131074
Total size: 513 kB
# ip route
192.168.11.0/24 dev eth0 proto kernel scope link src 192.168.11.129
default via 192.168.11.2 dev eth0
Two fixes are possible : Enlarge full_children & empty_children to 32bits, or
force a limit in code to never exceed 2^15 children in a tnode. I chose the
first solution since it can be done with 0 memory cost on 64bit arches.
Thank you
[FIB]: full_children & empty_children should be uint, not ushort
If declared as unsigned short, these fields can overflow, and whole trie logic
is broken. I could not make the machine crash, but some tnode can never
be freed.
Note for 64 bit arches : By reordering t_key and parent in [node, leaf, tnode]
structures, we can use 32 bits hole after t_key so that sizeof(struct tnode)
doesnt change after this patch.
Signed-off-by: Eric Dumazet <redacted>
From: David Miller <davem@davemloft.net> Date: 2008-01-14 06:32:05
From: Robert Olsson <redacted>
Date: Sun, 13 Jan 2008 23:02:11 +0100
Eric Dumazet writes:
> Eric Dumazet a écrit :
> > 4) full_children & empty_children being 'unsigned short',
> > we probably are limited to 2^15 elements, but I could not
> > find this limit enforced somewhere.
> Two fixes are possible : Enlarge full_children & empty_children to 32bits, or
> force a limit in code to never exceed 2^15 children in a tnode. I chose the
> first solution since it can be done with 0 memory cost on 64bit arches.
...
Thanks for spotting this. No we don't want put limits on the (root) node size.
You see the comment in code is correct so unsigned short are some leftover from
old testing which could have hit us hard as the routing table slowly grows.
From: Robert Olsson <hidden> Date: 2008-01-14 11:07:42
Thanks for hacking and improving and the trie... another idea that could
be also tested. If we look into routing table we see that most leafs
only has one prefix
Main:
Aver depth: 2.57
Max depth: 7
Leaves: 231173
ip route | wc -l
241649
Thats 231173/241649 = 96% with the current Internet routing.
How about if would have a fastpath and store one entry direct in the
leaf struct this to avoid loading the leaf_info list in most cases?
One could believe that both lookup and dump could improve.
Cheers.
--ro
Stephen Hemminger writes:
> Remember that the code should be optimized for lookup, not management
> operations. We ran into this during testing (the test suite was looking
> for number of routes), thats why I put in the size field.
>
> The existing dump code is really slow:
>
> 1) FIB_TRIE Under KVM:
> load 164393 routes 12.436 sec
> ip route | wc -l 12.569 sec
> grep /proc/net/route 25.357 sec
>
> 99% of the cpu time is spent in nextleaf() during these dump operations.
>
> 2) FIB_HASH Under KVM:
> load 164393 routes 10.833 sec
> ip route | wc -l 1.981 sec
> grep /proc/net/route 0.204 sec
From: Robert Olsson <hidden> Date: 2008-01-14 18:00:06
Eric Dumazet writes:
> > Thats 231173/241649 = 96% with the current Internet routing.
> >
> > How about if would have a fastpath and store one entry direct in the
> > leaf struct this to avoid loading the leaf_info list in most cases?
> >
> > One could believe that both lookup and dump could improve.
> >
> You mean to include one "leaf_info" inside leaf structure, so that we
> can access it without cache line miss ?
Yes.
Cheers
--ro
From: Eric Dumazet <hidden> Date: 2008-01-14 18:56:14
Robert Olsson a écrit :
Thanks for hacking and improving and the trie... another idea that could
be also tested. If we look into routing table we see that most leafs
only has one prefix
Main:
Aver depth: 2.57
Max depth: 7
Leaves: 231173
ip route | wc -l
241649
Thats 231173/241649 = 96% with the current Internet routing.
How about if would have a fastpath and store one entry direct in the
leaf struct this to avoid loading the leaf_info list in most cases?
One could believe that both lookup and dump could improve.
You mean to include one "leaf_info" inside leaf structure, so that we
can access it without cache line miss ?
From: Eric Dumazet <hidden> Date: 2008-01-14 19:27:16
fib_trie_seq_show() uses two helper functions, rtn_scope() and
rtn_type() that can
write to static storage without locking.
Just pass to them a temporary buffer to avoid potential corruption
(probably not triggerable but still...)
Signed-off-by: Eric Dumazet <redacted>
From: David Miller <davem@davemloft.net> Date: 2008-01-15 07:10:33
From: Eric Dumazet <redacted>
Date: Mon, 14 Jan 2008 20:27:11 +0100
fib_trie_seq_show() uses two helper functions, rtn_scope() and
rtn_type() that can
write to static storage without locking.
Just pass to them a temporary buffer to avoid potential corruption
(probably not triggerable but still...)
Signed-off-by: Eric Dumazet <redacted>
Applied to net-2.6.25, but I had to tweak it to apply
cleanly since the %d in rtn_type() is now a %u