mm/page_vma_mapped_walk: Use ptep_get_lockless() for lockless access
Subsystems (3)
Alexander Gordeev
maintainerPATCH v3 1/1 mm/page_vma_mapped_walk: Use ptep_get_lockless() for lockless access
Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.
--- mm/page_vma_mapped.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +7 -2
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!pvmw->pte)return false; - ptent =ptep_get (pvmw->pte); + ptent =ptep_get_lockless (pvmw->pte);if (pte_none (ptent)) {return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)struct mm_struct *mm = vma->vm_mm;unsigned long end;spinlock_t *ptl; +pte_t pteval;pgd_t *pgd;p4d_t *p4d;pud_t *pud;
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) goto restart; } pvmw->pte++; - }while (pte_none (ptep_get (pvmw->pte))); +if (!pvmw->ptl) + pteval =ptep_get_lockless (pvmw->pte); +else + pteval =ptep_get (pvmw->pte); + }while (pte_none (pteval));if (!pvmw->ptl) {spin_lock (ptl);
Signature · 1 line
2.51.0
Quoted 30 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.Signed-off-by Alexander Gordeev <[email protected]>---
mm/page_vma_mapped.c| 9 +++++++--1 file changed, 7 insertions(+), 2 deletions(-)mm/page_vma_mapped.c +2
-1@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!pvmw->pte)return false; - ptent =ptep_get (pvmw->pte); + ptent =ptep_get_lockless (pvmw->pte);if (pte_none (ptent)) {return false;@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)struct mm_struct *mm = vma->vm_mm;unsigned long end;spinlock_t *ptl; +pte_t pteval;pgd_t *pgd;p4d_t *p4d;pud_t *pud;
mm/page_vma_mapped.c bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) · line 318
Quoted 9 lines
mm/page_vma_mapped.c +5
-1@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) goto restart; } pvmw->pte++; - }while (pte_none (ptep_get (pvmw->pte))); +if (!pvmw->ptl) + pteval =ptep_get_lockless (pvmw->pte); +else + pteval =ptep_get (pvmw->pte); + }while (pte_none (pteval));
Use ptep_get_lockless() when lock is not taken.
LGTM, thanks
Quoted 5 lines
mm/page_vma_mapped.c +0
-0if (!pvmw->ptl) {spin_lock (ptl);Signature · 1 line
2.51.0
Signature · 2 lines
Wei Yang Help you, Help me
Lorenzo Stoakes
maintainerQuoted 2 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.
This is an insufficient commit message that's just saying what you're doing, which isn't very useful.
Please explain why you're doing this and what the benefit is please.
Thanks, Lorenzo
Quoted 43 lines
Signed-off-by Alexander Gordeev <[email protected]>--- mm/page_vma_mapped.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)mm/page_vma_mapped.c +7
-3@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!pvmw->pte)return false; - ptent =ptep_get (pvmw->pte); + ptent =ptep_get_lockless (pvmw->pte);if (pte_none (ptent)) {return false;@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)struct mm_struct *mm = vma->vm_mm;unsigned long end;spinlock_t *ptl; +pte_t pteval;pgd_t *pgd;p4d_t *p4d;pud_t *pud;@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) goto restart; } pvmw->pte++; - }while (pte_none (ptep_get (pvmw->pte))); +if (!pvmw->ptl) + pteval =ptep_get_lockless (pvmw->pte); +else + pteval =ptep_get (pvmw->pte); + }while (pte_none (pteval));if (!pvmw->ptl) {spin_lock (ptl); --2.51.0
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.This is an insufficient commit message that's just saying what you're doing, which isn't very useful.
Please explain why you're doing this and what the benefit is please.
Maybe something like
"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."
Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.
Signature · 2 lines
Oscar Salvador SUSE Labs
Alexander Gordeev
maintainerQuoted 8 lines · Oscar Salvador (SUSE)
Quoted 7 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.This is an insufficient commit message that's just saying what you're doing, which isn't very useful.
Quoted 7 lines
Quoted 1 line
Please explain why you're doing this and what the benefit is please.
Maybe something like
"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."
I would gladly use this, if it makes sense for everyone.
@Lorenzo?
Quoted 2 lines
Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.
Thanks!
Quoted 3 lines
Signature · 2 lines
Oscar Salvador SUSE Labs
Lorenzo Stoakes
maintainerQuoted 13 lines · Alexander Gordeev
Quoted 12 lines · Oscar Salvador (SUSE)
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.This is an insufficient commit message that's just saying what you're doing, which isn't very useful.
Please explain why you're doing this and what the benefit is please.
Maybe something like
Quoted 7 lines
Quoted 3 lines
"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."I would gladly use this, if it makes sense for everyone.
@Lorenzo?
Sounds good to me! Thanks
Quoted 9 lines
Quoted 3 lines
Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.
Thanks!
Quoted 3 lines
--
Oscar Salvador
SUSE Labs
Cheers, Lorenzo
Quoted 4 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.Signed-off-by Alexander Gordeev <[email protected]>
I see Andrew has picked up the patch with the amended changelog, so with that:
Quoted 41 lines
--- mm/page_vma_mapped.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)mm/page_vma_mapped.c +7
-2@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!pvmw->pte)return false; - ptent =ptep_get (pvmw->pte); + ptent =ptep_get_lockless (pvmw->pte);if (pte_none (ptent)) {return false;@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)struct mm_struct *mm = vma->vm_mm;unsigned long end;spinlock_t *ptl; +pte_t pteval;pgd_t *pgd;p4d_t *p4d;pud_t *pud;@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) goto restart; } pvmw->pte++; - }while (pte_none (ptep_get (pvmw->pte))); +if (!pvmw->ptl) + pteval =ptep_get_lockless (pvmw->pte); +else + pteval =ptep_get (pvmw->pte); + }while (pte_none (pteval));if (!pvmw->ptl) {spin_lock (ptl);Signature · 1 line
2.51.0
Signature · 2 lines
Oscar Salvador SUSE Labs
Quoted 5 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.Signed-off-by Alexander Gordeev <[email protected]>---
Signature · 3 lines
Cheers, David
Quoted 4 lines · Alexander Gordeev
Switch from
ptep_get()toptep_get_lockless()accessor for PTE reads when no lock is taken.Signed-off-by Alexander Gordeev <[email protected]>
Oh and the logic looks good so with the commit message updated, feel free to add:
Quoted 41 lines
--- mm/page_vma_mapped.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)mm/page_vma_mapped.c +7
-3@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,if (!pvmw->pte)return false; - ptent =ptep_get (pvmw->pte); + ptent =ptep_get_lockless (pvmw->pte);if (pte_none (ptent)) {return false;@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)struct mm_struct *mm = vma->vm_mm;unsigned long end;spinlock_t *ptl; +pte_t pteval;pgd_t *pgd;p4d_t *p4d;pud_t *pud;@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) goto restart; } pvmw->pte++; - }while (pte_none (ptep_get (pvmw->pte))); +if (!pvmw->ptl) + pteval =ptep_get_lockless (pvmw->pte); +else + pteval =ptep_get (pvmw->pte); + }while (pte_none (pteval));if (!pvmw->ptl) {spin_lock (ptl); --2.51.0