... and make setting MADV_NOHUGEPAGE with madvise() into a no-op if THP is not enabled.
I discovered this issue when trying to use the tool CRIU to checkpoint and restore a container. Our running kernel is compiled without CONFIG_TRANSPARENT_HUGETABLES. CRIU parses the output of /proc/<pid>/smaps and saves the "nh" flag. When trying to restore the container, CRIU fails to restore the "nh" mappings, since madvise() MADV_NOHUGEPAGE always returns an error because CONFIG_TRANSPARENT_HUGETABLES is not defined.
These patches: - Avoid mapping MAP_STACK to VM_NOHUGEPAGE if !THP - Avoid returning an error when calling madvise() with MADV_NOHUGEPAGE if !THP
Signed-off-by: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com --- Changes in v2: - [Patch 1/2] Use '#ifdef' instead of '#if defined(...)' - [Patch 1/2] Add 'Fixes: c4608d1bf7c6...' - Create [Patch 2/2]
- Link to v1: https://lore.kernel.org/r/20250502-map-map_stack-to-vm_nohugepage-only-if-th...
--- Ignacio Moreno Gonzalez (2): mm: mmap: map MAP_STACK to VM_NOHUGEPAGE only if THP is enabled mm: madvise: no-op for MADV_NOHUGEPAGE if THP is disabled
include/linux/huge_mm.h | 6 ++++++ include/linux/mman.h | 2 ++ 2 files changed, 8 insertions(+) --- base-commit: fc96b232f8e7c0a6c282f47726b2ff6a5fb341d2 change-id: 20250428-map-map_stack-to-vm_nohugepage-only-if-thp-is-enabled-ce40a1de095d
Best regards,
From: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com
commit c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") maps the mmap option MAP_STACK to VM_NOHUGEPAGE. This is also done if CONFIG_TRANSPARENT_HUGETABLES is not defined. But in that case, the VM_NOHUGEPAGE does not make sense.
Fixes: c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") Cc: stable@vger.kernel.org Reviewed-by: Lorenzo Stoakes lorenzo.stoakes@oracle.com Reviewed-by: Yang Shi yang@os.amperecomputing.com Signed-off-by: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com --- include/linux/mman.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/linux/mman.h b/include/linux/mman.h index bce214fece16b9af3791a2baaecd6063d0481938..f4c6346a8fcd29b08d43f7cd9158c3eddc3383e1 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -155,7 +155,9 @@ calc_vm_flag_bits(struct file *file, unsigned long flags) return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | +#ifdef CONFIG_TRANSPARENT_HUGEPAGE _calc_vm_trans(flags, MAP_STACK, VM_NOHUGEPAGE) | +#endif arch_calc_vm_flag_bits(file, flags); }
* Ignacio Moreno Gonzalez via B4 Relay devnull+Ignacio.MorenoGonzalez.kuka.com@kernel.org [250506 09:44]:
From: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com
commit c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") maps the mmap option MAP_STACK to VM_NOHUGEPAGE. This is also done if CONFIG_TRANSPARENT_HUGETABLES is not defined. But in that case, the VM_NOHUGEPAGE does not make sense.
Fixes: c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") Cc: stable@vger.kernel.org Reviewed-by: Lorenzo Stoakes lorenzo.stoakes@oracle.com Reviewed-by: Yang Shi yang@os.amperecomputing.com Signed-off-by: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com
Reviewed-by: Liam R. Howlett Liam.Howlett@oracle.com
include/linux/mman.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/linux/mman.h b/include/linux/mman.h index bce214fece16b9af3791a2baaecd6063d0481938..f4c6346a8fcd29b08d43f7cd9158c3eddc3383e1 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -155,7 +155,9 @@ calc_vm_flag_bits(struct file *file, unsigned long flags) return _calc_vm_trans(flags, MAP_GROWSDOWN, VM_GROWSDOWN ) | _calc_vm_trans(flags, MAP_LOCKED, VM_LOCKED ) | _calc_vm_trans(flags, MAP_SYNC, VM_SYNC ) | +#ifdef CONFIG_TRANSPARENT_HUGEPAGE _calc_vm_trans(flags, MAP_STACK, VM_NOHUGEPAGE) | +#endif arch_calc_vm_flag_bits(file, flags); }
-- 2.39.5
On Tue, 06 May 2025 15:44:32 +0200 Ignacio Moreno Gonzalez via B4 Relay devnull+Ignacio.MorenoGonzalez.kuka.com@kernel.org wrote:
commit c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") maps the mmap option MAP_STACK to VM_NOHUGEPAGE. This is also done if CONFIG_TRANSPARENT_HUGETABLES is not defined. But in that case, the VM_NOHUGEPAGE does not make sense.
Fixes: c4608d1bf7c6 ("mm: mmap: map MAP_STACK to VM_NOHUGEPAGE") Cc: stable@vger.kernel.org
Mixing -stable and non-stable patches in a single series is troublesome, because the timing and targeting of these patches are quite different. I usually have to split them apart, munge around the changelogging and generally do things which I'd prefer you had done in the original!
So please consider presenting these as two standalone patches.
On Tue, May 06, 2025 at 03:44:31PM +0200, Ignacio Moreno Gonzalez via B4 Relay wrote:
... and make setting MADV_NOHUGEPAGE with madvise() into a no-op if THP is not enabled.
This bit probably belongs after the rest without ellipses :P but it's not important.
I discovered this issue when trying to use the tool CRIU to checkpoint and restore a container. Our running kernel is compiled without CONFIG_TRANSPARENT_HUGETABLES. CRIU parses the output of /proc/<pid>/smaps and saves the "nh" flag. When trying to restore the container, CRIU fails to restore the "nh" mappings, since madvise() MADV_NOHUGEPAGE always returns an error because CONFIG_TRANSPARENT_HUGETABLES is not defined.
These patches:
- Avoid mapping MAP_STACK to VM_NOHUGEPAGE if !THP
- Avoid returning an error when calling madvise() with MADV_NOHUGEPAGE if !THP
Signed-off-by: Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com
The series looks good to me, thanks!
Applies cleanly, builds fine, all selftests tests passing etc.
Changes in v2:
[Patch 1/2] Use '#ifdef' instead of '#if defined(...)'
[Patch 1/2] Add 'Fixes: c4608d1bf7c6...'
Create [Patch 2/2]
Link to v1: https://lore.kernel.org/r/20250502-map-map_stack-to-vm_nohugepage-only-if-th...
Thanks for the summary!
Ignacio Moreno Gonzalez (2): mm: mmap: map MAP_STACK to VM_NOHUGEPAGE only if THP is enabled mm: madvise: no-op for MADV_NOHUGEPAGE if THP is disabled
include/linux/huge_mm.h | 6 ++++++ include/linux/mman.h | 2 ++ 2 files changed, 8 insertions(+)
base-commit: fc96b232f8e7c0a6c282f47726b2ff6a5fb341d2 change-id: 20250428-map-map_stack-to-vm_nohugepage-only-if-thp-is-enabled-ce40a1de095d
Best regards,
Ignacio Moreno Gonzalez Ignacio.MorenoGonzalez@kuka.com
On 5/6/2025 4:28 PM, Lorenzo Stoakes wrote:
This bit probably belongs after the rest without ellipses :P but it's not important.
I was not sure about modifying the subject for v2. Let me know if I should change it ;)
The series looks good to me, thanks!
Thank you too for reviewing it!
On Tue, May 06, 2025 at 05:12:37PM +0200, Ignacio Moreno Gonzalez wrote:
On 5/6/2025 4:28 PM, Lorenzo Stoakes wrote:
This bit probably belongs after the rest without ellipses :P but it's not important.
I was not sure about modifying the subject for v2. Let me know if I should change it ;)
Ahhh I see that's why you did that haha. I think for something this small it's fine.
The series looks good to me, thanks!
Thank you too for reviewing it!
No problem! Thanks for the series! :)
linux-stable-mirror@lists.linaro.org