Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: hu.shengming@zte.com.cn
Cc: akpm@linux-foundation.org, urezki@gmail.com, linux-mm@kvack.org,
	baoquan.he@linux.dev, zhang.run@zte.com.cn
Subject: Re: [PATCH] mm/vmalloc: skip clearing page array in vfree()
Date: Sun, 6 Dec 2026 15:48:50 +0100	[thread overview]
Message-ID: <axV10ioMMM-fvQME@milan> (raw)
In-Reply-To: <20261203165513646NPjqNhu4nc7m3b7zg9wRc@zte.com.cn>

On Thu, Dec 03, 2026 at 04:55:13PM +0800, hu.shengming@zte.com.cn wrote:
> From: Shengming Hu <hu.shengming@zte.com.cn>
> 
> vm_area_free_pages() clears freed entries in vm->pages[].
> This is needed by vrealloc() shrink, which retains the array,
> but not by vfree(), which immediately releases it with kvfree().
> 
> Add a clear_pages parameter to skip clearing when the page
> array will be freed. Pass false from vfree() and true
> from vrealloc() shrink.
> 
> On a 64-bit system with 4 KiB pages, this avoids 2 MiB of
> unnecessary writes when freeing a 1 GiB vmalloc allocation.
> 
> Note that Baoquan He's ongoing VM_SPARSE series adds new
> callers of this helper. These callers should pass true
> to preserve the existing clearing behavior.
> 
> Link: https://lore-kernel.gnuweeb.org/linux-mm/20261129150755.191662-1-baoquan.he@linux.dev/
> 
> Signed-off-by: Shengming Hu <hu.shengming@zte.com.cn>
> ---
>  mm/vmalloc.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
> 
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 320e981188c9..fa402bd38879 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3541,14 +3541,15 @@ void vfree_atomic(const void *addr)
>   * @vm: the vm_struct containing the pages
>   * @start_idx: first page index to free (inclusive)
>   * @end_idx: last page index to free (exclusive)
> + * @clear_pages: whether to clear freed vm->pages[] entries
>   *
>   * Free pages [start_idx, end_idx) updating NR_VMALLOC stat accounting.
> - * Freed vm->pages[] entries are set to NULL.
> + * If @clear_pages is true, freed vm->pages[] entries are set to NULL.
>   * Caller is responsible for unmapping (vunmap_range) and KASAN
>   * poisoning before calling this.
>   */
>  static void vm_area_free_pages(struct vm_struct *vm, unsigned long start_idx,
> -			       unsigned long end_idx)
> +			       unsigned long end_idx, bool clear_pages)
>  {
>  	unsigned long i;
> 
> @@ -3558,8 +3559,10 @@ static void vm_area_free_pages(struct vm_struct *vm, unsigned long start_idx,
>  	}
>  	free_pages_bulk(vm->pages + start_idx, end_idx - start_idx);
> 
> -	for (i = start_idx; i < end_idx; i++)
> -		vm->pages[i] = NULL;
> +	if (clear_pages) {
> +		for (i = start_idx; i < end_idx; i++)
> +			vm->pages[i] = NULL;
> +	}
>  }
>
IMO, it is not worth to introduce the flag in order to control
clean-ups. If you free 1GB of vmalloc allocation, bypassing a
clean up probably would not gain much.

And it looks like you already tested this where the delta is
small.

--
Uladzislau Rezki


      parent reply	other threads:[~2026-12-06 14:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  8:55 [PATCH] mm/vmalloc: skip clearing page array in vfree() hu.shengming
2026-12-03 10:26 ` Dev Jain
2026-12-03 13:05   ` hu.shengming
2026-12-03 14:37 ` Baoquan He
2026-12-03 15:37   ` hu.shengming
2026-12-03 16:32     ` Baoquan He
2026-12-04  8:55 ` sashiko-bot
2026-12-06 14:48 ` Uladzislau Rezki [this message]

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=axV10ioMMM-fvQME@milan \
    --to=urezki@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=hu.shengming@zte.com.cn \
    --cc=linux-mm@kvack.org \
    --cc=zhang.run@zte.com.cn \
    /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