[RFC] random: use per lcore state
Stephen Hemminger
stephen at networkplumber.org
Thu Sep 7 01:00:04 CEST 2023
On Wed, 6 Sep 2023 22:02:54 +0200
Mattias Rönnblom <hofors at lysator.liu.se> wrote:
> On 2023-09-06 19:20, Stephen Hemminger wrote:
> > Move the random number state into thread local storage.
>
> Me and Morten discussed TLS versus other alternatives in some other
> thread. The downside of TLS that Morten pointed out, from what I recall,
> is that lazy initialization is *required* (since the number of threads
> is open-ended), and the data ends up in non-huge page memory. It was
> also unclear to me what the memory footprint implications would be,
> would large per-lcore data structures be put in TLS. More specifically,
> if they would be duplicated across all threads, even non-lcore threads.
But current method is unsafe on non-lcore threads.
Two non-lcore threads calling rte_rand() will clash on state without
any locking protection.
Also, right now the array is sized at 129 entries to allow for the
maximum number of lcores. When the maximum is increased to 512 or 1024
the problem will get worse.
More information about the dev
mailing list