Limit number of waiters for atomics.wait and notify to 2^32-1
Categories
(Core :: JavaScript: WebAssembly, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox65 | --- | affected |
People
(Reporter: lth, Unassigned)
References
Details
| Reporter | ||
Comment 1•7 years ago
|
||
| Reporter | ||
Comment 2•7 years ago
|
||
Note, this is not P5 because P5 means "won't really do this" but it doesn't block anything really.
| Reporter | ||
Updated•4 years ago
|
Updated•3 years ago
|
Comment 3•11 months ago
|
||
Per [1] we're supposed to trap if the number of waiters is >= 2^32. I think the reason for this is because the wasm instructions are 32-bit unsigned and cannot express waking up more waiters than 2^32-1. This was not an issue before waitAsync because the number of waiters would be bound by the number of threads. Now with waitAsync, this case can actually happen.
[1] https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md#wait
Updated•11 months ago
|
Comment 4•3 months ago
•
|
||
Need a second opinion on this matter from the JS team:
- JS and Wasm share the same code here, so adding a limit in Wasm will affect JS in some way
- I cannot find the similar constraint in JS world, e.g. at https://tc39.es/ecma262/#sec-dowait or https://tc39.es/ecma262/#sec-addwaiter -- I guess it is not an issue for instructions/operations reason
- The current implementation and data structure is not capable to to maintain even a small fraction of 2^32 -- it is linked list.
- Looks like Atomics.waitAsync is implemented, make this bug an urgent matter (based on the description)
Do we need to change the linked list data structure to something like a hashmap or b-tree?
Comment 5•3 months ago
|
||
With regards to Atomics.waitAsync, and whether it makes this urgent: my understanding is that prior to Atomics.waitAsync the maximum number of waiters was bounded by the number of threads, which was never going to get anywhere close to 2^32, and now it's instead bound by the number of Promise objects we can allocate, which ... let's be honest, is also not going to get anywhere close to 2^32. A single PromiseObject is ... 56 bytes? (Shape pointer, slots pointer, elements pointer, and four slots.) So 2^32 promises is more than 200 GB of memory even before you start considering resolution functions and so on. That's going to hit other implementation limits first.
(Note also that the order in which waiters are inserted matters for the purposes of waking up the right ones, so a hashmap probably wouldn't work.)
Comment 6•3 months ago
|
||
let's be honest, is also not going to get anywhere close to 2^32... That's going to hit other implementation limits first.
I thought along that line too. What will be right way to proceed here though? will closing this issue as WONTFIX be enough, or we want to add some asserts
the order in which waiters are inserted matters for the purposes of waking up the right ones
atomics_notify_impl just has a loop that just filters out based on byteOffset != waiter->offset(), so I was thinking hashmap + list, which may allow us to count waiters per location
Comment 7•3 months ago
|
||
Note that we currently do some Clever Tricks involving the doubly linked list (it's possible for a timeout to resolve a waiter even after the associated SAB has been freed). I would hold off on modifying the data structures until we get some concrete evidence that perf is an issue.
In terms of the right way to proceed: if there's somewhere convenient to add a release-assert, that would be reasonable. I guess we don't necessarily have O(1) access to the number of waiters, though.
Description
•