Re: [RFC 06/10] Reclaim memory from blocked kernel stacks
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: 2026-08-28 15:10:36
Also in:
linux-mm, linux-rt-devel, lkml
On 2026-08-28 15:59:47 [+0200], Peter Zijlstra wrote:
quoted
quoted
+ + The wakeup latency of tasks with reclaimed stacks may increase, + especially while the system is under memory pressure.It says *may* increase and on RT it _definitely_ will increase since there is a kworker involved not to mention the memory allocation itself. Anyway. This either needs to stay away from PREEMPT_RT or find a way to exclude at the very least mlock()ed tasks. Did lockdep see this?It should have. They're taking spinlock inside raw_spinlock and lockdep should very much warn about that by default.
Yes. My point was that this was hidden from lockdep.
quoted
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.THREAD_SIZE_ORDER 2 THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) that makes for 4 pages.
Oh. I wasn't aware that we have 16kib stacks these days. But looking
at it we have it now for over 10 years… Judging from 6538b8ea886e4
("x86_64: expand kernel stack to 16K") it might be temporary and things
are better now? Arm64 has a different story according to 845ad05ec31e0
("arm64: Change kernel stack size to 16K"). Risc-V also mentions "for
now" in 0cac21b02ba5f ("riscv: use 16KB kernel stack on 64-bit").
I just booted my XFS kvm box and did things and 8KiB works so far.
quoted
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.That would still be a 12k memset with IRQs-disabled and rq->lock held.
Right, because the stack grew a bit. Probably still cheaper compared to the other things done here ;)
quoted
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.Right, so you can FREEZE the task, unmap its stack and then thaw it or something. But there should be a definite opt-out on all this, because taking faults on your stack will be horrible.
Definitely. Not something for the currently visible app.
Not to mention you'll suffer wakeup latencies while frozen.
Right but you would use it under memory pressure and steal the stack from the most idle tasks rather from everyone.
This all really sounds like what should be addressed is this insane number of tasks rather than trying to cope with the consequences of that.
Sebastian