Linux real-time development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "David Stevens" <stevensd@google.com>
Cc: linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: Re: [RFC 06/10] Reclaim memory from blocked kernel stacks
Date: Thu, 27 Aug 2026 23:53:18 +0000	[thread overview]
Message-ID: <20260827235319.0D5D41F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827232948.2520558-7-stevensd@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Memory leak of `obj_cgroup` in the `copy_process()` error path.
- [Medium] Repopulating kernel stack pages with `NUMA_NO_NODE` silently bypasses the task's NUMA mempolicy.
--

commit 19da8486785bcd64133ab34a423835e83ba21942
Author: David Stevens <stevensd@google.com>
Subject: Reclaim memory from blocked kernel stacks

This commit introduces a mechanism to reclaim unused portions of kernel
stacks for blocked tasks. It adds scheduler hooks and a new task flag
PF_RECLAIMABLE_STACK to manage safe stack reclaim and repopulation.

> diff --git a/kernel/fork.c b/kernel/fork.c
> index 6acad0038b78e..9b2cc3d01dd10 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
[ ... ]
> @@ -460,6 +462,7 @@ static int alloc_thread_stack_node(struct task_struct *tsk, int node)
>  
>  		tsk->stack_vm_area = vm_area;
>  		tsk->stack = stack;
> +		add_to_stack_shrinker(tsk, node);
>  		return 0;
>  	}

[Severity: High]
Does this leak the obj_cgroup reference in the copy_process() error path?

When dup_task_struct() completes successfully, we acquire an obj_cgroup
reference inside add_to_stack_shrinker(). However, if a subsequent step in
copy_process() fails (such as copy_mm()), the kernel jumps to the 
bad_fork_free label:

kernel/fork.c:copy_process() {
    ...
    bad_fork_free:
        WRITE_ONCE(p->__state, TASK_DEAD);
        exit_task_stack_account(p);
        put_task_stack(p);
        delayed_free_task(p);
    ...
}

Because delayed_free_task() directly frees the task without calling
__put_task_struct() or remove_from_stack_shrinker(), it seems the
obj_cgroup reference is permanently leaked, preventing the associated
mem_cgroup from being destroyed.

> diff --git a/kernel/stack_shrinker.c b/kernel/stack_shrinker.c
> new file mode 100644
> index 0000000000000..d7b1a7dfa7165
> --- /dev/null
> +++ b/kernel/stack_shrinker.c
[ ... ]
> +static bool repopulate_stack(struct task_struct *tsk, bool is_deferred,
> +			     struct llist_head *fail_list)
> +{
[ ... ]
> +	if (is_deferred) {
> +		gfp_t gfp = GFP_KERNEL_ACCOUNT | __GFP_ZERO;
[ ... ]
> +		for (; nr_allocated < num_missing_pages; nr_allocated++) {
> +			pages[nr_allocated] = alloc_pages_node_noprof(node, gfp, 0);

[Severity: Medium]
Can this silently bypass the task's NUMA mempolicy?

If a task has no specific node forced, the target node is set to NUMA_NO_NODE. 

Calling alloc_pages_node_noprof() with NUMA_NO_NODE unconditionally ignores
the task's explicit NUMA mempolicy (like MPOL_BIND or MPOL_INTERLEAVE) and
allocates from the current CPU's local node instead.

Should this branch and use alloc_pages_noprof() when the target node is 
NUMA_NO_NODE to properly respect the policy?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827232948.2520558-1-stevensd@google.com?part=6

  reply	other threads:[~2026-08-27 23:53 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 23:29 [RFC 00/10] Reclaimable kernel stacks David Stevens
2026-08-27 23:29 ` [RFC 01/10] Add !MEMCG memcg_list_lru_alloc implementation David Stevens
2026-08-27 23:29 ` [RFC 02/10] mm/vmalloc: Skip vmallocinfo NUMA stats for VM_SPARSE David Stevens
2026-08-27 23:29 ` [RFC 03/10] fork: refactor vmap stack alloc/free into helpers David Stevens
2026-08-27 23:29 ` [RFC 04/10] mm: vmalloc: support creating aligned vm areas David Stevens
2026-08-27 23:29 ` [RFC 05/10] fork: allocate reclaimable stacks with VM_SPARSE David Stevens
2026-08-27 23:29 ` [RFC 06/10] Reclaim memory from blocked kernel stacks David Stevens
2026-08-27 23:53   ` sashiko-bot [this message]
2026-08-28 11:54   ` Peter Zijlstra
2026-08-28 12:01   ` Peter Zijlstra
2026-08-28 12:04   ` Peter Zijlstra
2026-08-29  0:18     ` David Stevens
2026-08-28 12:41   ` Peter Zijlstra
2026-08-28 12:57   ` Peter Zijlstra
2026-08-28 23:33     ` David Stevens
2026-08-28 13:36   ` Sebastian Andrzej Siewior
2026-08-28 13:59     ` Peter Zijlstra
2026-08-28 14:25       ` Peter Zijlstra
2026-08-28 15:58         ` Sebastian Andrzej Siewior
2026-08-28 15:10       ` Sebastian Andrzej Siewior
2026-08-28 19:08         ` Steven Rostedt
2026-08-28 19:13           ` Steven Rostedt
2026-08-28 19:17             ` Steven Rostedt
2026-08-28 20:50       ` David Stevens
2026-08-28 21:17     ` David Stevens
2026-08-27 23:29 ` [RFC 07/10] Reclaim stacks via a shrinker David Stevens
2026-08-27 23:29 ` [RFC 08/10] Set PF_RECLAIMABLE_STACK in various places David Stevens
2026-08-27 23:43   ` sashiko-bot
2026-08-28  6:33   ` K Prateek Nayak
2026-08-27 23:29 ` [RFC 09/10] x86: Enable reclaimable stacks David Stevens
2026-08-27 23:29 ` [RFC 10/10] arm64: " David Stevens
2026-08-28 12:47 ` [RFC 00/10] Reclaimable kernel stacks Peter Zijlstra
2026-08-28 14:33   ` Steven Rostedt
2026-08-28 14:35     ` Peter Zijlstra
2026-08-28 14:45       ` Peter Zijlstra
2026-08-28 16:10         ` Steven Rostedt
2026-08-28 17:58   ` David Stevens

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260827235319.0D5D41F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=stevensd@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox