linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
@ 2025-04-09 19:54 T.J. Mercier
  2025-04-09 21:08 ` Andrew Morton
  0 siblings, 1 reply; 8+ messages in thread
From: T.J. Mercier @ 2025-04-09 19:54 UTC (permalink / raw)
  To: Suren Baghdasaryan, Kent Overstreet, Andrew Morton
  Cc: T.J. Mercier, Janghyuck Kim, linux-mm, linux-kernel

alloc_pages_bulk_node may partially succeed and allocate fewer than the
requested nr_pages. There are several conditions under which this can
occur, but we have encountered the case where CONFIG_PAGE_OWNER is
enabled causing all bulk allocations to always fallback to single page
allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
allocator recursion with pagesets.lock held").

Currently vm_module_tags_populate immediately fails when
alloc_pages_bulk_node returns fewer than the requested number of pages.
This patch causes vm_module_tags_populate to retry bulk allocations for
the remaining memory instead.

Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>
Signed-off-by: T.J. Mercier <tjmercier@google.com>
---
 lib/alloc_tag.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index 1d893e313614..25ecc1334b67 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -422,11 +422,20 @@ static int vm_module_tags_populate(void)
 		unsigned long old_shadow_end = ALIGN(phys_end, MODULE_ALIGN);
 		unsigned long new_shadow_end = ALIGN(new_end, MODULE_ALIGN);
 		unsigned long more_pages;
-		unsigned long nr;
+		unsigned long nr = 0;
 
 		more_pages = ALIGN(new_end - phys_end, PAGE_SIZE) >> PAGE_SHIFT;
-		nr = alloc_pages_bulk_node(GFP_KERNEL | __GFP_NOWARN,
-					   NUMA_NO_NODE, more_pages, next_page);
+		while (nr < more_pages) {
+			unsigned long allocated;
+
+			allocated = alloc_pages_bulk_node(GFP_KERNEL | __GFP_NOWARN,
+				NUMA_NO_NODE, more_pages - nr, next_page + nr);
+
+			if (!allocated)
+				break;
+			nr += allocated;
+		}
+
 		if (nr < more_pages ||
 		    vmap_pages_range(phys_end, phys_end + (nr << PAGE_SHIFT), PAGE_KERNEL,
 				     next_page, PAGE_SHIFT) < 0) {
-- 
2.49.0.504.g3bcea36a83-goog



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 19:54 [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate T.J. Mercier
@ 2025-04-09 21:08 ` Andrew Morton
  2025-04-09 21:11   ` Andrew Morton
  2025-04-09 21:48   ` T.J. Mercier
  0 siblings, 2 replies; 8+ messages in thread
From: Andrew Morton @ 2025-04-09 21:08 UTC (permalink / raw)
  To: T.J. Mercier
  Cc: Suren Baghdasaryan, Kent Overstreet, Janghyuck Kim, linux-mm,
	linux-kernel

On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:

> alloc_pages_bulk_node may partially succeed and allocate fewer than the
> requested nr_pages. There are several conditions under which this can
> occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> enabled causing all bulk allocations to always fallback to single page
> allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> allocator recursion with pagesets.lock held").
> 
> Currently vm_module_tags_populate immediately fails when
> alloc_pages_bulk_node returns fewer than the requested number of pages.
> This patch causes vm_module_tags_populate to retry bulk allocations for
> the remaining memory instead.

Please describe the userspace-visible runtime effects of this change.  In a way
which permits a user who is experiencing some problem can recognize that this
patch will address that problem.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 21:08 ` Andrew Morton
@ 2025-04-09 21:11   ` Andrew Morton
  2025-04-09 21:51     ` T.J. Mercier
  2025-04-09 21:48   ` T.J. Mercier
  1 sibling, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2025-04-09 21:11 UTC (permalink / raw)
  To: T.J. Mercier, Suren Baghdasaryan, Kent Overstreet, Janghyuck Kim,
	linux-mm, linux-kernel

On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:

> On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
> 
> > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > requested nr_pages. There are several conditions under which this can
> > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > enabled causing all bulk allocations to always fallback to single page
> > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > allocator recursion with pagesets.lock held").
> > 
> > Currently vm_module_tags_populate immediately fails when
> > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > This patch causes vm_module_tags_populate to retry bulk allocations for
> > the remaining memory instead.
> 
> Please describe the userspace-visible runtime effects of this change.  In a way
> which permits a user who is experiencing some problem can recognize that this
> patch will address that problem.
>
> ...
>
> Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>

A Closes: link will presumably help with the above info.  checkpatch
now warns about the absence of a Closes:



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 21:08 ` Andrew Morton
  2025-04-09 21:11   ` Andrew Morton
