All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-07 14:33 ` Kirill A. Shutemov
  0 siblings, 0 replies; 10+ messages in thread
From: Kirill A. Shutemov @ 2017-02-07 14:33 UTC (permalink / raw)
  To: Andrea Arcangeli, Mel Gorman, Andrew Morton
  Cc: linux-mm, linux-kernel, Kirill A. Shutemov

lock_pte_protection() uses pmd_lock() to make sure that we have stable
PTE page table before walking pte range.

That's not necessary. We only need to make sure that PTE page table is
established. It cannot vanish under us as long as we hold mmap_sem at
least for read.

And we already have helper for that -- pmd_trans_unstable().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 mm/mprotect.c | 43 ++++++++++++-------------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index f9c07f54dd62..e919e4613eab 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -33,34 +33,6 @@
 
 #include "internal.h"
 
-/*
- * For a prot_numa update we only hold mmap_sem for read so there is a
- * potential race with faulting where a pmd was temporarily none. This
- * function checks for a transhuge pmd under the appropriate lock. It
- * returns a pte if it was successfully locked or NULL if it raced with
- * a transhuge insertion.
- */
-static pte_t *lock_pte_protection(struct vm_area_struct *vma, pmd_t *pmd,
-			unsigned long addr, int prot_numa, spinlock_t **ptl)
-{
-	pte_t *pte;
-	spinlock_t *pmdl;
-
-	/* !prot_numa is protected by mmap_sem held for write */
-	if (!prot_numa)
-		return pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
-
-	pmdl = pmd_lock(vma->vm_mm, pmd);
-	if (unlikely(pmd_trans_huge(*pmd) || pmd_none(*pmd))) {
-		spin_unlock(pmdl);
-		return NULL;
-	}
-
-	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
-	spin_unlock(pmdl);
-	return pte;
-}
-
 static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 		unsigned long addr, unsigned long end, pgprot_t newprot,
 		int dirty_accountable, int prot_numa)
@@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 	unsigned long pages = 0;
 	int target_node = NUMA_NO_NODE;
 
-	pte = lock_pte_protection(vma, pmd, addr, prot_numa, &ptl);
+	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
 	if (!pte)
 		return 0;
 
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
 			if (next - addr != HPAGE_PMD_SIZE) {
 				__split_huge_pmd(vma, pmd, addr, false, NULL);
-				if (pmd_trans_unstable(pmd))
-					continue;
 			} else {
 				int nr_ptes = change_huge_pmd(vma, pmd, addr,
 						newprot, prot_numa);
@@ -195,6 +165,17 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 			}
 			/* fall through, the trans huge pmd just split */
 		}
+
+		/*
+		 * For prot_numa update we only hold mmap_sem for read so there
+		 * is a potential race with faulting where a pmd was
+		 * temporarily none.
+		 * Make sure we have PTE page table, before moving forward.
+		 * Page tables cannot go away under us as long as we hold
+		 * mmap_sem at least for read.
+		 */
+		if (pmd_trans_unstable(pmd))
+			continue;
 		this_pages = change_pte_range(vma, pmd, addr, next, newprot,
 				 dirty_accountable, prot_numa);
 		pages += this_pages;
-- 
2.11.0

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-07 14:33 ` Kirill A. Shutemov
  0 siblings, 0 replies; 10+ messages in thread
From: Kirill A. Shutemov @ 2017-02-07 14:33 UTC (permalink / raw)
  To: Andrea Arcangeli, Mel Gorman, Andrew Morton
  Cc: linux-mm, linux-kernel, Kirill A. Shutemov

lock_pte_protection() uses pmd_lock() to make sure that we have stable
PTE page table before walking pte range.

That's not necessary. We only need to make sure that PTE page table is
established. It cannot vanish under us as long as we hold mmap_sem at
least for read.

And we already have helper for that -- pmd_trans_unstable().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 mm/mprotect.c | 43 ++++++++++++-------------------------------
 1 file changed, 12 insertions(+), 31 deletions(-)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index f9c07f54dd62..e919e4613eab 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -33,34 +33,6 @@
 
 #include "internal.h"
 
