Linus Torvalds writes: (Summary)
..this doesn't really ratelimit anything, because you can just start a thousand threads, and they all end up being rate-limited, but they all just sleep for 10ms each, so you can get a hundred thousand accesses per second anyway.
per second anyway.
To fix that, you can either:
To fix that, you can either:
- just make it return -EAGAIN instead of sleeping (which probably just works fine and doesn't break anything and is simple) just works fine and doesn't break anything and is simple) - add a per-user mutex, and do the usleep inside of it, so that anybody who tries to do a thousand threads will just be serialized by the mutex.
the mutex.
Note that the mutex needs to be per-user, because otherwise it will be a DoS for the other users.
a DoS for the other users.
Of course, to avoid *another* DoS, the mutex should probably be interruptible, and return -EAGAIN, so that you don't have a thousand thread waiting f
[...]
+ usleep_range(10000, 10000);..this doesn't really ratelimit anything, because you can just start a thousand threads, and they all end up being rate-limited, but they all just sleep for 10ms each, so you can get a hundred thousand accesses per second anyway.
per second anyway.
To fix that, you can either:
To fix that, you can either:
- just make it return -EAGAIN instead of sleeping (which probably just works fine and doesn't break anything and is simple) just works fine and doesn't break anything and is simple) - add a per-user mutex, and do the usleep inside of it, so that anybody who tries to do a thousand threads will just be serialized by the mutex.
the mutex.
Note that the mutex needs to be per-user, because otherwise it will be a DoS for the other users.
a DoS for the other users.
Of course, to avoid *another* DoS, the mutex should probably be interruptible, and return -EAGAIN, so that you don't have a thousand thread waiting f