alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
Subsystems (2)
PATCH 1/1 alloc_tag: Handle incomplete bulk allocations in vm_module_tags_populate
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.
--- lib/alloc_tag.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
lib/alloc_tag.c +12 -3
@@ -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 ) {
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Andrew Morton
maintainerQuoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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.
Andrew Morton
maintainerQuoted 14 lines · On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto retry bulk allocations for the remaining memory instead.
Quoted 7 lines
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 <[email protected]>
A Closes: link will presumably help with the above info. checkpatch now warns about the absence of a Closes:
Quoted 21 lines · Andrew Morton
Quoted 18 lines · On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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.
Quoted 6 lines
Quoted 3 lines
...
Reported-by Janghyuck Kim <[email protected]>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.
Quoted 24 lines · T.J. Mercier
Quoted 23 lines · Andrew Morton
Quoted 20 lines · On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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.
...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reported-by Janghyuck Kim <[email protected]>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?"
Quoted 38 lines · Kent Overstreet
Quoted 24 lines · T.J. Mercier
Quoted 23 lines · Andrew Morton
Quoted 20 lines · On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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.
...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reported-by Janghyuck Kim <[email protected]>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?
Quoted 7 lines
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?
Suren Baghdasaryan
Acked-byQuoted 49 lines · T.J. Mercier
Quoted 38 lines · Kent Overstreet
Quoted 24 lines · T.J. Mercier
Quoted 23 lines · Andrew Morton
Quoted 20 lines · On Wed, 9 Apr 2025 14:08:48 -0700 Andrew Morton <[email protected]>…
Quoted 11 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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.
...
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Reported-by Janghyuck Kim <[email protected]>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?
Quoted 7 lines
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?"
Quoted 5 lines
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:
With that added:
Quoted 10 lines · Andrew Morton
Quoted 7 lines · On Wed, 9 Apr 2025 19:54:47 +0000 "T.J. Mercier" <[email protected]> wrote:
alloc_pages_bulk_nodemay partially succeed and allocate fewer than the requestednr_pages. There are several conditions under which this can occur, but we have encountered the case whereCONFIG_PAGE_OWNERis enabled causing all bulk allocations to always fallback to single page allocations due to commit187ad460b841("mm/page_alloc: avoid page allocator recursion with pagesets.lock held").
Quoted 8 lines
Quoted 4 lines
Currently
vm_module_tags_populateimmediately fails whenalloc_pages_bulk_nodereturns fewer than the requested number of pages. This patch causesvm_module_tags_populateto 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