From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Barry Song <21cnbao@gmail.com>,
akpm@linux-foundation.org, linux-mm@kvack.org
Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org,
Barry Song <v-songbaohua@oppo.com>,
Uladzislau Rezki <urezki@gmail.com>,
Sumit Semwal <sumit.semwal@linaro.org>,
John Stultz <jstultz@google.com>,
Maxime Ripard <mripard@kernel.org>
Subject: Re: [PATCH RFC] mm/vmap: map contiguous pages in batches whenever possible
Date: Mon, 1 Dec 2025 11:36:33 +0100 [thread overview]
Message-ID: <ed7701d7-28c8-4760-9ccb-f22fc1e9528e@kernel.org> (raw)
In-Reply-To: <20251122090343.81243-1-21cnbao@gmail.com>
On 11/22/25 10:03, Barry Song wrote:
> From: Barry Song <v-songbaohua@oppo.com>
>
> In many cases, the pages passed to vmap() may include
> high-order pages—for example, the systemheap often allocates
> pages in descending order: order 8, then 4, then 0. Currently,
> vmap() iterates over every page individually—even the pages
> inside a high-order block are handled one by one. This patch
> detects high-order pages and maps them as a single contiguous
> block whenever possible.
>
> Another possibility is to implement a new API, vmap_sg().
> However, that change seems to be quite large in scope.
>
> When vmapping a 128MB dma-buf using the systemheap,
> this RFC appears to make system_heap_do_vmap() 16× faster:
>
> W/ patch:
> [ 51.363682] system_heap_do_vmap took 2474000 ns
> [ 53.307044] system_heap_do_vmap took 2469008 ns
> [ 55.061985] system_heap_do_vmap took 2519008 ns
> [ 56.653810] system_heap_do_vmap took 2674000 ns
>
> W/o patch:
> [ 8.260880] system_heap_do_vmap took 39490000 ns
> [ 32.513292] system_heap_do_vmap took 38784000 ns
> [ 82.673374] system_heap_do_vmap took 40711008 ns
> [ 84.579062] system_heap_do_vmap took 40236000 ns
>
> Cc: Uladzislau Rezki <urezki@gmail.com>
> Cc: Sumit Semwal <sumit.semwal@linaro.org>
> Cc: John Stultz <jstultz@google.com>
> Cc: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> ---
> mm/vmalloc.c | 49 +++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 43 insertions(+), 6 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 0832f944544c..af2e3e8c052a 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -642,6 +642,34 @@ static int vmap_small_pages_range_noflush(unsigned long addr, unsigned long end,
> return err;
> }
>
> +static inline int get_vmap_batch_order(struct page **pages,
> + unsigned int stride,
> + int max_steps,
> + unsigned int idx)
These fit into less lines.
ideally
\t\tunsigned int stride, int max_steps, unsigned int idx)
> +{
int order, nr_pages, i;
struct page *base;
But I think you can just drop "base". And order.
> + /*
> + * Currently, batching is only supported in vmap_pages_range
> + * when page_shift == PAGE_SHIFT.
> + */
> + if (stride != 1)
> + return 0;
> +
> + struct page *base = pages[idx];
> + if (!PageHead(base))
> + return 0;
> +
> + int order = compound_order(base);
> + int nr_pages = 1 << order;
You can drop the head check etc and simply do
nr_pages = compound_nr(pages[idx]);
if (nr_pages == 1)
return 0;
Which raises the question: are these things folios? I assume not.
> +
> + if (max_steps < nr_pages)
> + return 0;
> +
> + for (int i = 0; i < nr_pages; i++)
> + if (pages[idx + i] != base + i)
> + return 0;
if (num_pages_contiguous(&pages[idx], nr_pages) == nr_pages)
return compound_order(pages[idx]);
return 0;
--
Cheers
David
next prev parent reply other threads:[~2025-12-01 10:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-22 9:03 [PATCH RFC] mm/vmap: map contiguous pages in batches whenever possible Barry Song
2025-11-27 16:53 ` Uladzislau Rezki
2025-11-27 20:43 ` Barry Song
2025-12-01 11:08 ` Uladzislau Rezki
2025-12-01 22:05 ` Barry Song
2025-12-02 14:03 ` Uladzislau Rezki
2025-12-01 10:36 ` David Hildenbrand (Red Hat) [this message]
2025-12-01 21:39 ` Barry Song
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=ed7701d7-28c8-4760-9ccb-f22fc1e9528e@kernel.org \
--to=david@kernel.org \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=jstultz@google.com \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mripard@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=urezki@gmail.com \
--cc=v-songbaohua@oppo.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;
as well as URLs for NNTP newsgroup(s).