-/*
- * For a prot_numa update we only hold mmap_sem for read so there is a
- * potential race with faulting where a pmd was temporarily none. This
- * function checks for a transhuge pmd under the appropriate lock. It
- * returns a pte if it was successfully locked or NULL if it raced with
- * a transhuge insertion.
- */
-static pte_t *lock_pte_protection(struct vm_area_struct *vma, pmd_t *pmd,
-			unsigned long addr, int prot_numa, spinlock_t **ptl)
-{
-	pte_t *pte;
-	spinlock_t *pmdl;
-
-	/* !prot_numa is protected by mmap_sem held for write */
-	if (!prot_numa)
-		return pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
-
-	pmdl = pmd_lock(vma->vm_mm, pmd);
-	if (unlikely(pmd_trans_huge(*pmd) || pmd_none(*pmd))) {
-		spin_unlock(pmdl);
-		return NULL;
-	}
-
-	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
-	spin_unlock(pmdl);
-	return pte;
-}
-
 static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 		unsigned long addr, unsigned long end, pgprot_t newprot,
 		int dirty_accountable, int prot_numa)
@@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
 	unsigned long pages = 0;
 	int target_node = NUMA_NO_NODE;
 
-	pte = lock_pte_protection(vma, pmd, addr, prot_numa, &ptl);
+	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
 	if (!pte)
 		return 0;
 
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
 			if (next - addr != HPAGE_PMD_SIZE) {
 				__split_huge_pmd(vma, pmd, addr, false, NULL);
-				if (pmd_trans_unstable(pmd))
-					continue;
 			} else {
 				int nr_ptes = change_huge_pmd(vma, pmd, addr,
 						newprot, prot_numa);
@@ -195,6 +165,17 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 			}
 			/* fall through, the trans huge pmd just split */
 		}
+
+		/*
+		 * For prot_numa update we only hold mmap_sem for read so there
+		 * is a potential race with faulting where a pmd was
+		 * temporarily none.
+		 * Make sure we have PTE page table, before moving forward.
+		 * Page tables cannot go away under us as long as we hold
+		 * mmap_sem at least for read.
+		 */
+		if (pmd_trans_unstable(pmd))
+			continue;
 		this_pages = change_pte_range(vma, pmd, addr, next, newprot,
 				 dirty_accountable, prot_numa);
 		pages += this_pages;
-- 
2.11.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
  2017-02-07 14:33 ` Kirill A. Shutemov
@ 2017-02-07 21:29   ` Andrea Arcangeli
  -1 siblings, 0 replies; 10+ messages in thread
From: Andrea Arcangeli @ 2017-02-07 21:29 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Mel Gorman, Andrew Morton, linux-mm, linux-kernel

On Tue, Feb 07, 2017 at 05:33:47PM +0300, Kirill A. Shutemov wrote:
> lock_pte_protection() uses pmd_lock() to make sure that we have stable
> PTE page table before walking pte range.
> 
> That's not necessary. We only need to make sure that PTE page table is
> established. It cannot vanish under us as long as we hold mmap_sem at
> least for read.
> 
> And we already have helper for that -- pmd_trans_unstable().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> ---
>  mm/mprotect.c | 43 ++++++++++++-------------------------------
>  1 file changed, 12 insertions(+), 31 deletions(-)
> 
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index f9c07f54dd62..e919e4613eab 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -33,34 +33,6 @@
>  
>  #include "internal.h"
>  
> -/*
> - * For a prot_numa update we only hold mmap_sem for read so there is a
> - * potential race with faulting where a pmd was temporarily none. This
> - * function checks for a transhuge pmd under the appropriate lock. It
> - * returns a pte if it was successfully locked or NULL if it raced with
> - * a transhuge insertion.
> - */
> -static pte_t *lock_pte_protection(struct vm_area_struct *vma, pmd_t *pmd,
> -			unsigned long addr, int prot_numa, spinlock_t **ptl)
> -{
> -	pte_t *pte;
> -	spinlock_t *pmdl;
> -
> -	/* !prot_numa is protected by mmap_sem held for write */
> -	if (!prot_numa)
> -		return pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
> -
> -	pmdl = pmd_lock(vma->vm_mm, pmd);
> -	if (unlikely(pmd_trans_huge(*pmd) || pmd_none(*pmd))) {
> -		spin_unlock(pmdl);
> -		return NULL;
> -	}
> -
> -	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
> -	spin_unlock(pmdl);
> -	return pte;
> -}
> -
>  static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  		unsigned long addr, unsigned long end, pgprot_t newprot,
>  		int dirty_accountable, int prot_numa)
> @@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  	unsigned long pages = 0;
>  	int target_node = NUMA_NO_NODE;
>  
> -	pte = lock_pte_protection(vma, pmd, addr, prot_numa, &ptl);
> +	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
>  	if (!pte)

I cleaned it up too but I moved the pmd_trans_unstable in the caller
above instead of the callee, otherwise it's the same.

>  
> @@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
>  		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
>  			if (next - addr != HPAGE_PMD_SIZE) {
>  				__split_huge_pmd(vma, pmd, addr, false, NULL);
> -				if (pmd_trans_unstable(pmd))
> -					continue;

Agree it can be removed too, but I only removed lock_pte_protection in
my version.

If you prefer this version to be merged so we don't have to cleanup
the above superfluous check in a incremental patch that's fine of
course, otherwise at runtime they're equivalent as far as I can
tell. The version in -mm is here.

https://git.kernel.org/cgit/linux/kernel/git/mhocko/mm.git/commit/?h=auto-latest&id=d84ff4e4985f397ca4ecfe7ec029c45c6f2b9906

Thanks,
Andrea

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-07 21:29   ` Andrea Arcangeli
  0 siblings, 0 replies; 10+ messages in thread
From: Andrea Arcangeli @ 2017-02-07 21:29 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Mel Gorman, Andrew Morton, linux-mm, linux-kernel

On Tue, Feb 07, 2017 at 05:33:47PM +0300, Kirill A. Shutemov wrote:
> lock_pte_protection() uses pmd_lock() to make sure that we have stable
> PTE page table before walking pte range.
> 
> That's not necessary. We only need to make sure that PTE page table is
> established. It cannot vanish under us as long as we hold mmap_sem at
> least for read.
> 
> And we already have helper for that -- pmd_trans_unstable().
> 
> Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> ---
>  mm/mprotect.c | 43 ++++++++++++-------------------------------
>  1 file changed, 12 insertions(+), 31 deletions(-)
> 
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index f9c07f54dd62..e919e4613eab 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -33,34 +33,6 @@
>  
>  #include "internal.h"
>  
> -/*
> - * For a prot_numa update we only hold mmap_sem for read so there is a
> - * potential race with faulting where a pmd was temporarily none. This
> - * function checks for a transhuge pmd under the appropriate lock. It
> - * returns a pte if it was successfully locked or NULL if it raced with
> - * a transhuge insertion.
> - */
> -static pte_t *lock_pte_protection(struct vm_area_struct *vma, pmd_t *pmd,
> -			unsigned long addr, int prot_numa, spinlock_t **ptl)
> -{
> -	pte_t *pte;
> -	spinlock_t *pmdl;
> -
> -	/* !prot_numa is protected by mmap_sem held for write */
> -	if (!prot_numa)
> -		return pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
> -
> -	pmdl = pmd_lock(vma->vm_mm, pmd);
> -	if (unlikely(pmd_trans_huge(*pmd) || pmd_none(*pmd))) {
> -		spin_unlock(pmdl);
> -		return NULL;
> -	}
> -
> -	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, ptl);
> -	spin_unlock(pmdl);
> -	return pte;
> -}
> -
>  static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  		unsigned long addr, unsigned long end, pgprot_t newprot,
>  		int dirty_accountable, int prot_numa)
> @@ -71,7 +43,7 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
>  	unsigned long pages = 0;
>  	int target_node = NUMA_NO_NODE;
>  
> -	pte = lock_pte_protection(vma, pmd, addr, prot_numa, &ptl);
> +	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
>  	if (!pte)

I cleaned it up too but I moved the pmd_trans_unstable in the caller
above instead of the callee, otherwise it's the same.

>  
> @@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
>  		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
>  			if (next - addr != HPAGE_PMD_SIZE) {
>  				__split_huge_pmd(vma, pmd, addr, false, NULL);
> -				if (pmd_trans_unstable(pmd))
> -					continue;

Agree it can be removed too, but I only removed lock_pte_protection in
my version.

If you prefer this version to be merged so we don't have to cleanup
the above superfluous check in a incremental patch that's fine of
course, otherwise at runtime they're equivalent as far as I can
tell. The version in -mm is here.

https://git.kernel.org/cgit/linux/kernel/git/mhocko/mm.git/commit/?h=auto-latest&id=d84ff4e4985f397ca4ecfe7ec029c45c6f2b9906

Thanks,
Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
  2017-02-07 14:33 ` Kirill A. Shutemov
@ 2017-02-07 21:44   ` Andrew Morton
  -1 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2017-02-07 21:44 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Andrea Arcangeli, Mel Gorman, linux-mm, linux-kernel

On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:

> lock_pte_protection() uses pmd_lock() to make sure that we have stable
> PTE page table before walking pte range.
> 
> That's not necessary. We only need to make sure that PTE page table is
> established. It cannot vanish under us as long as we hold mmap_sem at
> least for read.
> 
> And we already have helper for that -- pmd_trans_unstable().

http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
already did this?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-07 21:44   ` Andrew Morton
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2017-02-07 21:44 UTC (permalink / raw)
  To: Kirill A. Shutemov; +Cc: Andrea Arcangeli, Mel Gorman, linux-mm, linux-kernel

On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:

> lock_pte_protection() uses pmd_lock() to make sure that we have stable
> PTE page table before walking pte range.
> 
> That's not necessary. We only need to make sure that PTE page table is
> established. It cannot vanish under us as long as we hold mmap_sem at
> least for read.
> 
> And we already have helper for that -- pmd_trans_unstable().

http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
already did this?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
  2017-02-07 21:44   ` Andrew Morton
@ 2017-02-08 12:04     ` Kirill A. Shutemov
  -1 siblings, 0 replies; 10+ messages in thread
From: Kirill A. Shutemov @ 2017-02-08 12:04 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kirill A. Shutemov, Andrea Arcangeli, Mel Gorman, linux-mm, linux-kernel

On Tue, Feb 07, 2017 at 01:44:54PM -0800, Andrew Morton wrote:
> On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:
> 
> > lock_pte_protection() uses pmd_lock() to make sure that we have stable
> > PTE page table before walking pte range.
> > 
> > That's not necessary. We only need to make sure that PTE page table is
> > established. It cannot vanish under us as long as we hold mmap_sem at
> > least for read.
> > 
> > And we already have helper for that -- pmd_trans_unstable().
> 
> http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
> already did this?

Right. Except, it doesn't drop unneeded pmd_trans_unstable(pmd) check after
__split_huge_pmd().

Could you fold this part of my patch into Andrea's?

diff --git a/mm/mprotect.c b/mm/mprotect.c
index f9c07f54dd62..e919e4613eab 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
 			if (next - addr != HPAGE_PMD_SIZE) {
 				__split_huge_pmd(vma, pmd, addr, false, NULL);
-				if (pmd_trans_unstable(pmd))
-					continue;
 			} else {
 				int nr_ptes = change_huge_pmd(vma, pmd, addr,
 						newprot, prot_numa);
-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-08 12:04     ` Kirill A. Shutemov
  0 siblings, 0 replies; 10+ messages in thread
From: Kirill A. Shutemov @ 2017-02-08 12:04 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Kirill A. Shutemov, Andrea Arcangeli, Mel Gorman, linux-mm, linux-kernel

On Tue, Feb 07, 2017 at 01:44:54PM -0800, Andrew Morton wrote:
> On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:
> 
> > lock_pte_protection() uses pmd_lock() to make sure that we have stable
> > PTE page table before walking pte range.
> > 
> > That's not necessary. We only need to make sure that PTE page table is
> > established. It cannot vanish under us as long as we hold mmap_sem at
> > least for read.
> > 
> > And we already have helper for that -- pmd_trans_unstable().
> 
> http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
> already did this?

Right. Except, it doesn't drop unneeded pmd_trans_unstable(pmd) check after
__split_huge_pmd().

Could you fold this part of my patch into Andrea's?

diff --git a/mm/mprotect.c b/mm/mprotect.c
index f9c07f54dd62..e919e4613eab 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
 		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
 			if (next - addr != HPAGE_PMD_SIZE) {
 				__split_huge_pmd(vma, pmd, addr, false, NULL);
-				if (pmd_trans_unstable(pmd))
-					continue;
 			} else {
 				int nr_ptes = change_huge_pmd(vma, pmd, addr,
 						newprot, prot_numa);
-- 
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
  2017-02-08 12:04     ` Kirill A. Shutemov
@ 2017-02-08 13:45       ` Andrea Arcangeli
  -1 siblings, 0 replies; 10+ messages in thread
From: Andrea Arcangeli @ 2017-02-08 13:45 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Andrew Morton, Kirill A. Shutemov, Mel Gorman, linux-mm, linux-kernel

On Wed, Feb 08, 2017 at 03:04:21PM +0300, Kirill A. Shutemov wrote:
> On Tue, Feb 07, 2017 at 01:44:54PM -0800, Andrew Morton wrote:
> > On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:
> > 
> > > lock_pte_protection() uses pmd_lock() to make sure that we have stable
> > > PTE page table before walking pte range.
> > > 
> > > That's not necessary. We only need to make sure that PTE page table is
> > > established. It cannot vanish under us as long as we hold mmap_sem at
> > > least for read.
> > > 
> > > And we already have helper for that -- pmd_trans_unstable().
> > 
> > http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
> > already did this?
> 
> Right. Except, it doesn't drop unneeded pmd_trans_unstable(pmd) check after
> __split_huge_pmd().
> 
> Could you fold this part of my patch into Andrea's?

Reviewed-by: Andrea Arcangeli <aarcange@redhat.com>

> 
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index f9c07f54dd62..e919e4613eab 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
>  		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
>  			if (next - addr != HPAGE_PMD_SIZE) {
>  				__split_huge_pmd(vma, pmd, addr, false, NULL);
> -				if (pmd_trans_unstable(pmd))
> -					continue;
>  			} else {
>  				int nr_ptes = change_huge_pmd(vma, pmd, addr,
>  						newprot, prot_numa);

Yes this check was an harmless noop, but it's definitely good to clean
up this bit too after the other more important change that has a
positive runtime effect, or it could be a source of confusion to the
reader if left in there.

Thanks!
Andrea

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] mprotect: drop overprotective lock_pte_protection()
@ 2017-02-08 13:45       ` Andrea Arcangeli
  0 siblings, 0 replies; 10+ messages in thread
From: Andrea Arcangeli @ 2017-02-08 13:45 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Andrew Morton, Kirill A. Shutemov, Mel Gorman, linux-mm, linux-kernel

On Wed, Feb 08, 2017 at 03:04:21PM +0300, Kirill A. Shutemov wrote:
> On Tue, Feb 07, 2017 at 01:44:54PM -0800, Andrew Morton wrote:
> > On Tue,  7 Feb 2017 17:33:47 +0300 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> wrote:
> > 
> > > lock_pte_protection() uses pmd_lock() to make sure that we have stable
> > > PTE page table before walking pte range.
> > > 
> > > That's not necessary. We only need to make sure that PTE page table is
> > > established. It cannot vanish under us as long as we hold mmap_sem at
> > > least for read.
> > > 
> > > And we already have helper for that -- pmd_trans_unstable().
> > 
> > http://ozlabs.org/~akpm/mmots/broken-out/mm-mprotect-use-pmd_trans_unstable-instead-of-taking-the-pmd_lock.patch
> > already did this?
> 
> Right. Except, it doesn't drop unneeded pmd_trans_unstable(pmd) check after
> __split_huge_pmd().
> 
> Could you fold this part of my patch into Andrea's?

Reviewed-by: Andrea Arcangeli <aarcange@redhat.com>

> 
> diff --git a/mm/mprotect.c b/mm/mprotect.c
> index f9c07f54dd62..e919e4613eab 100644
> --- a/mm/mprotect.c
> +++ b/mm/mprotect.c
> @@ -177,8 +149,6 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma,
>  		if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) {
>  			if (next - addr != HPAGE_PMD_SIZE) {
>  				__split_huge_pmd(vma, pmd, addr, false, NULL);
> -				if (pmd_trans_unstable(pmd))
> -					continue;
>  			} else {
>  				int nr_ptes = change_huge_pmd(vma, pmd, addr,
>  						newprot, prot_numa);

Yes this check was an harmless noop, but it's definitely good to clean
up this bit too after the other more important change that has a
positive runtime effect, or it could be a source of confusion to the
reader if left in there.

Thanks!
Andrea

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-02-08 14:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-07 14:33 [PATCH] mprotect: drop overprotective lock_pte_protection() Kirill A. Shutemov
2017-02-07 14:33 ` Kirill A. Shutemov
2017-02-07 21:29 ` Andrea Arcangeli
2017-02-07 21:29   ` Andrea Arcangeli
2017-02-07 21:44 ` Andrew Morton
2017-02-07 21:44   ` Andrew Morton
2017-02-08 12:04   ` Kirill A. Shutemov
2017-02-08 12:04     ` Kirill A. Shutemov
2017-02-08 13:45     ` Andrea Arcangeli
2017-02-08 13:45       ` Andrea Arcangeli

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.