adjust the logic of checking THP
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected];[email protected];[email protected];[email protected]
PATCH 1/1 adjust the logic of checking THP
Acturally, pmd_trans_huge(orig_pmd) only checks the _PAGE_PSE bits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.
--- mm/memory.c | 28 +++++++++++++++------------- 1 files changed, 15 insertions(+), 13 deletions(-)
mm/memory.c +15 -13
@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd =pmd_alloc (mm, pud, address);if (!pmd)return VM_FAULT_OOM ; -if (pmd_none (*pmd) &&transparent_hugepage_enabled (vma)) { -if (!vma->vm_ops) -return do_huge_pmd_anonymous_page (mm, vma, address, - pmd, flags); - }else { -pmd_t orig_pmd = *pmd; -barrier (); -if (pmd_trans_huge (orig_pmd)) { -if (flags &FAULT_FLAG_WRITE && - !pmd_write (orig_pmd) && - !pmd_trans_splitting (orig_pmd)) -return do_huge_pmd_wp_page (mm, vma, address, - pmd, orig_pmd); +if (transparent_hugepage_enabled (vma)) { +if (pmd_none (*pmd)) { +if (!vma->vm_ops) +return do_huge_pmd_anonymous_page (mm, vma, address, + pmd, flags); + }else { +pmd_t orig_pmd = *pmd; +barrier (); +if (pmd_trans_huge (orig_pmd)) { +if (flags &FAULT_FLAG_WRITE && + !pmd_write (orig_pmd) && + !pmd_trans_splitting (orig_pmd)) +return do_huge_pmd_wp_page (mm, vma, address, + pmd, orig_pmd);return 0 ; + } } }
Signature · 1 line
1.7.7
Quoted 26 lines · Guanjun He
Acturally,
pmd_trans_huge(orig_pmd)only checks the_PAGE_PSEbits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.Signed-off-by Guanjun He <[email protected]>---
mm/memory.c | 28 +++++++++++++++-------------1 files changed, 15 insertions(+), 13 deletions(-)mm/memory.c +0
-4@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd = pmd_alloc(mm, pud, address); if (!pmd) return VM_FAULT_OOM; - if (pmd_none(*pmd) && transparent_hugepage_enabled(vma)) { - if (!vma->vm_ops) - return do_huge_pmd_anonymous_page(mm, vma, address, - pmd, flags);
mm/memory.c int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, · line 3468
Quoted 10 lines
mm/memory.c +1
-9- } else { - pmd_t orig_pmd = *pmd; - barrier(); - if (pmd_trans_huge(orig_pmd)) { - if (flags & FAULT_FLAG_WRITE && - !pmd_write(orig_pmd) && - !pmd_trans_splitting(orig_pmd)) - return do_huge_pmd_wp_page(mm, vma, address, - pmd, orig_pmd); + if (transparent_hugepage_enabled(vma)) {
Well, how about THP not configured?
Thanks,
Hillf
Quoted 21 lines
mm/memory.c +14
-1+ if (pmd_none(*pmd)) { + if (!vma->vm_ops) + return do_huge_pmd_anonymous_page(mm, vma, address, + pmd, flags); + } else { + pmd_t orig_pmd = *pmd; + barrier(); + if (pmd_trans_huge(orig_pmd)) { + if (flags & FAULT_FLAG_WRITE && + !pmd_write(orig_pmd) && + !pmd_trans_splitting(orig_pmd)) + return do_huge_pmd_wp_page(mm, vma, address, + pmd, orig_pmd); return 0; + } } } --1.7.7
Quoted 8 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m����������?�I�
Quoted 31 lines · Hillf Danton
Quoted 30 lines · Guanjun He
Acturally,
pmd_trans_huge(orig_pmd)only checks the_PAGE_PSEbits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.Signed-off-by Guanjun He <[email protected]>---
mm/memory.c | 28 +++++++++++++++-------------1 files changed, 15 insertions(+), 13 deletions(-)mm/memory.c +0
-8@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd = pmd_alloc(mm, pud, address); if (!pmd) return VM_FAULT_OOM; - if (pmd_none(*pmd) && transparent_hugepage_enabled(vma)) { - if (!vma->vm_ops) - return do_huge_pmd_anonymous_page(mm, vma, address, - pmd, flags); - } else { - pmd_t orig_pmd = *pmd; - barrier(); - if (pmd_trans_huge(orig_pmd)) {
Quoted 8 lines
mm/memory.c int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, · line 3468
Quoted 6 lines
mm/memory.c +1
-5- if (flags & FAULT_FLAG_WRITE && - !pmd_write(orig_pmd) && - !pmd_trans_splitting(orig_pmd)) - return do_huge_pmd_wp_page(mm, vma, address, - pmd, orig_pmd); + if (transparent_hugepage_enabled(vma)) {Well, how about THP not configured?
What do you mean 'not configured'? assume not enabled. If THP not enabled, of course the transparent_hugepage_enabled(vma) will be false.
Quoted 34 lines
Thanks,
HillfQuoted 29 lines
mm/memory.c +14
-1+ if (pmd_none(*pmd)) { + if (!vma->vm_ops) + return do_huge_pmd_anonymous_page(mm, vma, address, + pmd, flags); + } else { + pmd_t orig_pmd = *pmd; + barrier(); + if (pmd_trans_huge(orig_pmd)) { + if (flags & FAULT_FLAG_WRITE && + !pmd_write(orig_pmd) && + !pmd_trans_splitting(orig_pmd)) + return do_huge_pmd_wp_page(mm, vma, address, + pmd, orig_pmd); return 0; + } } } --1.7.7
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Quoted 41 lines · GuanJun He
Quoted 31 lines · Hillf Danton
Quoted 30 lines · Guanjun He
Acturally,
pmd_trans_huge(orig_pmd)only checks the_PAGE_PSEbits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.Signed-off-by Guanjun He <[email protected]>---
mm/memory.c | 28 +++++++++++++++-------------1 files changed, 15 insertions(+), 13 deletions(-)mm/memory.c +0
-8@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd = pmd_alloc(mm, pud, address); if (!pmd) return VM_FAULT_OOM; - if (pmd_none(*pmd) && transparent_hugepage_enabled(vma)) { - if (!vma->vm_ops) - return do_huge_pmd_anonymous_page(mm, vma, address, - pmd, flags); - } else { - pmd_t orig_pmd = *pmd; - barrier(); - if (pmd_trans_huge(orig_pmd)) {Quoted 8 lines
mm/memory.c int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, · line 3468
Quoted 6 lines
mm/memory.c +1
-5- if (flags & FAULT_FLAG_WRITE && - !pmd_write(orig_pmd) && - !pmd_trans_splitting(orig_pmd)) - return do_huge_pmd_wp_page(mm, vma, address, - pmd, orig_pmd); + if (transparent_hugepage_enabled(vma)) {Well, how about THP not configured?
Quoted 3 lines
What do you mean 'not configured'? assume not enabled. If THP not enabled, of course the
transparent_hugepage_enabled(vma)will be false.
In the original logic, it's possible that the code go into the logic of THP while the THP is not enabled.
Just think, If build another module that make pmd with the same bits, even THP is not enabled, the code can go into the logic of the THP.And this adjust can avoid this.
best,
Guanjun
Quoted 26 lines
Quoted 26 lines
Thanks,
HillfQuoted 21 lines
mm/memory.c +14
-1+ if (pmd_none(*pmd)) { + if (!vma->vm_ops) + return do_huge_pmd_anonymous_page(mm, vma, address, + pmd, flags); + } else { + pmd_t orig_pmd = *pmd; + barrier(); + if (pmd_trans_huge(orig_pmd)) { + if (flags & FAULT_FLAG_WRITE && + !pmd_write(orig_pmd) && + !pmd_trans_splitting(orig_pmd)) + return do_huge_pmd_wp_page(mm, vma, address, + pmd, orig_pmd); return 0; + } } } --1.7.7
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · Guanjun He
Acturally,
pmd_trans_huge(orig_pmd)only checks the_PAGE_PSEbits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.
You can't use _PAGE_PSE for special use for the pmd. Besides this is common code, archs without such bit can define pmd_trans_huge to return 0 like it happens with TRANSPARENT_HUGEPAGE=n.
Quoted 27 lines
mm/memory.c +6
-13@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd =pmd_alloc (mm, pud, address);if (!pmd)return VM_FAULT_OOM ; -if (pmd_none (*pmd) &&transparent_hugepage_enabled (vma)) { -if (!vma->vm_ops) -return do_huge_pmd_anonymous_page (mm, vma, address, - pmd, flags); - }else { -pmd_t orig_pmd = *pmd; -barrier (); -if (pmd_trans_huge (orig_pmd)) { -if (flags &FAULT_FLAG_WRITE && - !pmd_write (orig_pmd) && - !pmd_trans_splitting (orig_pmd)) -return do_huge_pmd_wp_page (mm, vma, address, - pmd, orig_pmd); +if (transparent_hugepage_enabled (vma)) { +if (pmd_none (*pmd)) { +if (!vma->vm_ops) +return do_huge_pmd_anonymous_page (mm, vma, address, + pmd, flags); + }else {
mm/memory.c int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, · line 3483
Quoted 10 lines
mm/memory.c +9
-0+pmd_t orig_pmd = *pmd; +barrier (); +if (pmd_trans_huge (orig_pmd)) { +if (flags &FAULT_FLAG_WRITE && + !pmd_write (orig_pmd) && + !pmd_trans_splitting (orig_pmd)) +return do_huge_pmd_wp_page (mm, vma, address, + pmd, orig_pmd);return 0 ; + }
This will infinite loop if you disable THP at runtime while some mapping needing cow is established.
Quoted 9 lines · Andrea Arcangeli
Quoted 7 lines · Guanjun He
Acturally,
pmd_trans_huge(orig_pmd)only checks the_PAGE_PSEbits, it's a pmd entry bits, only mark a size, not a flag;As one can easily create the same pmd entry bits for some special use,then the check will get confused.And this patch is to adjust the logic to use the flag, it can perfectly avoid this potential issuse,and basically no impact to the current code.
Quoted 3 lines
You can't use
_PAGE_PSEfor special use for the pmd. Besides this is common code, archs without such bit can definepmd_trans_hugeto return 0 like it happens with TRANSPARENT_HUGEPAGE=n.
ok, even _PAGE_PSE can not be used for special use for the pmd, This check is more efficient.
the original code always check 2 items " pmd_none(*pmd) && transparent_hugepage_enabled(vma) ",
even TRANSPARENT_HUGEPAGE not enabled.
Quoted 41 lines
Quoted 28 lines
mm/memory.c +6
-13@@ -3465,20 +3465,22 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, pmd = pmd_alloc(mm, pud, address); if (!pmd) return VM_FAULT_OOM; - if (pmd_none(*pmd) && transparent_hugepage_enabled(vma)) { - if (!vma->vm_ops) - return do_huge_pmd_anonymous_page(mm, vma, address, - pmd, flags); - } else { - pmd_t orig_pmd = *pmd; - barrier(); - if (pmd_trans_huge(orig_pmd)) { - if (flags & FAULT_FLAG_WRITE && - !pmd_write(orig_pmd) && - !pmd_trans_splitting(orig_pmd)) - return do_huge_pmd_wp_page(mm, vma, address, - pmd, orig_pmd); + if (transparent_hugepage_enabled(vma)) { + if (pmd_none(*pmd)) { + if (!vma->vm_ops) + return do_huge_pmd_anonymous_page(mm, vma, address, + pmd, flags); + } else {mm/memory.c int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma, · line 3483
Quoted 10 lines
mm/memory.c +9
-0+ pmd_t orig_pmd = *pmd; + barrier(); + if (pmd_trans_huge(orig_pmd)) { + if (flags & FAULT_FLAG_WRITE && + !pmd_write(orig_pmd) && + !pmd_trans_splitting(orig_pmd)) + return do_huge_pmd_wp_page(mm, vma, address, + pmd, orig_pmd); return 0; + }This will infinite loop if you disable THP at runtime while some mapping needing cow is established.