mm: thp: fix false negative of shmem vma's THP eligibility
Subsystems (3)
PATCH v2 1/1 mm: thp: fix false negative of shmem vma's THP eligibility
The commit 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma, __transparent_hugepage_enabled() is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:
7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764 /dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0
And, /proc/meminfo does show THP allocated and PMD mapped too:
ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kB
This doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling shmem_huge_enabled() with checking MMF_DISABLE_THP sounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.
---
v2: Check VM_NOHUGEPAGE per Michal Hocko
mm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)
mm/huge_memory.c +2 -2
@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }
mm/shmem.c +3 -0
@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )
Signature · 1 line
1.8.3.1
Quoted 21 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:
Quoted 7 lines
ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
I have to say that the THP tuning API is one giant mess :/
Btw. this patch also seem to fix khugepaged behavior because it previously ignored both VM_NOHUGEPAGE and MMF_DISABLE_THP.
Quoted 45 lines
Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )Signature · 1 line
1.8.3.1
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 29 lines · Michal Hocko
Quoted 21 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:Quoted 7 lines
ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.
Quoted 8 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
I have to say that the THP tuning API is one giant mess :/
Btw. this patch also seem to fix khugepaged behavior because it previously ignored both
VM_NOHUGEPAGEandMMF_DISABLE_THP.
Aha, I didn't notice this. It looks we need separate the patch to fix that khugepaged problem for both 5.1-rc and LTS.
Quoted 46 lines
Quoted 46 lines
Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )Signature · 1 line
1.8.3.1
Quoted 32 lines · Yang Shi
Quoted 29 lines · Michal Hocko
Quoted 28 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.
Quoted 8 lines
Quoted 8 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
I have to say that the THP tuning API is one giant mess :/
Btw. this patch also seem to fix khugepaged behavior because it previously ignored both
VM_NOHUGEPAGEandMMF_DISABLE_THP.
Second look shows this is not ignored. hugepage_vma_check() would check this for both anonymous vma and shmem vma before scanning. It is called before shmem_huge_enabled().
Quoted 50 lines
Aha, I didn't notice this. It looks we need separate the patch to fix that khugepaged problem for both 5.1-rc and LTS.
Quoted 46 lines
Quoted 46 lines
Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hocko
mm/huge_memory.c| 4 ++--
mm/shmem.c | 3 +++2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) { if (vma_is_anonymous(vma)) return __transparent_hugepage_enabled(vma); - if (vma_is_shmem(vma) && shmem_huge_enabled(vma)) - return __transparent_hugepage_enabled(vma); + if (vma_is_shmem(vma)) + return shmem_huge_enabled(vma); return false; }mm/shmem.c +0
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma) loff_t i_size; pgoff_t off;+ if ((
vma->vm_flags&VM_NOHUGEPAGE) || +test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false;
if (shmem_huge==SHMEM_HUGE_FORCE) return true;
if (shmem_huge==SHMEM_HUGE_DENY)Signature · 1 line
1.8.3.1
Quoted 45 lines · Yang Shi
Quoted 42 lines · Yang Shi
Quoted 39 lines · Michal Hocko
Quoted 25 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:Quoted 7 lines
ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
I have to say that the THP tuning API is one giant mess :/
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Btw. this patch also seem to fix khugepaged behavior because it previously
ignored bothVM_NOHUGEPAGEandMMF_DISABLE_THP.Second look shows this is not ignored.
hugepage_vma_check()would check this for both anonymous vma and shmem vma before scanning. It is called beforeshmem_huge_enabled().
Right. I have missed the earlier check. The main question remains though.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 25 lines · Michal Hocko
Quoted 24 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kB
Quoted 7 lines
Quoted 4 lines
This doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
Hi Kirill,
Ping. Any comment?
Thanks,
Yang
Quoted 51 lines
I have to say that the THP tuning API is one giant mess :/
Btw. this patch also seem to fix khugepaged behavior because it previously ignored both
VM_NOHUGEPAGEandMMF_DISABLE_THP.Quoted 45 lines
Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )Signature · 1 line
1.8.3.1
Quoted 32 lines · Yang Shi
Quoted 29 lines · Michal Hocko
Quoted 28 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.
Quoted 7 lines
Quoted 3 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior according to him. But, we all agree it looks inconsistent.
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistent
I'm not sure whether anyone relies on the behavior explicitly or implicitly or not.
If we would like to change the behavior, I may consider to take a step further to refactor the code a little bit to use huge_fault() to handle THP fault instead of falling back to handle_pte_fault() in the current implementation. This may make adding THP for other filesystems easier.
Quoted 56 lines
Thanks,
YangQuoted 51 lines
I have to say that the THP tuning API is one giant mess :/
Btw. this patch also seem to fix khugepaged behavior because it previously ignored both
VM_NOHUGEPAGEandMMF_DISABLE_THP.Quoted 45 lines
Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hocko
mm/huge_memory.c| 4 ++--
mm/shmem.c | 3 +++2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) { if (vma_is_anonymous(vma)) return __transparent_hugepage_enabled(vma); - if (vma_is_shmem(vma) && shmem_huge_enabled(vma)) - return __transparent_hugepage_enabled(vma); + if (vma_is_shmem(vma)) + return shmem_huge_enabled(vma); return false; }mm/shmem.c +0
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma) loff_t i_size; pgoff_t off;+ if ((
vma->vm_flags&VM_NOHUGEPAGE) || +test_bit(MMF_DISABLE_THP, &vma->vm_mm->flags)) + return false;
if (shmem_huge==SHMEM_HUGE_FORCE) return true;
if (shmem_huge==SHMEM_HUGE_DENY)Signature · 1 line
1.8.3.1
[Hmm, I thought, Hugh was CCed]
Quoted 50 lines · Yang Shi
Quoted 36 lines · Yang Shi
Quoted 33 lines · Michal Hocko
Quoted 32 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Quoted 7 lines
Quoted 3 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior according to him. But, we all agree it looks inconsistent.
Quoted 6 lines
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistentI'm not sure whether anyone relies on the behavior explicitly or implicitly or not.
Well, I would be certainly more happy with a more consistent behavior. Talked to Hugh at LSFMM about this and he finds treating shmem objects separately from the anonymous memory. And that is already the case partially when each mount point might have its own setup. So the primary question is whether we need a one global knob to controll all THP allocations. One argument to have that is that it might be helpful to for an admin to simply disable source of THP at a single place rather than crawling over all shmem mount points and remount them. Especially in environments where shmem points are mounted in a container by a non-root. Why would somebody wanted something like that? One example would be to temporarily workaround high order allocations issues which we have seen non trivial amount of in the past and we are likely not at the end of the tunel.
That being said I would be in favor of treating the global sysfs knob to be global for all THP allocations. I will not push back on that if there is a general consensus that shmem and fs in general are a different class of objects and a single global control is not desirable for whatever reasons.
Kirill, Hugh othe folks?
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 55 lines · Michal Hocko
[Hmm, I thought, Hugh was CCed]
Quoted 46 lines · Yang Shi
Quoted 35 lines · Yang Shi
Quoted 33 lines · Michal Hocko
Quoted 32 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Quoted 6 lines
Quoted 3 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior according to him. But, we all agree it looks inconsistent.
Quoted 6 lines
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistentI'm not sure whether anyone relies on the behavior explicitly or implicitly or not.
Quoted 13 lines
Well, I would be certainly more happy with a more consistent behavior. Talked to Hugh at LSFMM about this and he finds treating shmem objects separately from the anonymous memory. And that is already the case partially when each mount point might have its own setup. So the primary question is whether we need a one global knob to controll all THP allocations. One argument to have that is that it might be helpful to for an admin to simply disable source of THP at a single place rather than crawling over all shmem mount points and remount them. Especially in environments where shmem points are mounted in a container by a non-root. Why would somebody wanted something like that? One example would be to temporarily workaround high order allocations issues which we have seen non trivial amount of in the past and we are likely not at the end of the tunel.
Shmem has a global control for such use. Setting shmem_enabled to "force" or "deny" would enable or disable THP for shmem globally, including non-fs objects, i.e. memfd, SYS V shmem, etc.
Quoted 6 lines
That being said I would be in favor of treating the global sysfs knob to be global for all THP allocations. I will not push back on that if there is a general consensus that shmem and fs in general are a different class of objects and a single global control is not desirable for whatever reasons.
OK, we need more inputs from Kirill, Hugh and other folks.
Quoted 2 lines
Kirill, Hugh othe folks?
Quoted 75 lines · Yang Shi
Quoted 55 lines · Michal Hocko
[Hmm, I thought, Hugh was CCed]
Quoted 46 lines · Yang Shi
Quoted 35 lines · Yang Shi
Quoted 33 lines · Michal Hocko
Quoted 32 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result from shmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Quoted 6 lines
Quoted 3 lines
Kirill, can we get a confirmation that this is really intended behavior rather than an omission please? Is this documented? What is a global knob to simply disable THP system wise?
Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior according to him. But, we all agree it looks inconsistent.
Quoted 6 lines
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistentI'm not sure whether anyone relies on the behavior explicitly or implicitly or not.
Quoted 13 lines
Well, I would be certainly more happy with a more consistent behavior. Talked to Hugh at LSFMM about this and he finds treating shmem objects separately from the anonymous memory. And that is already the case partially when each mount point might have its own setup. So the primary question is whether we need a one global knob to controll all THP allocations. One argument to have that is that it might be helpful to for an admin to simply disable source of THP at a single place rather than crawling over all shmem mount points and remount them. Especially in environments where shmem points are mounted in a container by a non-root. Why would somebody wanted something like that? One example would be to temporarily workaround high order allocations issues which we have seen non trivial amount of in the past and we are likely not at the end of the tunel.
Shmem has a global control for such use. Setting
shmem_enabledto "force" or "deny" would enable or disable THP for shmem globally, including non-fs objects, i.e. memfd, SYS V shmem, etc.Quoted 1 line
Quoted 7 lines
Quoted 5 lines
That being said I would be in favor of treating the global sysfs knob to be global for all THP allocations. I will not push back on that if there is a general consensus that shmem and fs in general are a different class of objects and a single global control is not desirable for whatever reasons.
OK, we need more inputs from Kirill, Hugh and other folks.
[Forgot cc to mailing lists]
Hi guys,
How should we move forward for this one? Make the sysfs knob (/sys/kernel/mm/transparent_hugepage/enabled) to be global for both anonymous and tmpfs? Or just treat shmem objects separately from anon memory then fix the false-negative of THP eligibility by this patch?
Quoted 4 lines
Quoted 3 lines
Kirill, Hugh othe folks?
Hugh Dickins
maintainerQuoted 92 lines · Yang Shi
Quoted 83 lines · Yang Shi
Quoted 63 lines · Michal Hocko
[Hmm, I thought, Hugh was CCed]
Quoted 53 lines · Yang Shi
Quoted 39 lines · Yang Shi
Quoted 37 lines · Michal Hocko
Quoted 36 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is
called to override the result from shmem_huge_enabled(). It may result
in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not
intervene shmem THP. Callingshmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Quoted 8 lines
Quoted 5 lines
Kirill, can we get a confirmation that this is really intended behavior
rather than an omission please? Is this documented? What is a global
knob to simply disable THP system wise?Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior
according to him. But, we all agree it looks inconsistent.Quoted 7 lines
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistentI'm not sure whether anyone relies on the behavior explicitly or implicitly
or not.Quoted 13 lines
Well, I would be certainly more happy with a more consistent behavior. Talked to Hugh at LSFMM about this and he finds treating shmem objects separately from the anonymous memory. And that is already the case partially when each mount point might have its own setup. So the primary question is whether we need a one global knob to controll all THP allocations. One argument to have that is that it might be helpful to for an admin to simply disable source of THP at a single place rather than crawling over all shmem mount points and remount them. Especially in environments where shmem points are mounted in a container by a non-root. Why would somebody wanted something like that? One example would be to temporarily workaround high order allocations issues which we have seen non trivial amount of in the past and we are likely not at the end of the tunel.
Shmem has a global control for such use. Setting
shmem_enabledto "force" or "deny" would enable or disable THP for shmem globally, including non-fs objects, i.e. memfd, SYS V shmem, etc.Quoted 1 line
Quoted 7 lines
Quoted 5 lines
That being said I would be in favor of treating the global sysfs knob to be global for all THP allocations. I will not push back on that if there is a general consensus that shmem and fs in general are a different class of objects and a single global control is not desirable for whatever reasons.
OK, we need more inputs from Kirill, Hugh and other folks.
Quoted 8 lines
[Forgot cc to mailing lists]
Hi guys,
How should we move forward for this one? Make the sysfs knob (
/sys/kernel/mm/transparent_hugepage/enabled) to be global for both anonymous and tmpfs? Or just treat shmem objects separately from anon memory then fix the false-negative of THP eligibility by this patch?
Sorry for not getting back to you sooner on this.
I don't like to drive design by smaps. I agree with the word "mess" used several times of THP tunings in this thread, but it's too easy to make that mess worse by unnecessary changes, so I'm very cautious here.
The addition of "THPeligible" without an "Anon" in its name was unfortunate. I suppose we're two releases too late to change that.
Applying process (PR_SET_THP_DISABLE) and mm (MADV_*HUGEPAGE) limitations to shared filesystem objects doesn't work all that well.
I recommend that you continue to treat shmem objects separately from anon memory, and just make the smaps "THPeligible" more often accurate.
Is your v2 patch earlier in this thread the best for that? No answer tonight, I'll re-examine later in the day.
Hugh
On Fri 07-06-19 03:57:18, Hugh Dickins wrote:
[...]
Quoted 2 lines
The addition of "THPeligible" without an "Anon" in its name was unfortunate. I suppose we're two releases too late to change that.
Well, I do not really see any reason why THPeligible should be Anon specific at all. Even if ...
Quoted 2 lines
Applying process (
PR_SET_THP_DISABLE) and mm (MADV_*HUGEPAGE) limitations to shared filesystem objects doesn't work all that well.
... this is what we are going with then it is really important to have a single place to query the eligibility IMHO.
Quoted 2 lines
I recommend that you continue to treat shmem objects separately from anon memory, and just make the smaps "THPeligible" more often accurate.
Agreed on this.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 95 lines · Hugh Dickins
Quoted 86 lines · Yang Shi
Quoted 79 lines · Yang Shi
Quoted 61 lines · Michal Hocko
[Hmm, I thought, Hugh was CCed]
Quoted 51 lines · Yang Shi
Quoted 38 lines · Yang Shi
Quoted 37 lines · Michal Hocko
Quoted 36 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each
vma") introduced THPeligible bit for processes' smaps. But, when checking
the eligibility for shmem vma,__transparent_hugepage_enabled()is
called to override the result from shmem_huge_enabled(). It may result
in the anonymous vma's THP flag override shmem's. For example, running a
simple test which create THP for shmem, but with anonymous THP disabled,
when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/testSize: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB
ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not
intervene shmem THP. Callingshmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Quoted 8 lines
Quoted 5 lines
Kirill, can we get a confirmation that this is really intended behavior
rather than an omission please? Is this documented? What is a global
knob to simply disable THP system wise?Hi Kirill,
Ping. Any comment?
Talked with Kirill at LSFMM, it sounds this is kind of intended behavior
according to him. But, we all agree it looks inconsistent.Quoted 7 lines
So, we may have two options:
- Just fix the false negative issue as what the patch does
- Change the behavior to make it more consistentI'm not sure whether anyone relies on the behavior explicitly or implicitly
or not.Quoted 13 lines
Well, I would be certainly more happy with a more consistent behavior. Talked to Hugh at LSFMM about this and he finds treating shmem objects separately from the anonymous memory. And that is already the case partially when each mount point might have its own setup. So the primary question is whether we need a one global knob to controll all THP allocations. One argument to have that is that it might be helpful to for an admin to simply disable source of THP at a single place rather than crawling over all shmem mount points and remount them. Especially in environments where shmem points are mounted in a container by a non-root. Why would somebody wanted something like that? One example would be to temporarily workaround high order allocations issues which we have seen non trivial amount of in the past and we are likely not at the end of the tunel.
Shmem has a global control for such use. Setting
shmem_enabledto "force" or "deny" would enable or disable THP for shmem globally, including non-fs objects, i.e. memfd, SYS V shmem, etc.Quoted 6 lines
Quoted 5 lines
That being said I would be in favor of treating the global sysfs knob to be global for all THP allocations. I will not push back on that if there is a general consensus that shmem and fs in general are a different class of objects and a single global control is not desirable for whatever reasons.
OK, we need more inputs from Kirill, Hugh and other folks.
Quoted 8 lines
[Forgot cc to mailing lists]
Hi guys,
How should we move forward for this one? Make the sysfs knob (
/sys/kernel/mm/transparent_hugepage/enabled) to be global for both anonymous and tmpfs? Or just treat shmem objects separately from anon memory then fix the false-negative of THP eligibility by this patch?
Quoted 8 lines
Sorry for not getting back to you sooner on this.
I don't like to drive design by smaps. I agree with the word "mess" used several times of THP tunings in this thread, but it's too easy to make that mess worse by unnecessary changes, so I'm very cautious here.
The addition of "THPeligible" without an "Anon" in its name was unfortunate. I suppose we're two releases too late to change that.
The smaps shows it is anon vma or shmem vma for the most cases.
Quoted 3 lines
Applying process (
PR_SET_THP_DISABLE) and mm (MADV_*HUGEPAGE) limitations to shared filesystem objects doesn't work all that well.
The THP eligibility indicator is per vma, it just reports whether THP is eligible for a specific vma. So, I'm supposed it should keep consistent with MMF_DISABLE_THP and MADV_*HUGEPAGE setting.
The current implementation in shmem and kuhugepaged also checks these.
Quoted 5 lines
I recommend that you continue to treat shmem objects separately from anon memory, and just make the smaps "THPeligible" more often accurate.
Is your v2 patch earlier in this thread the best for that?
The v2 patch treats shmem objects separately from anon memory and it makes the "THPeligible" more often accurate.
Quoted 3 lines
No answer tonight, I'll re-examine later in the day.
Hugh
Quoted 8 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:
Quoted 6 lines
7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
But how does this happen in the first place?
In __handle_mm_fault() we do:
if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) {
ret = create_huge_pmd(&vmf);
if (!(ret & VM_FAULT_FALLBACK))
return ret;And __transparent_hugepage_enabled() checks the global THP settings. If THP is not enabled / is only for madvise and the vma is not madvised, then this should fail, and also khugepaged shouldn't either run at all, or don't do its job for such non-madvised vma.
What am I missing?
Quoted 58 lines
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )
Quoted 23 lines · Vlastimil Babka
Quoted 8 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:Quoted 6 lines
7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kBBut how does this happen in the first place?
In__handle_mm_fault()we do:if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) { ret = create_huge_pmd(&vmf); if (!(ret & VM_FAULT_FALLBACK)) return ret;
Quoted 4 lines
And
__transparent_hugepage_enabled()checks the global THP settings. If THP is not enabled / is only for madvise and the vma is not madvised, then this should fail, and also khugepaged shouldn't either run at all, or don't do its job for such non-madvised vma.
If __transparent_hugepage_enabled() returns false, the code will not reach create_huge_pmd() at all. If it returns true, create_huge_pmd() actually will return VM_FAULT_FALLBACK for shmem since shmem doesn't have huge_fault (or pmd_fault in earlier versions) method.
Then it will get into handle_pte_fault(), finally shmem_fault() is called, which allocates THP by checking some global flag (i.e. VM_NOHUGEPAGE and MMF_DISABLE_THP) and shmem THP knobs.
4.8 (the first version has shmem THP merged) behaves exactly in the same way. So, I suspect this may be intended behavior.
Quoted 61 lines
What am I missing?
Quoted 58 lines
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )
Quoted 31 lines · Yang Shi
Quoted 23 lines · Vlastimil Babka
Quoted 8 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:Quoted 6 lines
7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kBBut how does this happen in the first place?
In__handle_mm_fault()we do:if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) { ret = create_huge_pmd(&vmf); if (!(ret & VM_FAULT_FALLBACK)) return ret;Quoted 4 lines
And
__transparent_hugepage_enabled()checks the global THP settings. If THP is not enabled / is only for madvise and the vma is not madvised, then this should fail, and also khugepaged shouldn't either run at all, or don't do its job for such non-madvised vma.
Quoted 8 lines
If
__transparent_hugepage_enabled()returns false, the code will not reachcreate_huge_pmd()at all. If it returns true,create_huge_pmd()actually will returnVM_FAULT_FALLBACKfor shmem since shmem doesn't havehuge_fault(orpmd_faultin earlier versions) method.Then it will get into
handle_pte_fault(), finallyshmem_fault()is called, which allocates THP by checking some global flag (i.e.VM_NOHUGEPAGEandMMF_DISABLE_THP) and shmem THP knobs.
Aha, thanks! What a mess...
Quoted 3 lines
4.8 (the first version has shmem THP merged) behaves exactly in the same way. So, I suspect this may be intended behavior.
Still looks like an oversight to me. And it's inconsistent... it might fault huge shmem pages when THPs are globally disabled, but khugepaged is still not running. I think it should just check the global THP flags as well...
Quoted 35 lines · Vlastimil Babka
Quoted 34 lines · Yang Shi
Quoted 23 lines · Vlastimil Babka
Quoted 8 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:Quoted 6 lines
7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kBBut how does this happen in the first place?
In__handle_mm_fault()we do:if (pmd_none(*vmf.pmd) && __transparent_hugepage_enabled(vma)) { ret = create_huge_pmd(&vmf); if (!(ret & VM_FAULT_FALLBACK)) return ret;Quoted 4 lines
And
__transparent_hugepage_enabled()checks the global THP settings. If THP is not enabled / is only for madvise and the vma is not madvised, then this should fail, and also khugepaged shouldn't either run at all, or don't do its job for such non-madvised vma.If
__transparent_hugepage_enabled()returns false, the code will not reachcreate_huge_pmd()at all. If it returns true,create_huge_pmd()actually will returnVM_FAULT_FALLBACKfor shmem since shmem doesn't havehuge_fault(orpmd_faultin earlier versions) method.
Quoted 4 lines
Quoted 3 lines
Then it will get into
handle_pte_fault(), finallyshmem_fault()is called, which allocates THP by checking some global flag (i.e.VM_NOHUGEPAGEandMMF_DISABLE_THP) and shmem THP knobs.Aha, thanks! What a mess...
Yes, it does look convoluted. I'm wondering we may consider refactor the shmem THP fault handling.
Quoted 7 lines
Quoted 3 lines
4.8 (the first version has shmem THP merged) behaves exactly in the same way. So, I suspect this may be intended behavior.
Still looks like an oversight to me. And it's inconsistent... it might fault huge shmem pages when THPs are globally disabled, but khugepaged is still not running. I think it should just check the global THP flags as well...
It does looks inconsistent, particularly for the khugepaged part.
Hugh Dickins
maintainerQuoted 62 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +0
-0
mm/shmem.c bool shmem_huge_enabled(struct vm_area_struct *vma) · line 3878
Quoted 6 lines
mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;
Yes, that is correct; and correctly placed. But a little more is needed:
see how mm/memory.c's transhuge_vma_suitable() will only allow a pmd to be used instead of a pte if the vma offset and size permit. smaps should not report a shmem vma as THPeligible if its offset or size prevent it.
And I see that should also be fixed on anon vmas: at present smaps reports even a 4kB anon vma as THPeligible, which is not right. Maybe a test like transhuge_vma_suitable() can be added into transparent_hugepage_enabled(), to handle anon and shmem together. I say "like transhuge_vma_suitable()", because that function needs an address, which here you don't have.
The anon offset situation is interesting: usually anon vm_pgoff is initialized to fit with its vm_start, so the anon offset check passes; but I wonder what happens after mremap to a different address - does transhuge_vma_suitable() then prevent the use of pmds where they could actually be used? Not a Number#1 priority to investigate or fix here! but a curiosity someone might want to look into.
Quoted 5 lines
mm/shmem.c +0
-0if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )Signature · 1 line
1.8.3.1
Even with your changes
ShmemPmdMapped: 4096 kB THPeligible: 0 will easily be seen: THPeligible reflects whether a huge page can be
allocated and mapped by pmd in that vma; but if something else already allocated the huge page earlier, it will be mapped by pmd in this vma if offset and size allow, whatever THPeligible says. We could change transhuge_vma_suitable() to force ptes in that case, but it would be a silly change, just to make what smaps shows easier to explain.
Hugh
Quoted 75 lines · Hugh Dickins
Quoted 62 lines · Yang Shi
The commit
7635d9cbe832("mm, thp, proc: report THP eligibility for each vma") introduced THPeligible bit for processes' smaps. But, when checking the eligibility for shmem vma,__transparent_hugepage_enabled()is called to override the result fromshmem_huge_enabled(). It may result in the anonymous vma's THP flag override shmem's. For example, running a simple test which create THP for shmem, but with anonymous THP disabled, when reading the process's smaps, it may show:7fc92ec00000-7fc92f000000 rw-s 00000000 00:14 27764
/dev/shm/test
Size: 4096 kB
...
[snip]
...
ShmemPmdMapped: 4096 kB
...
[snip]
...
THPeligible: 0And,
/proc/meminfodoes show THP allocated and PMD mapped too:ShmemHugePages: 4096 kB ShmemPmdMapped: 4096 kBThis doesn't make too much sense. The anonymous THP flag should not intervene shmem THP. Calling
shmem_huge_enabled()with checkingMMF_DISABLE_THPsounds good enough. And, we could skip stack and dax vma check since we already checked if the vma is shmem already.Fixes 7635d9cbe832 ("mm, thp, proc: report THP eligibility for each vma")Cc Michal Hocko <[email protected]>Cc Vlastimil Babka <[email protected]>Cc David Rientjes <[email protected]>Cc Kirill A. Shutemov <[email protected]>Signed-off-by Yang Shi <[email protected]>---
v2: CheckVM_NOHUGEPAGEper Michal Hockomm/huge_memory.c | 4 ++-- mm/shmem.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)mm/huge_memory.c +2
-2@@ -67,8 +67,8 @@ bool transparent_hugepage_enabled(struct vm_area_struct *vma) {if (vma_is_anonymous (vma))return __transparent_hugepage_enabled (vma); -if (vma_is_shmem (vma) &&shmem_huge_enabled (vma)) -return __transparent_hugepage_enabled (vma); +if (vma_is_shmem (vma)) +return shmem_huge_enabled (vma);return false; }mm/shmem.c +0
-0mm/shmem.c bool shmem_huge_enabled(struct vm_area_struct *vma) · line 3878
Quoted 6 lines
mm/shmem.c +3
-0@@ -3873,6 +3873,9 @@ bool shmem_huge_enabled(struct vm_area_struct *vma)loff_t i_size;pgoff_t off; +if ((vma->vm_flags &VM_NOHUGEPAGE ) || +test_bit (MMF_DISABLE_THP , &vma->vm_mm->flags)) +return false;Yes, that is correct; and correctly placed. But a little more is needed:
see how mm/memory.c'stranshuge_vma_suitable()will only allow a pmd to be used instead of a pte if the vma offset and size permit. smaps should not report a shmem vma as THPeligible if its offset or size prevent it.
Quoted 6 lines
And I see that should also be fixed on anon vmas: at present smaps reports even a 4kB anon vma as THPeligible, which is not right. Maybe a test like
transhuge_vma_suitable()can be added intotransparent_hugepage_enabled(), to handle anon and shmem together. I say "liketranshuge_vma_suitable()", because that function needs an address, which here you don't have.
Thanks for the remind. Since we don't have an address I'm supposed we just need check if the vma's size is big enough or not other than other alignment check.
And, I'm wondering whether we could reuse transhuge_vma_suitable() by passing in an impossible address, i.e. -1 since it is not a valid userspace address. It can be used as and indicator that this call is from THPeligible context.
Quoted 7 lines
The anon offset situation is interesting: usually anon
vm_pgoffis initialized to fit with itsvm_start, so the anon offset check passes; but I wonder what happens after mremap to a different address - doestranshuge_vma_suitable()then prevent the use of pmds where they could actually be used? Not a Number#1 priority to investigate or fix here! but a curiosity someone might want to look into.
Will mark on my TODO list.
Quoted 8 lines
Quoted 6 lines
mm/shmem.c +0
-0if (shmem_huge ==SHMEM_HUGE_FORCE )return true;if (shmem_huge ==SHMEM_HUGE_DENY )Signature · 1 line
1.8.3.1Even with your changes
Quoted 8 lines
ShmemPmdMapped: 4096 kB THPeligible: 0 will easily be seen: THPeligible reflects whether a huge page can beallocated and mapped by pmd in that vma; but if something else already allocated the huge page earlier, it will be mapped by pmd in this vma if offset and size allow, whatever THPeligible says. We could change
transhuge_vma_suitable()to force ptes in that case, but it would be a silly change, just to make what smaps shows easier to explain.
Where did this come from? From the commit log? If so it is the example for the wrong smap output. If that case really happens, I think we could document it since THPeligible should just show the current status.
Quoted 2 lines
Hugh
Hugh Dickins
maintainerQuoted 13 lines · Yang Shi
Quoted 11 lines · Hugh Dickins
Yes, that is correct; and correctly placed. But a little more is needed:
see how mm/memory.c'stranshuge_vma_suitable()will only allow a pmd to be used instead of a pte if the vma offset and size permit. smaps should not report a shmem vma as THPeligible if its offset or size prevent it.And I see that should also be fixed on anon vmas: at present smaps reports even a 4kB anon vma as THPeligible, which is not right. Maybe a test like
transhuge_vma_suitable()can be added intotransparent_hugepage_enabled(), to handle anon and shmem together. I say "liketranshuge_vma_suitable()", because that function needs an address, which here you don't have.
Quoted 7 lines
Thanks for the remind. Since we don't have an address I'm supposed we just need check if the vma's size is big enough or not other than other alignment check.
And, I'm wondering whether we could reuse
transhuge_vma_suitable()by passing in an impossible address, i.e. -1 since it is not a valid userspace address. It can be used as and indicator that this call is from THPeligible context.
Perhaps, but sounds like it will abuse and uglify transhuge_vma_suitable() just for smaps. Would passing transhuge_vma_suitable() the address
((vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE)
give the the correct answer in all cases?
Quoted 20 lines
Quoted 7 lines
The anon offset situation is interesting: usually anon
vm_pgoffis initialized to fit with itsvm_start, so the anon offset check passes; but I wonder what happens after mremap to a different address - doestranshuge_vma_suitable()then prevent the use of pmds where they could actually be used? Not a Number#1 priority to investigate or fix here! but a curiosity someone might want to look into.Will mark on my TODO list.
Quoted 9 lines
Even with your changes
ShmemPmdMapped: 4096 kB THPeligible: 0 will easily be seen: THPeligible reflects whether a huge page can beallocated and mapped by pmd in that vma; but if something else already allocated the huge page earlier, it will be mapped by pmd in this vma if offset and size allow, whatever THPeligible says. We could change
transhuge_vma_suitable()to force ptes in that case, but it would be a silly change, just to make what smaps shows easier to explain.
Quoted 3 lines
Where did this come from? From the commit log? If so it is the example for the wrong smap output. If that case really happens, I think we could document it since THPeligible should just show the current status.
Please read again what I explained there: it's not necessarily an example of wrong smaps output, it's reasonable smaps output for a reasonable case.
Yes, maybe Documentation/filesystems/proc.txt should explain "THPeligble" a little better - "eligible for allocating THP pages" rather than just "eligible for THP pages" would be good enough? we don't want to write a book about the various cases.
Oh, and the "THPeligible" output lines up very nicely there in proc.txt:
could the actual alignment of that 0 or 1 be fixed in smaps itself too?
Thanks,
Hugh
Quoted 17 lines · Hugh Dickins
Quoted 16 lines · Yang Shi
Quoted 11 lines · Hugh Dickins
Yes, that is correct; and correctly placed. But a little more is needed:
see how mm/memory.c'stranshuge_vma_suitable()will only allow a pmd to be used instead of a pte if the vma offset and size permit. smaps should not report a shmem vma as THPeligible if its offset or size prevent it.And I see that should also be fixed on anon vmas: at present smaps reports even a 4kB anon vma as THPeligible, which is not right. Maybe a test like
transhuge_vma_suitable()can be added intotransparent_hugepage_enabled(), to handle anon and shmem together. I say "liketranshuge_vma_suitable()", because that function needs an address, which here you don't have.Thanks for the remind. Since we don't have an address I'm supposed we just need check if the vma's size is big enough or not other than other alignment check.
Quoted 7 lines
Quoted 3 lines
And, I'm wondering whether we could reuse
transhuge_vma_suitable()by passing in an impossible address, i.e. -1 since it is not a valid userspace address. It can be used as and indicator that this call is from THPeligible context.Perhaps, but sounds like it will abuse and uglify
transhuge_vma_suitable()just for smaps. Would passingtranshuge_vma_suitable()the address((vma->vm_end & HPAGE_PMD_MASK) - HPAGE_PMD_SIZE)give the the correct answer in all cases?
Yes, it looks better.
Quoted 21 lines
Quoted 18 lines
Quoted 7 lines
The anon offset situation is interesting: usually anon
vm_pgoffis initialized to fit with itsvm_start, so the anon offset check passes; but I wonder what happens after mremap to a different address - doestranshuge_vma_suitable()then prevent the use of pmds where they could actually be used? Not a Number#1 priority to investigate or fix here! but a curiosity someone might want to look into.Will mark on my TODO list.
Quoted 9 lines
Even with your changes
ShmemPmdMapped: 4096 kB THPeligible: 0 will easily be seen: THPeligible reflects whether a huge page can beallocated and mapped by pmd in that vma; but if something else already allocated the huge page earlier, it will be mapped by pmd in this vma if offset and size allow, whatever THPeligible says. We could change
transhuge_vma_suitable()to force ptes in that case, but it would be a silly change, just to make what smaps shows easier to explain.Quoted 3 lines
Where did this come from? From the commit log? If so it is the example for the wrong smap output. If that case really happens, I think we could document it since THPeligible should just show the current status.
Quoted 7 lines
Please read again what I explained there: it's not necessarily an example of wrong smaps output, it's reasonable smaps output for a reasonable case.
Yes, maybe
Documentation/filesystems/proc.txtshould explain "THPeligble" a little better - "eligible for allocating THP pages" rather than just "eligible for THP pages" would be good enough? we don't want to write a book about the various cases.
Yes, I agree.
Quoted 3 lines
Oh, and the "THPeligible" output lines up very nicely there in proc.txt:
could the actual alignment of that 0 or 1 be fixed in smaps itself too?
Sure.
Thanks,
Yang
Quoted 3 lines
Thanks,
Hugh