dscpPolicy: prevent cache overflow
It has been a long standing bug that eventually the dscp
policy socket cache fills up and stops working for new
sockets.
The intent was this would be periodically cleared on some
sort of LRU basis from userspace.
But why bother?
We convert from hash[cookie:u64] to array[cookie % X].
If the cache misses, we simply recalculate and replace it.
This also allows us to reduce the size of the map:
we go from 1024 entries to 32 entries per cpu (likely ~8) so 256.
We're unlikely to have many active flows on any given cpu
at any given time - and the chance of collision is reasonable,
so thrashing should be minimal.
Longer term it would probably be even better to use
socket local storage for this purpose...
(Note: we don't have generation ids on the policy,
so we still don't apply new policy / policy changes
to old sockets... oh, well...)
Test: TreeHugger, atest CtsNetTestCases:android.net.cts.DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia570aec44e399d326c165b271ae4dad01f8aa100
2 files changed