The first allocation that brings a device within a quarter of its
maxMemoryAllocationCount starts a thread that gives back the guest RAM
chunks imported ahead that no object took. An allocation that reached
the limit before that thread ran waited only for the free thread's
posted frees, then was refused while those chunks still held the
device's allocations: Metal would have made it.
Allocations now counts each give-back under way (GiveBack, dropped by
its thread once it gave back what it found, or with the closure where
the thread never started). An allocation that finds the limit reached
starts the give-back where one is due, waits for those under way, then
for the posted frees, then asks again before refusing. The give-back's
thread takes the RAMs', chunks' and memory's locks, none of which an
allocation is made under, and allocates nothing, so the wait ends.
Verified: allocations::tests::an_allocation_at_the_limit_waits_for_the_
give_back_under_way (CPU, fails without the fix: refused), and
host_ram_device's an_allocation_at_the_limit_waits_for_the_untaken_
chunks_to_go_back on lavapipe (fails at the test commit before this
one), with the give-back wait counted. RUNTIME behaviour: an allocation
at the limit may now wait for the give-back thread instead of failing
with ERROR_TOO_MANY_OBJECTS.
(cherry picked from commit d93fecb6add984b46cb1363fc6b69b2e2e014639)