From: Eric Dumazet <dada1@cosmosbay.com>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: Bill Fink <billfink@mindspring.com>,
David Miller <davem@davemloft.net>,
netdev@vger.kernel.org, kuznet@ms2.inr.ac.ru, pekkas@netcore.fi,
jmorris@namei.org, yoshfuji@linux-ipv6.org, kaber@trash.net,
Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Subject: Re: [PATCH] net: implement emergency route cache rebulds when gc_elasticity is exceeded
Date: Tue, 07 Oct 2008 07:13:29 +0200 [thread overview]
Message-ID: <48EAEFF9.1000606@cosmosbay.com> (raw)
In-Reply-To: <20081006225210.GA29794@hmsreliant.think-freely.org>
Neil Horman a écrit :
> On Mon, Oct 06, 2008 at 11:21:38PM +0200, Eric Dumazet wrote:
>> Neil Horman a écrit :
>>> So, I've been playing with this patch, and I've not figured out eactly whats
>>> bothering me yet, since the math seems right, but something doesn't seem right
>>> about the outcome of this algorithm. I've tested with my local system, and all
>>> works well, because the route cache is well behaved, and the sd value always
>>> works out to be very small, so ip_rt_gc_elasticity is used. So I've been
>>> working through some scenarios by hand to see what this looks like using larger
>>> numbers. If i assume ip_rt_gc_interval is 60, and rt_hash_log is 17, my sample
>>> count here is 7864320 samples per run. If within that sample 393216 (about 4%)
>>> of the buckets have one entry on the chain, and all the rest are zeros, my hand
>>> calculations result in a standard deviation of approximately 140 and an average
>>> of .4. That imples that in that sample set any one chain could be almost 500
>>> entires long before it triggered a cache rebuld. Does that seem reasonable?
>>>
>> if rt_hash_log is 17, and interval is 60, then you should scan (60 <<
>> 17)/300 slots. That's 26214 slots. (ie 20% of the 2^17 slots)
>>
>> I have no idea how you can have sd = 140, even if scaled by (1 << 3)
>> with slots being empty or with one entry only...
>>
> I don't either, that was my concern :).
>
>> If 4% of your slots have one element, then average length is 0.04 :)
>>
> Yes, and the average worked out properly, which is why I was concerned.
>
> If you take an even simpler case, like you state above (I admit I miseed the
> /300 part of the sample, but no matter).
>
> samples = 26214
> Assume each sample has a chain length of 1
>
> sum = 26214 * (1 << 3) = 209712
> sum2 = sum * sum = s09712 * 209712 = 43979122944
> avg = sum / samples = 209712 / 26214 = 8 (correct)
> sd = sqrt(sum2 / samples - avg*avg) = sqrt(43979122944/26214 - 64) = 1295
> sd >> 3 = 1295.23 >> 3 = 161
>
>
> Clearly, given the assumption that every chain in the sample set has 1 entry,
> giving us an average of one, the traditional method of computing standard
> deviation should have yielded an sd of 0 exactly, since every sample was
> precisely the average. However, the math above gives us something significantly
> larger. I'm hoping I missed something, but I don't think I have.
>
Famous last sentence ;)
You made some errors in your hand calculations.
sum2 is the sum of squares. Its not sum * sum.
If all slots have one entry, all "lengths" are (1<<3),
and their 'square scaled by 6' is (1 << 6) . So sum2 = 26214 * (1 << 6) = 1677696
avg = sum / samples = 209712 / 26214 = (1 << 3)
sd = sqrt(sum2 / samples - avg*avg) = sqrt(64 - 64) = 0 (this is what we expected)
Now if you have 4 % of slots with one entry, and 96 % that are empty,
you should have
/* real maths */
avg = 0.04
sd = sqrt(0.04 - 0.04*0.04) = sqrt(0.0384) = 0.195959
avg + 4*sd = 0.82
/* fixed point math */
sum = 0.04 * 26214 * (1<<3) = 1048 * (1<<3) = 8384
sum2 = 1048 * (1 << 6) = 67072
avg << 3 = 8384/26214 = 0 (with 3 bits for fractional part, we do have rounding error)
sd << 3 = sqrt(67072/26214 - 0) = 1
(avg + 4*sd) << 3 = 4 -> final result is 4>>3 = 0 (expected)
Now if 50% of slots have one entry, we get :
/* real maths */
avg = 0.5
sd = sqrt(0.5 - 0.5*0.5) = sqrt(0.25) = 0.5
avg + 4*sd = 2.5
/* fixed point math */
sum = 0.5 * 26214 * (1<<3) = 104856
sum2 = 13107 * (1<<6) = 838848
avg << 3 = 104856/26214 = 4
sd << 3 = sqrt(838848/26214 - 4*4) = sqrt(32 - 16) = 4
(avg + 4*sd) << 3 = 20 -> final result is 20>>3 = 2 (expected)
Hope this helps
next prev parent reply other threads:[~2008-10-07 5:13 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-29 19:12 [PATCH] net: implement emergency route cache rebulds when gc_elasticity is exceeded Neil Horman
2008-09-29 20:22 ` Eric Dumazet
2008-09-29 20:27 ` Neil Horman
2008-09-29 21:00 ` Eric Dumazet
2008-09-29 22:38 ` Neil Horman
2008-09-30 6:02 ` Eric Dumazet
2008-09-30 11:23 ` Neil Horman
2008-09-30 14:10 ` David Miller
2008-09-30 17:16 ` Eric Dumazet
2008-09-30 18:42 ` Neil Horman
2008-10-02 7:16 ` Evgeniy Polyakov
2008-10-02 13:14 ` Neil Horman
2008-10-01 18:08 ` Neil Horman
2008-10-02 5:01 ` Bill Fink
2008-10-02 6:56 ` Eric Dumazet
2008-10-02 8:15 ` Eric Dumazet
2008-10-02 14:20 ` Eric Dumazet
2008-10-03 0:31 ` Neil Horman
2008-10-03 20:36 ` Neil Horman
2008-10-06 10:49 ` Eric Dumazet
2008-10-06 13:14 ` Neil Horman
2008-10-06 20:54 ` Neil Horman
2008-10-06 21:21 ` Eric Dumazet
2008-10-06 22:52 ` Neil Horman
2008-10-07 5:13 ` Eric Dumazet [this message]
2008-10-07 10:54 ` Neil Horman
2008-10-13 18:26 ` Neil Horman
2008-10-16 6:55 ` David Miller
2008-10-16 9:19 ` Eric Dumazet
2008-10-16 21:18 ` David Miller
2008-10-16 11:41 ` Neil Horman
2008-10-16 12:25 ` Eric Dumazet
2008-10-16 16:36 ` Neil Horman
2008-10-16 23:35 ` Neil Horman
2008-10-17 4:53 ` Eric Dumazet
2008-10-17 5:23 ` David Miller
2008-10-17 5:03 ` Stephen Hemminger
2008-10-17 5:06 ` Stephen Hemminger
2008-10-17 10:39 ` Neil Horman
[not found] ` <48F8806A.6090306@cosmosbay.com>
[not found] ` <20081017152328.GB23591@hmsreliant.think-freely.org>
[not found] ` <48F8AFBE.5080503@cosmosbay.com>
2008-10-17 20:44 ` Neil Horman
2008-10-18 0:54 ` Neil Horman
2008-10-18 4:36 ` Eric Dumazet
2008-10-18 13:30 ` Neil Horman
2008-10-20 0:07 ` Neil Horman
2008-10-20 8:12 ` Eric Dumazet
2008-10-27 19:28 ` David Miller
2008-10-02 7:13 ` Evgeniy Polyakov
2008-09-30 14:08 ` David Miller
2008-09-30 14:08 ` David Miller
2008-09-30 17:47 ` Eric Dumazet
2008-10-05 3:26 ` Herbert Xu
2008-10-05 4:45 ` Andrew Dickinson
2008-10-05 17:34 ` David Miller
2008-10-05 18:06 ` Andrew Dickinson
2008-10-06 4:21 ` Herbert Xu
2008-10-06 10:50 ` Neil Horman
2008-10-06 11:02 ` Herbert Xu
2008-10-06 12:43 ` Neil Horman
2008-09-30 14:17 ` Denis V. Lunev
2008-09-30 14:35 ` Neil Horman
2008-09-30 14:49 ` Denis V. Lunev
2008-10-05 3:17 ` Herbert Xu
2008-10-05 3:20 ` Herbert Xu
2008-10-06 0:52 ` Neil Horman
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=48EAEFF9.1000606@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=billfink@mindspring.com \
--cc=davem@davemloft.net \
--cc=jmorris@namei.org \
--cc=johnpol@2ka.mipt.ru \
--cc=kaber@trash.net \
--cc=kuznet@ms2.inr.ac.ru \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.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).