[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aJST7TnermwROX41@tiehlicka>
Date: Thu, 7 Aug 2025 13:54:21 +0200
From: Michal Hocko <mhocko@...e.com>
To: "Uladzislau Rezki (Sony)" <urezki@...il.com>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>,
Vlastimil Babka <vbabka@...e.cz>, Baoquan He <bhe@...hat.com>,
LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 7/8] mm/vmalloc: Support non-blocking GFP flags in
__vmalloc_area_node()
On Thu 07-08-25 09:58:09, Uladzislau Rezki wrote:
> This patch makes __vmalloc_area_node() to correctly handle non-blocking
> allocation requests, such as GFP_ATOMIC and GFP_NOWAIT. Main changes:
>
> - Add a __GFP_HIGHMEM to gfp_mask only for blocking requests
> if there are no DMA constraints.
This begs for a more explanation. Why does __GFP_HIGHMEM matters? I
suspect this is due to kmapping of those pages but that could be done in
an atomic way. But in practice I do not think we really care about
highmem all that much for vmalloc. The vmalloc space is really tiny for
32b systems where highmem matters and failing vmalloc allocations due to
lack is of __GFP_HIGHMEM is hard to consider important if relevant at
all.
> - vmap_page_range() is wrapped by memalloc_noreclaim_save/restore()
> to avoid memory reclaim related operations that could sleep during
> page table setup or mapping pages.
>
> This is particularly important for page table allocations that
> internally use GFP_PGTABLE_KERNEL, which may sleep unless such
> scope restrictions are applied. For example:
>
> <snip>
> __pte_alloc_kernel()
> pte_alloc_one_kernel(&init_mm);
> pagetable_alloc_noprof(GFP_PGTABLE_KERNEL & ~__GFP_HIGHMEM, 0);
> <snip>
As I've said in several occations, I am not entirely happy about this
approach because it doesn't really guarantee atomicty. If any
architecture decides to use some sleeping locking down that path then
the whole thing just blows up. On the other hand this is mostly a
theoretical concern at this stage and this is a feature people have
been asking for a long time (especially from kvmalloc side) so better
good than perfect that his.
That being said, you are missing __kvmalloc_node_noprof,
__vmalloc_node_range_noprof (and maybe some more places) documentation
update.
> Note: in most cases, PTE entries are established only up to the level
> required by current vmap space usage, meaning the page tables are typically
> fully populated during the mapping process.
>
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@...il.com>
With the doc part fixed
Acked-by: Michal Hocko <mhocko@...e.com>
Thanks!
> ---
> mm/vmalloc.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 2424f80d524a..8a7eab810561 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3721,12 +3721,20 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> unsigned int nr_small_pages = size >> PAGE_SHIFT;
> unsigned int page_order;
> unsigned int flags;
> + bool noblock;
> int ret;
>
> array_size = (unsigned long)nr_small_pages * sizeof(struct page *);
> + noblock = !gfpflags_allow_blocking(gfp_mask);
>
> - if (!(gfp_mask & (GFP_DMA | GFP_DMA32)))
> - gfp_mask |= __GFP_HIGHMEM;
> + if (noblock) {
> + /* __GFP_NOFAIL and "noblock" flags are mutually exclusive. */
> + nofail = false;
> + } else {
> + /* Allow highmem allocations if there are no DMA constraints. */
> + if (!(gfp_mask & (GFP_DMA | GFP_DMA32)))
> + gfp_mask |= __GFP_HIGHMEM;
> + }
>
> /* Please note that the recursion is strictly bounded. */
> if (array_size > PAGE_SIZE) {
> @@ -3790,7 +3798,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> * page tables allocations ignore external gfp mask, enforce it
> * by the scope API
> */
> - if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO)
> + if (noblock)
> + flags = memalloc_noreclaim_save();
> + else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO)
> flags = memalloc_nofs_save();
> else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == 0)
> flags = memalloc_noio_save();
> @@ -3802,7 +3812,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> schedule_timeout_uninterruptible(1);
> } while (nofail && (ret < 0));
>
> - if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO)
> + if (noblock)
> + memalloc_noreclaim_restore(flags);
> + else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == __GFP_IO)
> memalloc_nofs_restore(flags);
> else if ((gfp_mask & (__GFP_FS | __GFP_IO)) == 0)
> memalloc_noio_restore(flags);
> --
> 2.39.5
>
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists