mm,thp,shmem: limit shmem THP alloc gfp_mask
Subsystems (5)
PATCH 1/1 mm,thp,shmem: limit shmem THP alloc gfp_mask
The allocation flags of anonymous transparent huge pages can be controlled through the files in /sys/kernel/mm/transparent_hugepage/defrag, which can help the system from getting bogged down in the page reclaim and compaction code when many THPs are getting allocated simultaneously.
However, the gfp_mask for shmem THP allocations were not limited by those configuration settings, and some workloads ended up with all CPUs stuck on the LRU lock in the page reclaim code, trying to allocate dozens of THPs simultaneously.
This patch applies the same configurated limitation of THPs to shmem hugepage allocations, to prevent that from happening.
This way a THP defrag setting of "never" or "defer+madvise" will result in quick allocation failures without direct reclaim when no 2MB free pages are available.
---
include/linux/gfp.h +2 -0
@@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);extern void pm_restrict_gfp_mask (void );extern void pm_restore_gfp_mask (void ); +extern gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma); +#ifdef CONFIG_PM_SLEEP extern bool pm_suspended_storage (void );#else
mm/huge_memory.c +1 -1
@@ -649,7 +649,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,* available * never: never stall for any thp allocation */ -static inline gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) +gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) {const bool vma_madvised = !!(vma->vm_flags &VM_HUGEPAGE );
mm/shmem.c +5 -2
@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; + gfp &=alloc_hugepage_direct_gfpmask (&pvma); + page =alloc_pages_vma (gfp,HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), + true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);
Signature · 1 line
All rights reversed.
Michal Hocko
reviewerQuoted 10 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled through the files in
/sys/kernel/mm/transparent_hugepage/defrag, which can help the system from getting bogged down in the page reclaim and compaction code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those configuration settings, and some workloads ended up with all CPUs stuck on the LRU lock in the page reclaim code, trying to allocate dozens of THPs simultaneously.
Quoted 6 lines
This patch applies the same configurated limitation of THPs to shmem hugepage allocations, to prevent that from happening.
This way a THP defrag setting of "never" or "defer+madvise" will result in quick allocation failures without direct reclaim when no 2MB free pages are available.
I remmeber I wanted to unify this in the past as well. The patch got reverted in the end. It was a long story and I do not have time to read through lengthy discussions again. I do remember though that there were some objections pointing out that shmem has its own behavior which is controlled by the mount option - at least for the explicitly mounted shmems. I might misremember.
[...]
mm/shmem.c static struct page *shmem_alloc_hugepage(gfp_t gfp, · line 1549
Quoted 12 lines
mm/shmem.c +2
-2@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN;
What is the reason for these when alloc_hugepage_direct_gfpmask provides the full mask?
Quoted 9 lines
mm/shmem.c +3
-0+ gfp &=alloc_hugepage_direct_gfpmask (&pvma); + page =alloc_pages_vma (gfp,HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), + true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);Signature · 2 lines
-- All rights reversed.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 27 lines · Michal Hocko
Quoted 20 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled
through the files in/sys/kernel/mm/transparent_hugepage/defrag, which can
help the system from getting bogged down in the page reclaim and compaction
code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those
configuration settings, and some workloads ended up with all CPUs stuck
on the LRU lock in the page reclaim code, trying to allocate dozens of
THPs simultaneously.This patch applies the same configurated limitation of THPs to shmem
hugepage allocations, to prevent that from happening.Quoted 5 lines
This way a THP defrag setting of "never" or "defer+madvise" will result
in quick allocation failures without direct reclaim when no 2MB free
pages are available.
Quoted 8 lines
I remmeber I wanted to unify this in the past as well. The patch got reverted in the end. It was a long story and I do not have time to read
through lengthy discussions again. I do remember though that there were
some objections pointing out that shmem has its own behavior which is controlled by the mount option - at least for the explicitly mounted shmems. I might misremember.
That is not entirely true, though.
THP has two main sysfs knobs: "enabled" and "defrag"
The mount options
control the shmem equivalent options
for "enabled", but they do not do anything for the "defrag" equivalent options.
This patch applies the "defrag" THP options to
shmem.
Quoted 10 lines
[...]
Quoted 8 lines
mm/shmem.c +0
-0@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp, return NULL;
Quoted 11 lines
mm/shmem.c static struct page · line 1552
Quoted 7 lines
mm/shmem.c +2
-2shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN;What is the reason for these when
alloc_hugepage_direct_gfpmaskprovides
the full mask?
The mapping_gfp_mask for the shmem file might have additional restrictions above and beyond the gfp mask returned by alloc_hugepage_direct_gfpmask, and I am not sure we should just ignore the mapping_gfp_mask.
That is why this patch takes the union of both gfp masks.
However, digging into things more, it looks like shmem inodes always have the mapping gfp mask set to GFP_HIGHUSER_MOVABLE, and it is never changed, so simply using the output from alloc_hugepage_direct_gfpmask should be fine.
I can do the patch either way. Just let me know what you prefer.
Quoted 10 lines
Quoted 10 lines
mm/shmem.c +2
-0+ gfp &=alloc_hugepage_direct_gfpmask (&pvma); + page = alloc_pages_vma(gfp, HPAGE_PMD_ORDER, &pvma, 0,
numa_node_id(),mm/shmem.c +1
-0+ true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);Signature · 2 lines
-- All rights reversed.
Signature · 1 line
All Rights Reversed.
Michal Hocko
reviewerQuoted 37 lines · Rik van Riel
Quoted 27 lines · Michal Hocko
Quoted 20 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled
through the files in/sys/kernel/mm/transparent_hugepage/defrag, which can
help the system from getting bogged down in the page reclaim and compaction
code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those
configuration settings, and some workloads ended up with all CPUs stuck
on the LRU lock in the page reclaim code, trying to allocate dozens of
THPs simultaneously.This patch applies the same configurated limitation of THPs to shmem
hugepage allocations, to prevent that from happening.Quoted 5 lines
This way a THP defrag setting of "never" or "defer+madvise" will result
in quick allocation failures without direct reclaim when no 2MB free
pages are available.Quoted 8 lines
I remmeber I wanted to unify this in the past as well. The patch got reverted in the end. It was a long story and I do not have time to read
through lengthy discussions again. I do remember though that there were
some objections pointing out that shmem has its own behavior which is controlled by the mount option - at least for the explicitly mounted shmems. I might misremember.
Quoted 8 lines
That is not entirely true, though.
THP has two main sysfs knobs: "enabled" and "defrag"
The mount options
control the shmem equivalent options
for "enabled", but they do not do anything for the "defrag" equivalent options.
Yeah, the situation is quite messy :/
Quoted 2 lines
This patch applies the "defrag" THP options to
shmem.
I am not really objecting I just do remember some pushback. My previous attempt was to unify everything inside alloc_pages_vma IIRC.
Quoted 22 lines
Quoted 10 lines
[...]
Quoted 8 lines
mm/shmem.c +0
-0@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp, return NULL;Quoted 11 lines
mm/shmem.c static struct page · line 1552
Quoted 7 lines
mm/shmem.c +2
-2shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN;What is the reason for these when
alloc_hugepage_direct_gfpmaskprovides
the full mask?
Quoted 4 lines
The
mapping_gfp_maskfor the shmem file might have additional restrictions above and beyond the gfp mask returned byalloc_hugepage_direct_gfpmask, and I am not sure we should just ignore themapping_gfp_mask.
No, we shouldn't. But I do not see why you should be adding the above set of flags on top.
Quoted 8 lines
That is why this patch takes the union of both gfp masks.
However, digging into things more, it looks like shmem inodes always have the mapping gfp mask set to
GFP_HIGHUSER_MOVABLE, and it is never changed, so simply using the output fromalloc_hugepage_direct_gfpmaskshould be fine.I can do the patch either way. Just let me know what you prefer.
I would just and the given gfp with alloc_hugepage_direct_gfpmask
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 27 lines · Michal Hocko
Quoted 26 lines · Rik van Riel
Quoted 24 lines · Michal Hocko
Quoted 18 lines · Rik van Riel
mm/shmem.c +0
-1@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp, return NULL; shmem_pseudo_vma_init(&pvma, info, hindex); - page = alloc_pages_vma(gfp | __GFP_COMP | __GFP_NORETRY|
__GFP_NOWARN,mm/shmem.c +0
-1- HPAGE_PMD_ORDER, &pvma, 0,
numa_node_id(),
true);mm/shmem.c +1
-0+/* Limit the gfp mask according to THP configuration. */
mm/shmem.c static struct page *shmem_alloc_hugepage(gfp_t gfp, · line 1549
Quoted 1 line
mm/shmem.c +1
-0+ gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN;What is the reason for these when
alloc_hugepage_direct_gfpmaskprovides
the full mask?
Quoted 7 lines
Quoted 4 lines
The
mapping_gfp_maskfor the shmem file might have additional restrictions above and beyond the gfp mask returned byalloc_hugepage_direct_gfpmask, and I am not sure we should just ignore themapping_gfp_mask.No, we shouldn't. But I do not see why you should be adding the above set of flags on top.
Because THP allocations are higher order and optimistic, and we want them to:
1) be annotated as compound allocations
2) fail (and fall back to 4kB allocations) when they cannot be easily satisfied, and
3) not create a spew of allocation failure backtraces on the (serial) console when these THP allocations fail
Quoted 10 lines
Quoted 8 lines
That is why this patch takes the union of both gfp masks.
However, digging into things more, it looks like shmem inodes always have the mapping gfp mask set to
GFP_HIGHUSER_MOVABLE, and it is never changed, so simply using the output fromalloc_hugepage_direct_gfpmaskshould be fine.I can do the patch either way. Just let me know what you prefer.
I would just and the given gfp with
alloc_hugepage_direct_gfpmask
That would miss the three things we definitely want from above.
Signature · 1 line
All Rights Reversed.
Michal Hocko
reviewerQuoted 36 lines · Rik van Riel
Quoted 27 lines · Michal Hocko
Quoted 26 lines · Rik van Riel
Quoted 24 lines · Michal Hocko
Quoted 18 lines · Rik van Riel
mm/shmem.c +0
-1@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp, return NULL; shmem_pseudo_vma_init(&pvma, info, hindex); - page = alloc_pages_vma(gfp | __GFP_COMP | __GFP_NORETRY|
__GFP_NOWARN,mm/shmem.c +0
-1- HPAGE_PMD_ORDER, &pvma, 0,
numa_node_id(),
true);mm/shmem.c +1
-0+/* Limit the gfp mask according to THP configuration. */
mm/shmem.c static struct page *shmem_alloc_hugepage(gfp_t gfp, · line 1549
Quoted 1 line
mm/shmem.c +1
-0+ gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN;What is the reason for these when
alloc_hugepage_direct_gfpmaskprovides
the full mask?Quoted 7 lines
Quoted 4 lines
The
mapping_gfp_maskfor the shmem file might have additional restrictions above and beyond the gfp mask returned byalloc_hugepage_direct_gfpmask, and I am not sure we should just ignore themapping_gfp_mask.No, we shouldn't. But I do not see why you should be adding the above set of flags on top.
Quoted 7 lines
Because THP allocations are higher order and optimistic, and we want them to:
1) be annotated as compound allocations
2) fail (and fall back to 4kB allocations) when they cannot be easily satisfied, and
3) not create a spew of allocation failure backtraces on the (serial) console when these THP allocations fail
This all is already returned from alloc_hugepage_direct_gfpmask.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 10 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled through the files in
/sys/kernel/mm/transparent_hugepage/defrag, which can help the system from getting bogged down in the page reclaim and compaction code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those configuration settings, and some workloads ended up with all CPUs stuck on the LRU lock in the page reclaim code, trying to allocate dozens of THPs simultaneously.
Quoted 8 lines
This patch applies the same configurated limitation of THPs to shmem hugepage allocations, to prevent that from happening.
This way a THP defrag setting of "never" or "defer+madvise" will result in quick allocation failures without direct reclaim when no 2MB free pages are available.
Signed-off-by Rik van Riel <[email protected]>
FTR, a patch to the same effect was sent by Xu Yu:
Quoted 47 lines
---
include/linux/gfp.h +2
-0@@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);extern void pm_restrict_gfp_mask (void );extern void pm_restore_gfp_mask (void ); +extern gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma); +#ifdef CONFIG_PM_SLEEP extern bool pm_suspended_storage (void );#else mm/huge_memory.c +1
-1@@ -649,7 +649,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,* available * never: never stall for any thp allocation */ -static inline gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) +gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) {const bool vma_madvised = !!(vma->vm_flags &VM_HUGEPAGE );mm/shmem.c +5
-2@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; + gfp &=alloc_hugepage_direct_gfpmask (&pvma); + page =alloc_pages_vma (gfp,HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), + true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);
Quoted 14 lines · Vlastimil Babka
Quoted 13 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled through the files in
/sys/kernel/mm/transparent_hugepage/defrag, which can help the system from getting bogged down in the page reclaim and compaction code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those configuration settings, and some workloads ended up with all CPUs stuck on the LRU lock in the page reclaim code, trying to allocate dozens of THPs simultaneously.This patch applies the same configurated limitation of THPs to shmem hugepage allocations, to prevent that from happening.
Quoted 7 lines
Quoted 5 lines
This way a THP defrag setting of "never" or "defer+madvise" will result in quick allocation failures without direct reclaim when no 2MB free pages are available.
Signed-off-by Rik van Riel <[email protected]>FTR, a patch to the same effect was sent by Xu Yu:
Hm thought I did CC, but TB ate it. sorry for the noise
Quoted 50 lines
Quoted 47 lines
---
include/linux/gfp.h +2
-0@@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);extern void pm_restrict_gfp_mask (void );extern void pm_restore_gfp_mask (void ); +extern gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma); +#ifdef CONFIG_PM_SLEEP extern bool pm_suspended_storage (void );#else mm/huge_memory.c +1
-1@@ -649,7 +649,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,* available * never: never stall for any thp allocation */ -static inline gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) +gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) {const bool vma_madvised = !!(vma->vm_flags &VM_HUGEPAGE );mm/shmem.c +5
-2@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; + gfp &=alloc_hugepage_direct_gfpmask (&pvma); + page =alloc_pages_vma (gfp,HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), + true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);
Quoted 51 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled through the files in
/sys/kernel/mm/transparent_hugepage/defrag, which can help the system from getting bogged down in the page reclaim and compaction code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those configuration settings, and some workloads ended up with all CPUs stuck on the LRU lock in the page reclaim code, trying to allocate dozens of THPs simultaneously.This patch applies the same configurated limitation of THPs to shmem hugepage allocations, to prevent that from happening.
This way a THP defrag setting of "never" or "defer+madvise" will result in quick allocation failures without direct reclaim when no 2MB free pages are available.
Signed-off-by Rik van Riel <[email protected]>---
include/linux/gfp.h +2
-0@@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);extern void pm_restrict_gfp_mask (void );extern void pm_restore_gfp_mask (void ); +extern gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma); +#ifdef CONFIG_PM_SLEEP extern bool pm_suspended_storage (void );#else mm/huge_memory.c +1
-1@@ -649,7 +649,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf,* available * never: never stall for any thp allocation */ -static inline gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) +gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) {const bool vma_madvised = !!(vma->vm_flags &VM_HUGEPAGE );mm/shmem.c +0
-0
mm/shmem.c static struct page *shmem_alloc_hugepage(gfp_t gfp, · line 1550
Quoted 8 lines
mm/shmem.c +3
-2@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; + gfp &=alloc_hugepage_direct_gfpmask (&pvma);
It is fine to reuse alloc_hugepage_direct_gfpmask, but pvma.vm_flags & VM_HUGEPAGE is always false here, thus, vma_madvised in alloc_hugepage_direct_gfpmask will always be false.
That is why I chose to do the gfp_mask fixup in shmem_getpage_gfp, using sgp_huge to indicate vma_madvised, although with some silly mistakes pointed out by you, in another mail thread.
It will be better if vma_madvised is well handled in your solution.
Quoted 6 lines
mm/shmem.c +2
-0+ page =alloc_pages_vma (gfp,HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), + true);shmem_pseudo_vma_destroy (&pvma);if (page)prep_transhuge_page (page);
Signature · 2 lines
Thanks, Yu
Quoted 81 lines · Yu Xu
Quoted 64 lines · Rik van Riel
The allocation flags of anonymous transparent huge pages can be controlled
through the files in/sys/kernel/mm/transparent_hugepage/defrag, which can
help the system from getting bogged down in the page reclaim and compaction
code when many THPs are getting allocated simultaneously.However, the
gfp_maskfor shmem THP allocations were not limited by those
configuration settings, and some workloads ended up with all CPUs stuck
on the LRU lock in the page reclaim code, trying to allocate dozens of
THPs simultaneously.This patch applies the same configurated limitation of THPs to shmem
hugepage allocations, to prevent that from happening.This way a THP defrag setting of "never" or "defer+madvise" will result
in quick allocation failures without direct reclaim when no 2MB free
pages are available.Signed-off-by Rik van Riel <[email protected]>---
include/linux/gfp.h +2
-0@@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask);extern void pm_restrict_gfp_mask (void );extern void pm_restore_gfp_mask (void ); +extern gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma); +#ifdef CONFIG_PM_SLEEP extern bool pm_suspended_storage (void );#elsemm/huge_memory.c +1
-1@@ -649,7 +649,7 @@ static vm_fault_t__do_huge_pmd_anonymous_page(struct vm_fault *vmf, * available * never: never stall for any thp allocation */ -static inline gfp_t alloc_hugepage_direct_gfpmask (struct vm_area_struct *vma) +gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) {const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE);mm/shmem.c +0
-0@@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp,mm/shmem.c static struct page · line 1553
Quoted 10 lines
mm/shmem.c +3
-2return NULL ;shmem_pseudo_vma_init (&pvma, info, hindex); - page =alloc_pages_vma (gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, -HPAGE_PMD_ORDER , &pvma,0 ,numa_node_id (), true); +/* Limit the gfp mask according to THP configuration. */ + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; + gfp &=alloc_hugepage_direct_gfpmask (&pvma);It is fine to reuse
alloc_hugepage_direct_gfpmask, butpvma.vm_flags & VM_HUGEPAGEis always false here, thus,vma_madvisedinalloc_hugepage_direct_gfpmaskwill always be false.
Quoted 5 lines
That is why I chose to do the
gfp_maskfixup inshmem_getpage_gfp, usingsgp_hugeto indicatevma_madvised, although with some silly mistakes pointed out by you, in another mail thread.It will be better if
vma_madvisedis well handled in your solution.
OK, let me send a v2 that does that!
By just passing a correct gfp_mask to shmem_alloc_and_acct_page we can also avoid the gfp gymnastics in shmem_alloc_hugepage that Michal rightfully objected to.
Signature · 1 line
All Rights Reversed.