@ 2025-04-09 21:48   ` T.J. Mercier
  1 sibling, 0 replies; 8+ messages in thread
From: T.J. Mercier @ 2025-04-09 21:48 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Suren Baghdasaryan, Kent Overstreet, Janghyuck Kim, linux-mm,
	linux-kernel

On Wed, Apr 9, 2025 at 2:08 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
>
> > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > requested nr_pages. There are several conditions under which this can
> > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > enabled causing all bulk allocations to always fallback to single page
> > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > allocator recursion with pagesets.lock held").
> >
> > Currently vm_module_tags_populate immediately fails when
> > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > This patch causes vm_module_tags_populate to retry bulk allocations for
> > the remaining memory instead.
>
> Please describe the userspace-visible runtime effects of this change.  In a way
> which permits a user who is experiencing some problem can recognize that this
> patch will address that problem.

The userspace visible effect is that memory allocation profiling will
get disabled when the bulk allocation is incomplete, for example:
[   14.297583] [9:       modprobe:  465] Failed to allocate memory for
allocation tags in the module scsc_wlan. Memory allocation profiling
is disabled!
[   14.299339] [9:       modprobe:  465] modprobe: Failed to insmod
'/vendor/lib/modules/scsc_wlan.ko' with args '': Out of memory


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 21:11   ` Andrew Morton
@ 2025-04-09 21:51     ` T.J. Mercier
  2025-04-09 21:57       ` Kent Overstreet
  0 siblings, 1 reply; 8+ messages in thread
From: T.J. Mercier @ 2025-04-09 21:51 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Suren Baghdasaryan, Kent Overstreet, Janghyuck Kim, linux-mm,
	linux-kernel

On Wed, Apr 9, 2025 at 2:11 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
>
> > On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
> >
> > > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > > requested nr_pages. There are several conditions under which this can
> > > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > > enabled causing all bulk allocations to always fallback to single page
> > > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > > allocator recursion with pagesets.lock held").
> > >
> > > Currently vm_module_tags_populate immediately fails when
> > > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > > This patch causes vm_module_tags_populate to retry bulk allocations for
> > > the remaining memory instead.
> >
> > Please describe the userspace-visible runtime effects of this change.  In a way
> > which permits a user who is experiencing some problem can recognize that this
> > patch will address that problem.
> >
> > ...
> >
> > Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>
>
> A Closes: link will presumably help with the above info.  checkpatch
> now warns about the absence of a Closes:

Hi Andrew, This was reported on our internal bug tracker so there is
no public link I can provide here. If it's better not to add a
Reported-by in this case, then I will do that in the future.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 21:51     ` T.J. Mercier
@ 2025-04-09 21:57       ` Kent Overstreet
  2025-04-09 22:10         ` T.J. Mercier
  0 siblings, 1 reply; 8+ messages in thread
From: Kent Overstreet @ 2025-04-09 21:57 UTC (permalink / raw)
  To: T.J. Mercier
  Cc: Andrew Morton, Suren Baghdasaryan, Janghyuck Kim, linux-mm, linux-kernel

On Wed, Apr 09, 2025 at 02:51:18PM -0700, T.J. Mercier wrote:
> On Wed, Apr 9, 2025 at 2:11 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > > On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
> > >
> > > > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > > > requested nr_pages. There are several conditions under which this can
> > > > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > > > enabled causing all bulk allocations to always fallback to single page
> > > > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > > > allocator recursion with pagesets.lock held").
> > > >
> > > > Currently vm_module_tags_populate immediately fails when
> > > > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > > > This patch causes vm_module_tags_populate to retry bulk allocations for
> > > > the remaining memory instead.
> > >
> > > Please describe the userspace-visible runtime effects of this change.  In a way
> > > which permits a user who is experiencing some problem can recognize that this
> > > patch will address that problem.
> > >
> > > ...
> > >
> > > Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>
> >
> > A Closes: link will presumably help with the above info.  checkpatch
> > now warns about the absence of a Closes:
> 
> Hi Andrew, This was reported on our internal bug tracker so there is
> no public link I can provide here. If it's better not to add a
> Reported-by in this case, then I will do that in the future.

In that case perhaps cut and paste the info from your internal bug
tracker?

Commit messages can include quite a bit more than just a short
description of the commit, when it's relevant - e.g. I try to include
the literal log of the oops being fixed when appropriate.

It really helps when looking at things weeks or months later and trying
to remember "ok, exactly what was that code path I need to watch out
for?"


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 21:57       ` Kent Overstreet
@ 2025-04-09 22:10         ` T.J. Mercier
  2025-04-09 22:24           ` Suren Baghdasaryan
  0 siblings, 1 reply; 8+ messages in thread
From: T.J. Mercier @ 2025-04-09 22:10 UTC (permalink / raw)
  To: Kent Overstreet
  Cc: Andrew Morton, Suren Baghdasaryan, Janghyuck Kim, linux-mm, linux-kernel

