]> git.ipfire.org Git - thirdparty/systemd.git/commit
loop-util: wait a random time before trying again
authorLennart Poettering <lennart@poettering.net>
Tue, 13 Oct 2020 12:37:39 +0000 (14:37 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Oct 2020 12:58:28 +0000 (14:58 +0200)
commitb202ec20688cd0abe3f4b2e35cf6002c8bc45189
tree60cbec38307f2eace1d88e6d5c6722484a462634
parent786e3a52a24d0317d20d3c8839db59b7bad6d0b7
loop-util: wait a random time before trying again

Let's try to make collisions when multiple clients want to use the same
device less likely, by sleeping a random time on collision.

The loop device allocation protocol is inherently collision prone:
first, a program asks which is the next free loop device, then it tries
to acquire it, in a separate, unsynchronized setp. If many peers do this
all at the same time, they'll likely all collide when trying to
acquire the device, so that they need to ask for a free device again and
again.

Let's make this a little less prone to collisions, reducing the number
of failing attempts: whenever we notice a collision we'll now wait
short and randomized time, making it more likely another peer succeeds.

(This also adds a similar logic when retrying LOOP_SET_STATUS64, but
with a slightly altered calculation, since there we definitely want to
wait a bit, under all cases)
src/shared/loop-util.c