linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-mm@kvack.org, Pasha Tatashin <pasha.tatashin@soleen.com>
Subject: Re: [PATCH 3/5] fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE
Date: Tue, 6 May 2025 18:53:22 -0700	[thread overview]
Message-ID: <20250506185322.cd87ba823030024061b5ae77@linux-foundation.org> (raw)
In-Reply-To: <20250506-fork-fixes-v1-3-bd35b63f0f1b@linaro.org>

On Tue, 06 May 2025 09:57:55 +0200 Linus Walleij <linus.walleij@linaro.org> wrote:

> From: Pasha Tatashin <pasha.tatashin@soleen.com>
> 
> In many places number of pages in the stack is detremined via
> (THREAD_SIZE / PAGE_SIZE). There is also a BUG_ON() that ensures that
> (THREAD_SIZE / PAGE_SIZE) is indeed equal to vm_area->nr_pages.
> 
> Consistently use vm_area->nr_pages to determine the actual number
> of pages allocated in the stack instead, so it is clear what is
> going on here.
> 
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> Link: https://lore.kernel.org/20240311164638.2015063-5-pasha.tatashin@soleen.com
> [Rebased, also skipped intermediary helper variable nr_pages]

I like

[linus.walleij@linaro.org: rebased, also skipped intermediary helper variable nr_pages]

> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -254,9 +254,7 @@ static int memcg_charge_kernel_stack(struct vm_struct *vm_area)
>  	int ret;
>  	int nr_charged = 0;
>  
> -	BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE);
> -
> -	for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) {
> +	for (i = 0; i < vm_area->nr_pages; i++) {

Well, constants are fast and small.  I assume this will add a few
instructions and a bit of runtime overhead?

>  		ret = memcg_kmem_charge_page(vm_area->pages[i], GFP_KERNEL, 0);
>  		if (ret)
>  			goto err;
> @@ -518,7 +516,7 @@ static void account_kernel_stack(struct task_struct *tsk, int account)
>  		struct vm_struct *vm_area = task_stack_vm_area(tsk);
>  		int i;
>  
> -		for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
> +		for (i = 0; i < vm_area->nr_pages; i++)
>  			mod_lruvec_page_state(vm_area->pages[i], NR_KERNEL_STACK_KB,
>  					      account * (PAGE_SIZE / 1024));
>  	} else {



  reply	other threads:[~2025-05-07  1:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06  7:57 [PATCH 0/5] fork: Page operation cleanups in the fork code Linus Walleij
2025-05-06  7:57 ` [PATCH 1/5] fork: Clean-up ifdef logic around stack allocation Linus Walleij
2025-05-06  7:57 ` [PATCH 2/5] fork: Clean-up naming of vm_strack/vm_struct variables in vmap stacks code Linus Walleij
2025-05-07  1:51   ` Andrew Morton
2025-05-06  7:57 ` [PATCH 3/5] fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE Linus Walleij
2025-05-07  1:53   ` Andrew Morton [this message]
2025-05-07 12:38     ` Linus Walleij
2025-05-06  7:57 ` [PATCH 4/5] fork: check charging success before zeroing stack Linus Walleij
2025-05-06  7:57 ` [PATCH 5/5] fork: zero vmap stack using clear_page() instead of memset() Linus Walleij

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=20250506185322.cd87ba823030024061b5ae77@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.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