Re: [RFC 06/10] Reclaim memory from blocked kernel stacks

From: Sebastian Andrzej Siewior

Date: Mon Aug 31 2026 - 04:11:55 EST


On 2026-08-28 14:17:49 [-0700], David Stevens wrote:
> > Did lockdep see this?
>
> What are you referring to by "this"? I did stress testing with lockdep
> enabled and didn't see any errors, although I will admit the bulk of
> that stress testing was !PREEMPT_RT.

I am (was) just surprised that lockdep did not complain about the memory
allocation under the PI lock. It was pointed out in that thread later
that the new trylock usage could mask that.

> > If I understood the whole exercise correct then you have a kernel stack
> > of two pages and in best case you can unmap and release the second page
> > while the task is napping.
> >
> > What might be a tad simpler is to memset(,0,) the remaining part of the
> > stack. Since the stack is vmap-ed it should be swapped out on its own
> > without additional tricks. That memset() would help zram to compress
> > better so it uses less memory. ta-da.
> >
> > What also should be simpler (and I am not saying just to move you away
> > from the scheduler) is to have a shrinker which iterates over all tasks
> > which are marked for reclaim and then similar to swap just unmap both
> > stack pages and release the second page which is not used.
> > Upon wake up the task should create a page_fault which would be used to
> > allocate the second stack page and map the whole stack again.
> >
> > This sounds simpler.
>
> There is no swap for kernel memory, only user memory. I did contribute
> to some previous work that aimed to only only prepopulate one page of
> each kernel stack and then to dynamically fault in further pages as
> needed [1], but handling that architecturally and guaranteeing that
> memory is available when needed is difficult. Full-on swap to zram

but faulting it in while the task is running is sort of complicated
since the task might have page_faults disabled. This is what I missed
initially (the task is with disabled interrupts in the scheduler).

But unmap the stack while application is sleeping (via shrinker) and
fault it in via another thread on wake up should be doable.

Sebastian