Subscribe to EPOLLOUT only while a send waits for it in no-io_uring mode #144

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:no-uring-epollout-on-demand into master
Contributor

Description

QEMU runs the fd handlers of a client without io_uring in a level-triggered loop (no EPOLLET), so the permanent EPOLLOUT subscription added in b88e2ea6 calls the write handler on every pass while the socket is writable, and an idle client spins at 100% CPU. Subscribe to EPOLLOUT only when a send parks on a full socket, and unsubscribe on EPOLLOUT. A missed edge is not possible: epoll_manager_t::set_fd_handler() polls the fd when it registers it and delivers EPOLLOUT if the socket is already writable.

Tested: new test_no_uring_epollout_on_demand in test_msgr_stop. It drives the messenger without a ringloop through a level-triggered poll() loop, the way QEMU calls the handlers. Without the fix, the write handler is called on all 100 idle passes and the test fails. With it, there are no idle calls, a send to a peer that doesn't read parks with EPOLLOUT subscribed, and it completes once the peer drains, with the subscription dropped again. Also fio with -no_io_uring=1 against a local 3-OSD cluster (run_3osds.sh): tests/test_no_uring.sh, and a 512M 4M-block write with -verify=crc32c, where sends parked on EAGAIN and resumed.

A separate issue in the same function, not fixed here: in handle_peer_epoll(), the EPOLLOUT branch looks the client up with clients.find(cl->client_id) after read_requests(). read_requests() can stop the client, and stop_client() can delete cl (msgr_stop.cpp), so that reads freed memory. Saving cl->client_id before the EPOLLIN branch avoids it.

Contributor Name

