From: Usama Anjum <usama.anjum@arm.com>
To: Zi Yan <ziy@nvidia.com>
Cc: usama.anjum@arm.com, Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Uladzislau Rezki <urezki@gmail.com>,
Nick Terrell <terrelln@fb.com>, David Sterba <dsterba@suse.com>,
Vishal Moola <vishal.moola@gmail.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Ryan.Roberts@arm.com,
david.hildenbrand@arm.com
Subject: Re: [PATCH v3 2/3] vmalloc: Optimize vfree
Date: Wed, 25 Mar 2026 14:34:36 +0000 [thread overview]
Message-ID: <c379889b-42eb-44ea-8cf4-1f29a45b6ce1@arm.com> (raw)
In-Reply-To: <1D88CFF0-8A74-413F-9A6A-39E27B760AE1@nvidia.com>
<snip>
>> +void free_pages_bulk(struct page **page_array, unsigned long nr_pages)
>> +{
>> + unsigned long start_pfn = 0, pfn;
>> + unsigned long i, nr_contig = 0;
>> +
>> + for (i = 0; i < nr_pages; i++) {
>> + pfn = page_to_pfn(page_array[i]);
>> + if (!nr_contig) {
>> + start_pfn = pfn;
>> + nr_contig = 1;
>> + } else if (start_pfn + nr_contig != pfn) {
>> + __free_contig_range(start_pfn, nr_contig);
>> + start_pfn = pfn;
>> + nr_contig = 1;
>> + cond_resched();
>> + } else {
>> + nr_contig++;
>> + }
>> + }
>> + if (nr_contig)
>> + __free_contig_range(start_pfn, nr_contig);
>> +}
>
> free_pages_bulk() assumes pages in page_array are sorted in PFN ascending order.
> I think it is worth documenting it, since without sorting, it can degrade
> back to the original implementation.
I'll add the kerneldoc comment.
>
>> +
>> /*
>> * This is the 'heart' of the zoned buddy allocator.
>> */
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index c607307c657a6..e9b3d6451e48b 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -3459,19 +3459,13 @@ void vfree(const void *addr)
>>
>> if (unlikely(vm->flags & VM_FLUSH_RESET_PERMS))
>> vm_reset_perms(vm);
>> - for (i = 0; i < vm->nr_pages; i++) {
>> - struct page *page = vm->pages[i];
>>
>> - BUG_ON(!page);
>> - /*
>> - * High-order allocs for huge vmallocs are split, so
>> - * can be freed as an array of order-0 allocations
>> - */
>> - if (!(vm->flags & VM_MAP_PUT_PAGES))
>> - mod_lruvec_page_state(page, NR_VMALLOC, -1);
>> - __free_page(page);
>> - cond_resched();
>> + if (!(vm->flags & VM_MAP_PUT_PAGES)) {
>> + for (i = 0; i < vm->nr_pages; i++)
>> + mod_lruvec_page_state(vm->pages[i], NR_VMALLOC, -1);
>> }
>> + free_pages_bulk(vm->pages, vm->nr_pages);
>> +
>
> stats is updated before any page is freed. It is better to mention
> it in the commit message.
I'll mention it.
>
>> kvfree(vm->pages);
>> kfree(vm);
>> }
>> --
>> 2.47.3
>
> Otherwise, LGTM.
>
> Acked-by: Zi Yan <ziy@nvidia.com>
>
> Best Regards,
> Yan, Zi
>
Thanks,
Usama
next prev parent reply other threads:[~2026-03-25 14:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 13:35 [PATCH v3 0/3] mm: Free contiguous order-0 pages efficiently Muhammad Usama Anjum
2026-03-24 13:35 ` [PATCH v3 1/3] mm/page_alloc: Optimize free_contig_range() Muhammad Usama Anjum
2026-03-24 14:46 ` Zi Yan
2026-03-24 15:22 ` David Hildenbrand
2026-03-24 17:14 ` Zi Yan
2026-03-25 14:06 ` Muhammad Usama Anjum
2026-03-24 20:56 ` David Hildenbrand (Arm)
2026-03-25 14:11 ` Muhammad Usama Anjum
2026-03-24 13:35 ` [PATCH v3 2/3] vmalloc: Optimize vfree Muhammad Usama Anjum
2026-03-24 14:55 ` Zi Yan
2026-03-25 8:56 ` Uladzislau Rezki
2026-03-25 15:02 ` Muhammad Usama Anjum
2026-03-25 16:16 ` Uladzislau Rezki
2026-03-25 16:25 ` Muhammad Usama Anjum
2026-03-25 16:34 ` David Hildenbrand (Arm)
2026-03-25 16:49 ` Uladzislau Rezki
2026-03-25 14:34 ` Usama Anjum [this message]
2026-03-25 10:05 ` David Hildenbrand (Arm)
2026-03-25 14:26 ` Muhammad Usama Anjum
2026-03-25 15:01 ` David Hildenbrand (Arm)
2026-03-24 13:35 ` [PATCH v3 3/3] mm/page_alloc: Optimize __free_contig_frozen_range() Muhammad Usama Anjum
2026-03-24 15:06 ` Zi Yan
2026-03-25 10:14 ` David Hildenbrand (Arm)
2026-03-25 16:03 ` Muhammad Usama Anjum
2026-03-25 19:52 ` Zi Yan
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=c379889b-42eb-44ea-8cf4-1f29a45b6ce1@arm.com \
--to=usama.anjum@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=Ryan.Roberts@arm.com \
--cc=akpm@linux-foundation.org \
--cc=bpf@vger.kernel.org \
--cc=david.hildenbrand@arm.com \
--cc=david@kernel.org \
--cc=dsterba@suse.com \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=terrelln@fb.com \
--cc=urezki@gmail.com \
--cc=vbabka@kernel.org \
--cc=vishal.moola@gmail.com \
--cc=ziy@nvidia.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