Re: [RFC 06/10] Reclaim memory from blocked kernel stacks
From: Peter Zijlstra
Date: Fri Aug 28 2026 - 08:08:58 EST
On Thu, Aug 27, 2026 at 04:29:44PM -0700, David Stevens wrote:
> @@ -4295,8 +4296,6 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> if (!ttwu_state_match(p, state, &success))
> break;
>
> - trace_sched_waking(p);
> -
> /*
> * Ensure we load p->on_rq _after_ p->state, otherwise it would
> * be possible to, falsely, observe p->on_rq == 0 and get stuck
> @@ -4320,8 +4319,18 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> * A similar smp_rmb() lives in __task_needs_rq_lock().
> */
> smp_rmb();
> - if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags))
> + if (READ_ONCE(p->on_rq) && ttwu_runnable(p, wake_flags)) {
> + trace_sched_waking(p);
> + break;
> + }
> +
> + if (!ensure_stack_is_present(p, &need_deferred_repopulate)) {
> + WRITE_ONCE(p->__state, TASK_STACK_RECLAIM);
> + do_deferred_repopulate_wake = need_deferred_repopulate;
> break;
> + }
> +
> + trace_sched_waking(p);
>
> /*
> * Ensure we load p->on_cpu _after_ p->on_rq, otherwise it would be
Don't move that tracepoint. That's simply lying about how long it takes
to wake up the task.