Yury Luneff (MIND Software LLC, https://mindsw.io)

CLA

### Description QEMU runs the fd handlers of a client without io_uring in a level-triggered loop (no EPOLLET), so the permanent EPOLLOUT subscription added in b88e2ea6 calls the write handler on every pass while the socket is writable, and an idle client spins at 100% CPU. Subscribe to EPOLLOUT only when a send parks on a full socket, and unsubscribe on EPOLLOUT. A missed edge is not possible: epoll_manager_t::set_fd_handler() polls the fd when it registers it and delivers EPOLLOUT if the socket is already writable. Tested: new test_no_uring_epollout_on_demand in test_msgr_stop. It drives the messenger without a ringloop through a level-triggered poll() loop, the way QEMU calls the handlers. Without the fix, the write handler is called on all 100 idle passes and the test fails. With it, there are no idle calls, a send to a peer that doesn't read parks with EPOLLOUT subscribed, and it completes once the peer drains, with the subscription dropped again. Also fio with -no_io_uring=1 against a local 3-OSD cluster (run_3osds.sh): tests/test_no_uring.sh, and a 512M 4M-block write with -verify=crc32c, where sends parked on EAGAIN and resumed. A separate issue in the same function, not fixed here: in handle_peer_epoll(), the EPOLLOUT branch looks the client up with `clients.find(cl->client_id)` after read_requests(). read_requests() can stop the client, and stop_client() can delete `cl` (msgr_stop.cpp), so that reads freed memory. Saving `cl->client_id` before the EPOLLIN branch avoids it. ### Contributor Name Yury Luneff (MIND Software LLC, https://mindsw.io) ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-21 12:01:56 +03:00
QEMU runs the fd handlers of a client without io_uring in a level-triggered
loop, so a permanent EPOLLOUT subscription calls the write handler on every
pass and an idle client spins at 100% CPU. Subscribe only when a send parks
on a full socket and unsubscribe on EPOLLOUT.
Owner

Какой реальный юзкейс мы здесь решаем? Level-triggered как будто нет желания поддерживать.

Какой реальный юзкейс мы здесь решаем? Level-triggered как будто нет желания поддерживать.
Author
Contributor

Юзкейс — QEMU (или qemu-img) там, где io_uring_setup запрещён:

  • контейнер docker/podman с профилем seccomp по умолчанию;
  • ядро с kernel.io_uring_disabled=2;
  • ядро без io_uring.

Режим без io_uring у вас поддерживается: e4a7e9bf, test_no_uring.sh в run_tests.sh. Драйвер в этом случае сам уходит в запасной путь: «failed to create io_uring - I/O will be slower» и vitastor_c_create_qemu() (src/client/qemu_driver.c:695-699). А vitastor_c_create_qemu() регистрирует каждый сокет OSD в AioContext QEMU через aio_set_fd_handler (vitastor_c.cpp:87-103, vitastor_c_create_qemu_common). AioContext работает по уровню, это не мы его выбрали. После b88e2ea6 у сокета постоянно висит fd_write, поэтому QEMU зовёт его на каждом проходе цикла, пока сокет доступен на запись. Простаивающий процесс занимает 100 % ядра. Мерили на qemu-storage-daemon с экспортом vduse-blk и kernel.io_uring_disabled=2: 100 % в простое без этого PR, 0 % с ним, запись 1 ГиБ с проверкой crc32c проходит в обоих случаях. До e4a7e9bf тот же сценарий зависал на первой отправке в OSD.

Если не хочется поддерживать level-triggered в мессенджере, есть вариант меньше и в духе epoll_manager. В запасном пути драйвера создавать клиента через vitastor_c_create_epoll_json() и регистрировать в AioContext один fd — vitastor_c_epoll_get_fd(), обработчик чтения vitastor_c_epoll_handle_events(proxy, 0). Так уже сделано с uring_eventfd: qemu_driver.c:671-684, attach/detach — 807-814, 856-858, 880-882. Мессенджер тогда остаётся edge-triggered, EPOLLOUT из b88e2ea6 трогать не нужно. QEMU видит только epoll fd, а он читаем, только пока есть события. Изменения только в qemu_driver.c, этот PR тогда закрою. Переделать так?

Юзкейс — QEMU (или qemu-img) там, где io_uring_setup запрещён: - контейнер docker/podman с профилем seccomp по умолчанию; - ядро с kernel.io_uring_disabled=2; - ядро без io_uring. Режим без io_uring у вас поддерживается: e4a7e9bf, test_no_uring.sh в run_tests.sh. Драйвер в этом случае сам уходит в запасной путь: «failed to create io_uring - I/O will be slower» и `vitastor_c_create_qemu()` (src/client/qemu_driver.c:695-699). А `vitastor_c_create_qemu()` регистрирует каждый сокет OSD в AioContext QEMU через aio_set_fd_handler (vitastor_c.cpp:87-103, vitastor_c_create_qemu_common). AioContext работает по уровню, это не мы его выбрали. После b88e2ea6 у сокета постоянно висит fd_write, поэтому QEMU зовёт его на каждом проходе цикла, пока сокет доступен на запись. Простаивающий процесс занимает 100 % ядра. Мерили на qemu-storage-daemon с экспортом vduse-blk и kernel.io_uring_disabled=2: 100 % в простое без этого PR, 0 % с ним, запись 1 ГиБ с проверкой crc32c проходит в обоих случаях. До e4a7e9bf тот же сценарий зависал на первой отправке в OSD. Если не хочется поддерживать level-triggered в мессенджере, есть вариант меньше и в духе epoll_manager. В запасном пути драйвера создавать клиента через `vitastor_c_create_epoll_json()` и регистрировать в AioContext один fd — `vitastor_c_epoll_get_fd()`, обработчик чтения `vitastor_c_epoll_handle_events(proxy, 0)`. Так уже сделано с uring_eventfd: qemu_driver.c:671-684, attach/detach — 807-814, 856-858, 880-882. Мессенджер тогда остаётся edge-triggered, EPOLLOUT из b88e2ea6 трогать не нужно. QEMU видит только epoll fd, а он читаем, только пока есть события. Изменения только в qemu_driver.c, этот PR тогда закрою. Переделать так?
This pull request has changes conflicting with the target branch.
  • src/test/test_msgr_stop.cpp
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u no-uring-epollout-on-demand:koolkhel-no-uring-epollout-on-demand
git checkout koolkhel-no-uring-epollout-on-demand
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#144
No description provided.