mm/shmem: Inline shmem_is_huge() for disabled transparent hugepages
Subsystems (3)
PATCH 1/1 mm/shmem: Inline shmem_is_huge() for disabled transparent hugepages
In order to minimize code size (CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) for shmem_is_huge() instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’
383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })
| ^~~~~~~~~
mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’
1148 | stat->blksize = HPAGE_PMD_SIZE;
To prevent the possible error, always inline shmem_is_huge() when transparent hugepages are disabled.
--- include/linux/shmem_fs.h | 9 +++++++++ mm/shmem.c | 6 ------ 2 files changed, 9 insertions(+), 6 deletions(-)
include/linux/shmem_fs.h +9 -0
@@ -110,8 +110,17 @@ extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,extern void shmem_truncate_range (struct inode *inode,loff_t start,loff_t end);int shmem_unuse (unsigned int type); +#ifdef CONFIG_TRANSPARENT_HUGEPAGE extern bool shmem_is_huge (struct inode *inode,pgoff_t index,bool shmem_huge_force,struct mm_struct *mm,unsigned long vm_flags); +#else +static __always_inline bool shmem_is_huge(struct inode *inode, pgoff_t index, bool shmem_huge_force, +struct mm_struct *mm,unsigned long vm_flags) +{ +return false; +} +#endif +#ifdef CONFIG_SHMEM extern unsigned long shmem_swap_usage (struct vm_area_struct *vma);#else
mm/shmem.c +0 -6
@@ -748,12 +748,6 @@ static long shmem_unused_huge_count(struct super_block *sb,#define shmem_huge SHMEM_HUGE_DENY -bool shmem_is_huge (struct inode *inode,pgoff_t index,bool shmem_huge_force, -struct mm_struct *mm,unsigned long vm_flags) -{ -return false; -} -static unsigned long shmem_unused_huge_shrink (struct shmem_sb_info *sbinfo,struct shrink_control *sc,unsigned long nr_to_split) {
Signature · 1 line
2.40.1
Quoted 9 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’
383 | #defineHPAGE_PMD_SIZE({BUILD_BUG(); 0; })
Quoted 7 lines
| ^~~~~~~~~
mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’
1148 |stat->blksize=HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.
Do you know which commit introduced that?
Signature · 3 lines
Cheers, David / dhildenb
Quoted 14 lines · David Hildenbrand
Quoted 13 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’
383 | #defineHPAGE_PMD_SIZE({BUILD_BUG(); 0; })| ^~~~~~~~~
mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’
1148 |stat->blksize=HPAGE_PMD_SIZE;
Quoted 5 lines
Quoted 3 lines
To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Do you know which commit introduced that?
Hi David,
Currently with CONFIG_CC_OPTIMIZE_FOR_SIZE=y and expirementing with -fPIC kernel compiler option, I could see this error on s390.
However, default kernel compiler options doesnt end up with the above pattern right now.
I think, shmem_is_huge() for disabled transparent hugepages comes from:
Commit 5e6e5a12a44c ("huge tmpfs: shmem_is_huge(vma, inode, index)")
However, HPAGE_PMD_SIZE macros for !CONFIG_TRANSPARENT_HUGEPAGE originates from:
Commit d8c37c480678 ("thp: add HPAGE_PMD_* definitions for !CONFIG_TRANSPARENT_HUGEPAGE")
Thanks,
Sumanth
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~
mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’
1148 |stat->blksize=HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.
Got it. I assume on Linus' tree, not mm/unstable?
Quoted 3 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent HPAGE_PMD_SIZE changes:
commit c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26f
Author: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400
mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~
mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’
1148 |stat->blksize=HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 7 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:
Quoted 7 lines
commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks,
Sumanth
Quoted 41 lines · Sumanth Korikkar
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~ mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’ 1148 | stat->blksize = HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 11 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400
Quoted 5 lines
Quoted 3 lines
mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks! Can you try with Peters patch? (ccing Peter)
If I am not wrong, that should also resolve the issue you are seeing.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 44 lines · David Hildenbrand
Quoted 43 lines · Sumanth Korikkar
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~ mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’ 1148 | stat->blksize = HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 13 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400mm: make HPAGE_PXD_* macros even if !THP
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks! Can you try with Peters patch? (ccing Peter)
If I am not wrong, that should also resolve the issue you are seeing.
David,
Do you mean this one?
https://lore.kernel.org/all/[email protected]/
That's indeed similar but that was for pud_pfn() not HPAGE_* stuff.
I just had a quick look, Sumanth's fix looks valid, and IIUC the goal is also that we should keep these build checks around for the long term goal (Jason definitely preferred that [1] too, which I agree).
I removed that build check there for pud_pfn just to avoid other build fallouts for other archs as a temporary measure. For this one if it's in common code for a long time and if it's the single spot maybe it's nice to have this patch as proposed, as it means it optimizes the if check too besides fixing the build error. After all referencing HPAGE_* with !THP+!HUGETLB shouldn't happen logically.
[1] https://lore.kernel.org/r/[email protected]
Thanks,
Signature · 1 line
Peter Xu
Quoted 51 lines · Peter Xu
Quoted 50 lines · David Hildenbrand
Quoted 41 lines · Sumanth Korikkar
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~ mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’ 1148 | stat->blksize = HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 11 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400Quoted 5 lines
Quoted 3 lines
mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks! Can you try with Peters patch? (ccing Peter)
Quoted 8 lines
Quoted 1 line
If I am not wrong, that should also resolve the issue you are seeing.
David,
Do you mean this one?
No, I meant:
https://lore.kernel.org/all/[email protected]/
which removes the "#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })" that we seem to trigger here.
... but it's been a long day, so maybe I'm all wrong :)
Quoted 17 lines
That's indeed similar but that was for
pud_pfn()not HPAGE_* stuff.I just had a quick look, Sumanth's fix looks valid, and IIUC the goal is also that we should keep these build checks around for the long term goal (Jason definitely preferred that [1] too, which I agree).
I removed that build check there for
pud_pfnjust to avoid other build fallouts for other archs as a temporary measure. For this one if it's in common code for a long time and if it's the single spot maybe it's nice to have this patch as proposed, as it means it optimizes the if check too besides fixing the build error. After all referencing HPAGE_* with !THP+!HUGETLB shouldn't happen logically.[1] https://lore.kernel.org/r/[email protected]
Thanks,
Signature · 3 lines
Cheers, David / dhildenb
Quoted 63 lines · David Hildenbrand
Quoted 51 lines · Peter Xu
Quoted 50 lines · David Hildenbrand
Quoted 41 lines · Sumanth Korikkar
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~ mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’ 1148 | stat->blksize = HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 11 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400Quoted 5 lines
Quoted 3 lines
mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks! Can you try with Peters patch? (ccing Peter)
Quoted 8 lines
Quoted 1 line
If I am not wrong, that should also resolve the issue you are seeing.
David,
Do you mean this one?
No, I meant:
Quoted 7 lines
https://lore.kernel.org/all/[email protected]/
which removes the "#define
HPAGE_PMD_SIZE({BUILD_BUG(); 0; })" that we seem to trigger here.... but it's been a long day, so maybe I'm all wrong :)
Ah.. So I thought it was one step further. :)
Then that shouldn't be the case; it didn't remove it but defined properly with HPAGE_PMD_SHIFT:
+#define HPAGE_PMD_SIZE ((1UL) << HPAGE_PMD_SHIFT)
Now we even have that properly defined for HUGETLB_PAGE, while prior to that we should hit this issue easier (even with !THP+HUGETLB_PAGE).
Quoted 24 lines
Quoted 18 lines
That's indeed similar but that was for
pud_pfn()not HPAGE_* stuff.I just had a quick look, Sumanth's fix looks valid, and IIUC the goal is also that we should keep these build checks around for the long term goal (Jason definitely preferred that [1] too, which I agree).
I removed that build check there for
pud_pfnjust to avoid other build fallouts for other archs as a temporary measure. For this one if it's in common code for a long time and if it's the single spot maybe it's nice to have this patch as proposed, as it means it optimizes the if check too besides fixing the build error. After all referencing HPAGE_* with !THP+!HUGETLB shouldn't happen logically.[1] https://lore.kernel.org/r/[email protected]
Thanks,
Signature · 3 lines
Cheers, David / dhildenb
Signature · 1 line
Peter Xu
David Hildenbrand
Acked-byQuoted 74 lines · Peter Xu
Quoted 63 lines · David Hildenbrand
Quoted 51 lines · Peter Xu
Quoted 50 lines · David Hildenbrand
Quoted 41 lines · Sumanth Korikkar
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Sumanth Korikkar
Quoted 18 lines · David Hildenbrand
Quoted 16 lines · Sumanth Korikkar
In order to minimize code size (
CONFIG_CC_OPTIMIZE_FOR_SIZE=y), compiler might choose to make a regular function call (out-of-line) forshmem_is_huge()instead of inlining it. When transparent hugepages are disabled (CONFIG_TRANSPARENT_HUGEPAGE=n), it can cause compilation error.
mm/shmem.c: In function ‘shmem_getattr’:./include/linux/huge_mm.h:383:27: note: in expansion of macro ‘BUILD_BUG’383 | #define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; }) | ^~~~~~~~~ mm/shmem.c:1148:33: note: in expansion of macro ‘HPAGE_PMD_SIZE’ 1148 | stat->blksize = HPAGE_PMD_SIZE;To prevent the possible error, always inline
shmem_is_huge()when transparent hugepages are disabled.Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Do you know which commit introduced that?
Hi David,
Currently with
CONFIG_CC_OPTIMIZE_FOR_SIZE=yand expirementing with -fPIC kernel compiler option, I could see this error on s390.Got it. I assume on Linus' tree, not mm/unstable?
It's not yet upstream.
Quoted 11 lines
Quoted 4 lines
However, default kernel compiler options doesnt end up with the above pattern right now.
Okay, just asking if this is related to recent
HPAGE_PMD_SIZEchanges:commit
c1a1e497a3d5711dbf8fa6d7432d6b83ec18c26fAuthor: Peter Xu <[email protected]> Date: Wed Mar 27 11:23:22 2024 -0400Quoted 5 lines
Quoted 3 lines
mm: make HPAGE_PXD_* macros even if !THP
Which is still in mm-unstable and not upstream.
Not related to this commit. I tried on master branch.
Thanks! Can you try with Peters patch? (ccing Peter)
Quoted 8 lines
Quoted 1 line
If I am not wrong, that should also resolve the issue you are seeing.
David,
Do you mean this one?
No, I meant:
Quoted 7 lines
https://lore.kernel.org/all/[email protected]/
which removes the "#define
HPAGE_PMD_SIZE({BUILD_BUG(); 0; })" that we seem to trigger here.... but it's been a long day, so maybe I'm all wrong :)
Ah.. So I thought it was one step further. :)
Quoted 7 lines
Then that shouldn't be the case; it didn't remove it but defined properly with
HPAGE_PMD_SHIFT:+#define
HPAGE_PMD_SIZE((1UL) <<HPAGE_PMD_SHIFT)Now we even have that properly defined for
HUGETLB_PAGE, while prior to that we should hit this issue easier (even with !THP+HUGETLB_PAGE).
Ah, now I spot
#define HPAGE_PMD_SHIFT ({ BUILD_BUG(); 0; })
:) sorry for the noise!
To the original patch here
Signature · 3 lines
Cheers, David / dhildenb