Files
unkernel/kernel/patches/linux
pi0x 45a024e879 kernel: let busy workqueue workers finish before kernel threads park on SMP, and serve a requested grace period first, so that a park cycle right after a netns teardown no longer fails (#76)
On the SMP kernel a workqueue worker in the middle of an item could wait
for kernel threads that had already parked, never reach its own park
point, and end the cycle with -EBUSY naming it. A netns teardown's
cleanup_net() does that: it waits for grace periods, the expedited
grace-period worker and other work items. A cycle started right after an
`unshare -n` exit failed 13 times in 15 on 2 CPUs and 12 in 15 on 4; beside
a loop of netns teardowns 22 of 30 and 20 of 30 failed. Docker's
containers (#59) make such teardowns routine in Debian guests.

- The TREE_RCU grace-period kthread parks only while no grace period is
  in progress or requested, so that a kernel thread in synchronize_rcu()
  or rcu_barrier() can reach its park point (a fixup of the park points
  patch).
- Between the user and the kernel-thread phases kwparkd waits, at most
  HZ/2, until every workqueue worker is idle (in TASK_IDLE), while every
  kernel thread still runs (kw_park_settle_work(), a fixup of the arch
  patch).

With both, every cycle of those runs passed (120 on 2 and 4 CPUs). An idle
cycle's median went from 17.9 ms to 0.3 ms on 2 CPUs; a cycle that waits
for a teardown takes 60-230 ms. kwtest's park check is unchanged (2-5 ms
mean). parking.md describes the settle step and the grace-period rule.

Based on Martin Brook's patches on the android branch of
martinbrook/unkernel (cc78ca9, 4849ed9). His settle step also ran
rcu_barrier() and waited only for workers in an uninterruptible sleep:
here the barrier cost 40-50 ms in every cycle, and a worker between two
waits (runnable) ended the wait early, so 11 of 15 cycles still failed.

Co-authored-by: Pooya Parsa <pooya@pi0.io>
Co-authored-by: Martin Brook <martin.brook100@googlemail.com>
2026-11-28 22:33:07 +01:00
..