On Wed, Apr 9, 2025 at 2:57 PM Kent Overstreet
<kent.overstreet@linux.dev> wrote:
>
> On Wed, Apr 09, 2025 at 02:51:18PM -0700, T.J. Mercier wrote:
> > On Wed, Apr 9, 2025 at 2:11 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > > On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
> > > >
> > > > > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > > > > requested nr_pages. There are several conditions under which this can
> > > > > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > > > > enabled causing all bulk allocations to always fallback to single page
> > > > > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > > > > allocator recursion with pagesets.lock held").
> > > > >
> > > > > Currently vm_module_tags_populate immediately fails when
> > > > > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > > > > This patch causes vm_module_tags_populate to retry bulk allocations for
> > > > > the remaining memory instead.
> > > >
> > > > Please describe the userspace-visible runtime effects of this change.  In a way
> > > > which permits a user who is experiencing some problem can recognize that this
> > > > patch will address that problem.
> > > >
> > > > ...
> > > >
> > > > Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>
> > >
> > > A Closes: link will presumably help with the above info.  checkpatch
> > > now warns about the absence of a Closes:
> >
> > Hi Andrew, This was reported on our internal bug tracker so there is
> > no public link I can provide here. If it's better not to add a
> > Reported-by in this case, then I will do that in the future.
>
> In that case perhaps cut and paste the info from your internal bug
> tracker?
>
> Commit messages can include quite a bit more than just a short
> description of the commit, when it's relevant - e.g. I try to include
> the literal log of the oops being fixed when appropriate.
>
> It really helps when looking at things weeks or months later and trying
> to remember "ok, exactly what was that code path I need to watch out
> for?"

Agreed, it would have been better to include this. I think the
modprobe errors I followed up with would be good to append to the
commit message.

Shall I send a v2?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
  2025-04-09 22:10         ` T.J. Mercier
@ 2025-04-09 22:24           ` Suren Baghdasaryan
  0 siblings, 0 replies; 8+ messages in thread
From: Suren Baghdasaryan @ 2025-04-09 22:24 UTC (permalink / raw)
  To: T.J. Mercier
  Cc: Kent Overstreet, Andrew Morton, Janghyuck Kim, linux-mm, linux-kernel

On Wed, Apr 9, 2025 at 3:11 PM T.J. Mercier <tjmercier@google.com> wrote:
>
> On Wed, Apr 9, 2025 at 2:57 PM Kent Overstreet
> <kent.overstreet@linux.dev> wrote:
> >
> > On Wed, Apr 09, 2025 at 02:51:18PM -0700, T.J. Mercier wrote:
> > > On Wed, Apr 9, 2025 at 2:11 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> > > >
> > > > On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> > > >
> > > > > On Wed,  9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <tjmercier@google.com> wrote:
> > > > >
> > > > > > alloc_pages_bulk_node may partially succeed and allocate fewer than the
> > > > > > requested nr_pages. There are several conditions under which this can
> > > > > > occur, but we have encountered the case where CONFIG_PAGE_OWNER is
> > > > > > enabled causing all bulk allocations to always fallback to single page
> > > > > > allocations due to commit 187ad460b841 ("mm/page_alloc: avoid page
> > > > > > allocator recursion with pagesets.lock held").
> > > > > >
> > > > > > Currently vm_module_tags_populate immediately fails when
> > > > > > alloc_pages_bulk_node returns fewer than the requested number of pages.
> > > > > > This patch causes vm_module_tags_populate to retry bulk allocations for
> > > > > > the remaining memory instead.
> > > > >
> > > > > Please describe the userspace-visible runtime effects of this change.  In a way
> > > > > which permits a user who is experiencing some problem can recognize that this
> > > > > patch will address that problem.
> > > > >
> > > > > ...
> > > > >
> > > > > Reported-by: Janghyuck Kim <janghyuck.kim@samsung.com>
> > > >
> > > > A Closes: link will presumably help with the above info.  checkpatch
> > > > now warns about the absence of a Closes:
> > >
> > > Hi Andrew, This was reported on our internal bug tracker so there is
> > > no public link I can provide here. If it's better not to add a
> > > Reported-by in this case, then I will do that in the future.
> >
> > In that case perhaps cut and paste the info from your internal bug
> > tracker?
> >
> > Commit messages can include quite a bit more than just a short
> > description of the commit, when it's relevant - e.g. I try to include
> > the literal log of the oops being fixed when appropriate.
> >
> > It really helps when looking at things weeks or months later and trying
> > to remember "ok, exactly what was that code path I need to watch out
> > for?"
>
> Agreed, it would have been better to include this. I think the
> modprobe errors I followed up with would be good to append to the
> commit message.
>
> Shall I send a v2?

Yes please and add the userspace visible effect you posted earlier along with:

Fixes: 0f9b685626da "alloc_tag: populate memory for module tags as needed"

With that added:

Acked-by: Suren Baghdasaryan <surenb@google.com>


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-04-09 22:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-09 19:54 [PATCH] alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate T.J. Mercier
2025-04-09 21:08 ` Andrew Morton
2025-04-09 21:11   ` Andrew Morton
2025-04-09 21:51     ` T.J. Mercier
2025-04-09 21:57       ` Kent Overstreet
2025-04-09 22:10         ` T.J. Mercier
2025-04-09 22:24           ` Suren Baghdasaryan
2025-04-09 21:48   ` T.J. Mercier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox