osd: Let the event loop run between PG peering calculations #197

Merged
vitalif merged 1 commits from koolkhel/vitastor:osd-peering-yield into master 2026-11-28 11:19:20 +03:00
Contributor

Description

handle_peers() (src/osd/osd_peering.cpp:24) calls ringloop->wakeup() after each calc_object_states(). But wakeup() only makes ring_loop_t::loop() run the consumers again in the same pass (src/util/ringloop.cpp:94-169), and completions are read only at the start of a pass. So an OSD that is primary for several PGs whose LISTs are all in computes all of them back to back. Pings, timers and the etcd lease renewal wait for the whole series.

With EC 8+2 and ~850k objects per PG, one calculation takes 1-3 s, and a weight change made one OSD primary for up to 11 peering PGs at once. Peers dropped that OSD by osd_ping_timeout, which started peering again, and the cluster kept re-peering.

The change: after each calculation, arm a 1 ms timer (tfd->set_timer(), the same one-shot timer as the pause between reshard chunks) and start the next calculation when it fires. The loop then reads what came in during the calculation, and the reads and sends that starts have time to finish. A NOP is not enough: a ping needs an epoll event, a recvmsg completion and a send. In a test the recvmsg completion came one drain after the NOP's, so the number of passes to wait for depends on kernel timing.

  • Flush and recovery in handle_peers() still run while the timer is pending.
  • Each calculation still blocks for its full length. This is not interruptible peering (item 4 of the plan in #123). It only stops the calculations of several PGs from adding up.
  • No option: results are the same. Each calculation is followed by a 1 ms yield, so when N PGs are ready at once, the last one becomes active up to N ms later.
  • It is independent of the store.
  • It complements #180, which shortens one calculation. #123 moves the calculation to a thread.

Found: seen in a run. On a cluster with ~850k objects per PG, OSDs stopped answering pings for many seconds while they peered several PGs, peers dropped them, and the PGs peered again in a loop.

Tested:

  • test_peering_yields_between_pgs (osd_test): two PGs become ready at once. One loop pass computes only one of them, and the next pass computes nothing until the timer fires. It fails on master.
  • osd_test and test_pg_chaos (100 seeds) pass. osd_test_fixture_t now runs its timer manager on the virtual clock, as test_pg_chaos does, and pump() advances it 1 ms while the timer is armed.
  • Ping round trip on a real ring_loop_t + epoll_manager_t while 11 calculations of 600k-object EC 8+2 PGs run (~0.8 s each, i7-12700H): the longest ping wait is 9.06 s on master (all 11 calculations) and 0.94 s with this change (one calculation); the 11 calculations take the same 9.06 s total (median of 3 runs, -O3 -g). A 1 ms io_uring timeout instead of the timer gives the same numbers.

Contributor Name

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

CLA

### Description handle_peers() (src/osd/osd_peering.cpp:24) calls ringloop->wakeup() after each calc_object_states(). But wakeup() only makes ring_loop_t::loop() run the consumers again in the same pass (src/util/ringloop.cpp:94-169), and completions are read only at the start of a pass. So an OSD that is primary for several PGs whose LISTs are all in computes all of them back to back. Pings, timers and the etcd lease renewal wait for the whole series. With EC 8+2 and ~850k objects per PG, one calculation takes 1-3 s, and a weight change made one OSD primary for up to 11 peering PGs at once. Peers dropped that OSD by osd_ping_timeout, which started peering again, and the cluster kept re-peering. The change: after each calculation, arm a 1 ms timer (`tfd->set_timer()`, the same one-shot timer as the pause between reshard chunks) and start the next calculation when it fires. The loop then reads what came in during the calculation, and the reads and sends that starts have time to finish. A NOP is not enough: a ping needs an epoll event, a recvmsg completion and a send. In a test the recvmsg completion came one drain after the NOP's, so the number of passes to wait for depends on kernel timing. - Flush and recovery in handle_peers() still run while the timer is pending. - Each calculation still blocks for its full length. This is not interruptible peering (item 4 of the plan in #123). It only stops the calculations of several PGs from adding up. - No option: results are the same. Each calculation is followed by a 1 ms yield, so when N PGs are ready at once, the last one becomes active up to N ms later. - It is independent of the store. - It complements #180, which shortens one calculation. #123 moves the calculation to a thread. Found: seen in a run. On a cluster with ~850k objects per PG, OSDs stopped answering pings for many seconds while they peered several PGs, peers dropped them, and the PGs peered again in a loop. Tested: - test_peering_yields_between_pgs (osd_test): two PGs become ready at once. One loop pass computes only one of them, and the next pass computes nothing until the timer fires. It fails on master. - osd_test and test_pg_chaos (100 seeds) pass. osd_test_fixture_t now runs its timer manager on the virtual clock, as test_pg_chaos does, and pump() advances it 1 ms while the timer is armed. - Ping round trip on a real ring_loop_t + epoll_manager_t while 11 calculations of 600k-object EC 8+2 PGs run (~0.8 s each, i7-12700H): the longest ping wait is 9.06 s on master (all 11 calculations) and 0.94 s with this change (one calculation); the 11 calculations take the same 9.06 s total (median of 3 runs, -O3 -g). A 1 ms io_uring timeout instead of the timer gives the same numbers. ### 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-27 22:46:04 +03:00
handle_peers() called ringloop->wakeup() after each calc_object_states(),
but wakeup() only makes ring_loop_t::loop() run the consumers again in the
same pass, before any completion is read. So an OSD that is primary for
several peering PGs calculated all of them back to back without answering
pings or renewing its etcd lease, and peers dropped it by osd_ping_timeout,
which started the peering again. Submit a 1 ms ring timeout after each
calculation and start the next one when it completes: the loop then reads
the completions that came during the calculation, and the reads and sends
they start get time to finish, however many passes that takes.
koolkhel force-pushed osd-peering-yield from 682224f9f6 to a8a7c41983 2026-11-27 23:16:03 +03:00 Compare
koolkhel force-pushed osd-peering-yield from a8a7c41983 to 7f843c8a5a 2026-11-28 00:25:22 +03:00 Compare
koolkhel added 1 commit 2026-11-28 02:42:06 +03:00
The ring loop frees a ring_data_t before it runs the callback, so the
pointer to the timeout's slot could never be used to cancel it. Only
whether a timeout is in flight matters.
koolkhel added 1 commit 2026-11-28 09:17:00 +03:00
Without an SQE the yield falls back to wakeup(), so the next calculation
runs in the same loop pass. If that fallback stopped, peering would stall.
koolkhel force-pushed osd-peering-yield from ce3e8e2f75 to 66733b1369 2026-11-28 11:01:19 +03:00 Compare
vitalif merged commit 54b8d2c0ed into master 2026-11-28 11:19:20 +03:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#197
No description provided.