Re: [PATCH v4 5/5] rust: workqueue: add ScopedWork for non-'static work items

From: Tejun Heo

Date: Fri Nov 27 2026 - 11:12:32 EST


Hello, Alice.

On Thu, Nov 26, 2026 at 12:43:07PM +0000, Alice Ryhl wrote:
> Of course, there may be other ways to enforce the non-reentrance
> conditions hold, which could let me get rid of the lifetime. But the
> lifetime is there to handle the cleanup before destroy_workqueue() is
> called case, so a percpu refcount does not come into play.

I didn't explain myself well. I'm not saying that the current scheme
doesn't work. My concern is how easy the interface is to use, and I wonder
whether taking workqueue lifetime out of the compiler-managed lifetime
rules could make it simpler. Something like the following:

- Every Rust work item and delayed work item is bound to one workqueue.

- A Rust workqueue has a percpu refcnt and each work item bound to it
holds a reference.

- Destroying the workqueue waits for the refcnt to reach zero. A leaked
work item then stalls workqueue destruction, which seems like an okay
failure mode.

Work items bound this way never move between workqueues, and neither
delayed work items nor ScopedWork would need the workqueue to be 'static
or carry its lifetime. This doesn't solve data or device lifetimes but it
decouples them from the workqueue's, and device accesses can use workqueue
destruction as the draining point.

We can add whatever is needed on the workqueue side to make draining work
well, e.g. an operation which expires a workqueue so that work items
queued on it afterwards are dropped without running, self-freeing ones
included.

Workqueue looks the way it does because it's C and leaves all lifetime
management to its users. Carrying the same model over to Rust and then
wrapping it for each use case seems like a missed opportunity. I don't
know Rust well, so I could just be blowing hot air.

Thanks.

--
tejun