[Demo] Nested epoll fd avoid to call add_interest, because there is a global kernel lock when doing epoll_ctl #388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Cascading engine has a performance issue when used in multi-thread program.
Its
wait_for_events
will firstly callwait_for_fd
, and thenadd_interest
with one-shot.For epoll engine, the kernel
epoll_ctl
will compete in multi-threads to acquire one global mutex, if the fd it watches on is epoll fd. See https://elixir.bootlin.com/linux/v5.15.125/source/fs/eventpoll.c#L2130io_uring engine doesn't have this problem.
According to my observation, in a 24 threads program, the lock acquisition can consume as much as 80% CPU workload, which is totally unacceptable.
The solution is to use multi-shot poll to replace those
epoll_ctl
, so we need to keep tracks on the epoll fd.After applying this demo changes, the osq_lock has disappered. You can run this demo in your environment.
The demo has used a limited size of arrays (8 elements) to store fd, instead of map. Comparisons are also made.
The idea is that we should only allow a small number of nested epoll fd to be registered, and use array to reduce overhead in the I/O path.
Finally, this is just a demo. We need formal patch.