linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -mm v2] mm: add page_check_address_transhuge helper
@ 2015-11-20  9:31 Vladimir Davydov
  2015-11-24  4:29 ` Sergey Senozhatsky
  0 siblings, 1 reply; 9+ messages in thread
From: Vladimir Davydov @ 2015-11-20  9:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Kirill A. Shutemov, linux-mm, linux-kernel

page_referenced_one() and page_idle_clear_pte_refs_one() duplicate the
code for looking up pte of a (possibly transhuge) page. Move this code
to a new helper function, page_check_address_transhuge(), and make the
above mentioned functions use it.

This is just a cleanup, no functional changes are intended.

Signed-off-by: Vladimir Davydov <vdavydov@virtuozzo.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
Changes in v2:
 - rebase on top of v4.4-rc1-mmotm-2015-11-18-15-38
 - fix comment to page_check_address_transhuge as suggested by Kirill

 include/linux/rmap.h |   8 ++++
 mm/page_idle.c       |  63 ++++-------------------------
 mm/rmap.c            | 110 ++++++++++++++++++++++++++++++---------------------
 3 files changed, 81 insertions(+), 100 deletions(-)

diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index ebf3750e42b2..b9eedc63e9e6 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -216,6 +216,14 @@ static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
 }
 
 /*
+ * Used by idle page tracking to check if a page was referenced via page
+ * tables.
+ */
+bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
+				  unsigned long address, pmd_t **pmdp,
+				  pte_t **ptep, spinlock_t **ptlp);
+
+/*
  * Used by swapoff to help locate where page is expected in vma.
  */
 unsigned long page_address_in_vma(struct page *, struct vm_area_struct *);
diff --git a/mm/page_idle.c b/mm/page_idle.c
index 2c553ba969f8..374931f32ebc 100644
--- a/mm/page_idle.c
+++ b/mm/page_idle.c
@@ -55,71 +55,22 @@ static int page_idle_clear_pte_refs_one(struct page *page,
 					unsigned long addr, void *arg)
 {
 	struct mm_struct *mm = vma->vm_mm;
-	spinlock_t *ptl;
-	pgd_t *pgd;
-	pud_t *pud;
 	pmd_t *pmd;
 	pte_t *pte;
+	spinlock_t *ptl;
 	bool referenced = false;
 
-	pgd = pgd_offset(mm, addr);
-	if (!pgd_present(*pgd))
-		return SWAP_AGAIN;
-	pud = pud_offset(pgd, addr);
-	if (!pud_present(*pud))
-		return SWAP_AGAIN;
-	pmd = pmd_offset(pud, addr);
-
-	if (pmd_trans_huge(*pmd)) {
-		ptl = pmd_lock(mm, pmd);
-		if (!pmd_present(*pmd))
-			goto unlock_pmd;
-		if (unlikely(!pmd_trans_huge(*pmd))) {
-			spin_unlock(ptl);
-			goto map_pte;
-		}
-
-		if (pmd_page(*pmd) != page)
-			goto unlock_pmd;
-
-		referenced = pmdp_clear_young_notify(vma, addr, pmd);
-		spin_unlock(ptl);
-		goto found;
-unlock_pmd:
-		spin_unlock(ptl);
+	if (!page_check_address_transhuge(page, mm, addr, &pmd, &pte, &ptl))
 		return SWAP_AGAIN;
-	} else {
-		pmd_t pmde = *pmd;
-
-		barrier();
-		if (!pmd_present(pmde) || pmd_trans_huge(pmde))
-			return SWAP_AGAIN;
 
-	}
-map_pte:
-	pte = pte_offset_map(pmd, addr);
-	if (!pte_present(*pte)) {
+	if (pte) {
+		referenced = ptep_clear_young_notify(vma, addr, pte);
 		pte_unmap(pte);
-		return SWAP_AGAIN;
-	}
-
-	ptl = pte_lockptr(mm, pmd);
-	spin_lock(ptl);
-
-	if (!pte_present(*pte)) {
-		pte_unmap_unlock(pte, ptl);
-		return SWAP_AGAIN;
-	}
+	} else
+		referenced = pmdp_clear_young_notify(vma, addr, pmd);
 
-	/* THP can be referenced by any subpage */
-	if (pte_pfn(*pte) - page_to_pfn(page) >= hpage_nr_pages(page)) {
-		pte_unmap_unlock(pte, ptl);
-		return SWAP_AGAIN;
-	}
+	spin_unlock(ptl);
 
-	referenced = ptep_clear_young_notify(vma, addr, pte);
-	pte_unmap_unlock(pte, ptl);
-found:
 	if (referenced) {
 		clear_page_idle(page);
 		/*
diff --git a/mm/rmap.c b/mm/rmap.c
index 936c46584179..27916086ac50 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -798,48 +798,43 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
 	return 1;
 }
 
-struct page_referenced_arg {
-	int mapcount;
-	int referenced;
-	unsigned long vm_flags;
-	struct mem_cgroup *memcg;
-};
 /*
- * arg: page_referenced_arg will be passed
+ * Check that @page is mapped at @address into @mm. In contrast to
+ * page_check_address(), this function can handle transparent huge pages.
+ *
+ * On success returns true with pte mapped and locked. For PMD-mapped
+ * transparent huge pages *@ptep is set to NULL.
  */
-static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
-			unsigned long address, void *arg)
+bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
+				  unsigned long address, pmd_t **pmdp,
+				  pte_t **ptep, spinlock_t **ptlp)
 {
-	struct mm_struct *mm = vma->vm_mm;
-	spinlock_t *ptl;
-	int referenced = 0;
-	struct page_referenced_arg *pra = arg;
 	pgd_t *pgd;
 	pud_t *pud;
 	pmd_t *pmd;
 	pte_t *pte;
+	spinlock_t *ptl;
 
 	if (unlikely(PageHuge(page))) {
 		/* when pud is not present, pte will be NULL */
 		pte = huge_pte_offset(mm, address);
 		if (!pte)
-			return SWAP_AGAIN;
+			return false;
 
 		ptl = huge_pte_lockptr(page_hstate(page), mm, pte);
+		pmd = NULL;
 		goto check_pte;
 	}
 
 	pgd = pgd_offset(mm, address);
 	if (!pgd_present(*pgd))
-		return SWAP_AGAIN;
+		return false;
 	pud = pud_offset(pgd, address);
 	if (!pud_present(*pud))
-		return SWAP_AGAIN;
+		return false;
 	pmd = pmd_offset(pud, address);
 
 	if (pmd_trans_huge(*pmd)) {
-		int ret = SWAP_AGAIN;
-
 		ptl = pmd_lock(mm, pmd);
 		if (!pmd_present(*pmd))
 			goto unlock_pmd;
@@ -851,31 +846,23 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
 		if (pmd_page(*pmd) != page)
 			goto unlock_pmd;
 
-		if (vma->vm_flags & VM_LOCKED) {
-			pra->vm_flags |= VM_LOCKED;
-			ret = SWAP_FAIL; /* To break the loop */
-			goto unlock_pmd;
-		}
-
-		if (pmdp_clear_flush_young_notify(vma, address, pmd))
-			referenced++;
-		spin_unlock(ptl);
+		pte = NULL;
 		goto found;
 unlock_pmd:
 		spin_unlock(ptl);
-		return ret;
+		return false;
 	} else {
 		pmd_t pmde = *pmd;
 
 		barrier();
 		if (!pmd_present(pmde) || pmd_trans_huge(pmde))
-			return SWAP_AGAIN;
+			return false;
 	}
 map_pte:
 	pte = pte_offset_map(pmd, address);
 	if (!pte_present(*pte)) {
 		pte_unmap(pte);
-		return SWAP_AGAIN;
+		return false;
 	}
 
 	ptl = pte_lockptr(mm, pmd);
@@ -884,35 +871,70 @@ check_pte:
 
 	if (!pte_present(*pte)) {
 		pte_unmap_unlock(pte, ptl);
-		return SWAP_AGAIN;
+		return false;
 	}
 
 	/* THP can be referenced by any subpage */
 	if (pte_pfn(*pte) - page_to_pfn(page) >= hpage_nr_pages(page)) {
 		pte_unmap_unlock(pte, ptl);
-		return SWAP_AGAIN;
+		return false;
 	}
+found:
+	*ptep = pte;
+	*pmdp = pmd;
+	*ptlp = ptl;
+	return true;
+}
+
+struct page_referenced_arg {
+	int mapcount;
+	int referenced;
+	unsigned long vm_flags;
+	struct mem_cgroup *memcg;
+};
+/*
+ * arg: page_referenced_arg will be passed
+ */
+static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
+			unsigned long address, void *arg)
+{
+	struct mm_struct *mm = vma->vm_mm;
+	struct page_referenced_arg *pra = arg;
+	pmd_t *pmd;
+	pte_t *pte;
+	spinlock_t *ptl;
+	int referenced = 0;
+
+	if (!page_check_address_transhuge(page, mm, address, &pmd, &pte, &ptl))
+		return SWAP_AGAIN;
 
 	if (vma->vm_flags & VM_LOCKED) {
-		pte_unmap_unlock(pte, ptl);
+		if (pte)
+			pte_unmap(pte);
+		spin_unlock(ptl);
 		pra->vm_flags |= VM_LOCKED;
 		return SWAP_FAIL; /* To break the loop */
 	}
 
-	if (ptep_clear_flush_young_notify(vma, address, pte)) {
-		/*
-		 * Don't treat a reference through a sequentially read
-		 * mapping as such.  If the page has been used in
-		 * another mapping, we will catch it; if this other
-		 * mapping is already gone, the unmap path will have
-		 * set PG_referenced or activated the page.
-		 */
-		if (likely(!(vma->vm_flags & VM_SEQ_READ)))
+	if (pte) {
+		if (ptep_clear_flush_young_notify(vma, address, pte)) {
+			/*
+			 * Don't treat a reference through a sequentially read
+			 * mapping as such.  If the page has been used in
+			 * another mapping, we will catch it; if this other
+			 * mapping is already gone, the unmap path will have
+			 * set PG_referenced or activated the page.
+			 */
+			if (likely(!(vma->vm_flags & VM_SEQ_READ)))
+				referenced++;
+		}
+		pte_unmap(pte);
+	} else {
+		if (pmdp_clear_flush_young_notify(vma, address, pmd))
 			referenced++;
 	}
-	pte_unmap_unlock(pte, ptl);
+	spin_unlock(ptl);
 
-found:
 	if (referenced)
 		clear_page_idle(page);
 	if (test_and_clear_page_young(page))
-- 
2.1.4

--
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 related	[flat|nested] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-20  9:31 [PATCH -mm v2] mm: add page_check_address_transhuge helper Vladimir Davydov
@ 2015-11-24  4:29 ` Sergey Senozhatsky
  2015-11-24  9:09   ` Kirill A. Shutemov
  0 siblings, 1 reply; 9+ messages in thread
From: Sergey Senozhatsky @ 2015-11-24  4:29 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: Andrew Morton, Kirill A. Shutemov, linux-mm, linux-kernel,
	sergey.senozhatsky.work

Hello,

On (11/20/15 12:31), Vladimir Davydov wrote:
[..]
> -	if (ptep_clear_flush_young_notify(vma, address, pte)) {
> -		/*
> -		 * Don't treat a reference through a sequentially read
> -		 * mapping as such.  If the page has been used in
> -		 * another mapping, we will catch it; if this other
> -		 * mapping is already gone, the unmap path will have
> -		 * set PG_referenced or activated the page.
> -		 */
> -		if (likely(!(vma->vm_flags & VM_SEQ_READ)))
> +	if (pte) {
> +		if (ptep_clear_flush_young_notify(vma, address, pte)) {
> +			/*
> +			 * Don't treat a reference through a sequentially read
> +			 * mapping as such.  If the page has been used in
> +			 * another mapping, we will catch it; if this other
> +			 * mapping is already gone, the unmap path will have
> +			 * set PG_referenced or activated the page.
> +			 */
> +			if (likely(!(vma->vm_flags & VM_SEQ_READ)))
> +				referenced++;
> +		}
> +		pte_unmap(pte);
> +	} else {
> +		if (pmdp_clear_flush_young_notify(vma, address, pmd))
>  			referenced++;
>  	}

# CONFIG_TRANSPARENT_HUGEPAGE is not set

x86_64, 4.4.0-rc2-mm1


mm/built-in.o: In function `page_referenced_one':
rmap.c:(.text+0x32070): undefined reference to `pmdp_clear_flush_young'


	-ss

--
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] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  4:29 ` Sergey Senozhatsky
@ 2015-11-24  9:09   ` Kirill A. Shutemov
  2015-11-24  9:23     ` Sergey Senozhatsky
  2015-11-24  9:36     ` Vladimir Davydov
  0 siblings, 2 replies; 9+ messages in thread
From: Kirill A. Shutemov @ 2015-11-24  9:09 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Vladimir Davydov, Andrew Morton, linux-mm, linux-kernel

On Tue, Nov 24, 2015 at 01:29:41PM +0900, Sergey Senozhatsky wrote:
> Hello,
> 
> On (11/20/15 12:31), Vladimir Davydov wrote:
> [..]
> > -	if (ptep_clear_flush_young_notify(vma, address, pte)) {
> > -		/*
> > -		 * Don't treat a reference through a sequentially read
> > -		 * mapping as such.  If the page has been used in
> > -		 * another mapping, we will catch it; if this other
> > -		 * mapping is already gone, the unmap path will have
> > -		 * set PG_referenced or activated the page.
> > -		 */
> > -		if (likely(!(vma->vm_flags & VM_SEQ_READ)))
> > +	if (pte) {
> > +		if (ptep_clear_flush_young_notify(vma, address, pte)) {
> > +			/*
> > +			 * Don't treat a reference through a sequentially read
> > +			 * mapping as such.  If the page has been used in
> > +			 * another mapping, we will catch it; if this other
> > +			 * mapping is already gone, the unmap path will have
> > +			 * set PG_referenced or activated the page.
> > +			 */
> > +			if (likely(!(vma->vm_flags & VM_SEQ_READ)))
> > +				referenced++;
> > +		}
> > +		pte_unmap(pte);
> > +	} else {
> > +		if (pmdp_clear_flush_young_notify(vma, address, pmd))
> >  			referenced++;
> >  	}
> 
> # CONFIG_TRANSPARENT_HUGEPAGE is not set
> 
> x86_64, 4.4.0-rc2-mm1
> 
> 
> mm/built-in.o: In function `page_referenced_one':
> rmap.c:(.text+0x32070): undefined reference to `pmdp_clear_flush_young'

Something like this?

diff --git a/mm/page_idle.c b/mm/page_idle.c
index 374931f32ebc..4ea9c4ef5146 100644
--- a/mm/page_idle.c
+++ b/mm/page_idle.c
@@ -66,8 +66,12 @@ static int page_idle_clear_pte_refs_one(struct page *page,
 	if (pte) {
 		referenced = ptep_clear_young_notify(vma, addr, pte);
 		pte_unmap(pte);
-	} else
+	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
 		referenced = pmdp_clear_young_notify(vma, addr, pmd);
+	} else {
+		/* unexpected pmd-mapped page? */
+		WARN_ON_ONCE(1);
+	}
 
 	spin_unlock(ptl);
 
diff --git a/mm/rmap.c b/mm/rmap.c
index 27916086ac50..499b24511b1f 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -929,9 +929,12 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
 				referenced++;
 		}
 		pte_unmap(pte);
-	} else {
+	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
 		if (pmdp_clear_flush_young_notify(vma, address, pmd))
 			referenced++;
+	} else {
+		/* unexpected pmd-mapped page? */
+		WARN_ON_ONCE(1);
 	}
 	spin_unlock(ptl);
 
-- 
 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 related	[flat|nested] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:09   ` Kirill A. Shutemov
@ 2015-11-24  9:23     ` Sergey Senozhatsky
  2015-11-24  9:36     ` Vladimir Davydov
  1 sibling, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2015-11-24  9:23 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Sergey Senozhatsky, Vladimir Davydov, Andrew Morton, linux-mm,
	linux-kernel

On (11/24/15 11:09), Kirill A. Shutemov wrote:
[..]
> diff --git a/mm/page_idle.c b/mm/page_idle.c
> index 374931f32ebc..4ea9c4ef5146 100644
> --- a/mm/page_idle.c
> +++ b/mm/page_idle.c
> @@ -66,8 +66,12 @@ static int page_idle_clear_pte_refs_one(struct page *page,
>  	if (pte) {
>  		referenced = ptep_clear_young_notify(vma, addr, pte);
>  		pte_unmap(pte);
> -	} else
> +	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
>  		referenced = pmdp_clear_young_notify(vma, addr, pmd);
> +	} else {
> +		/* unexpected pmd-mapped page? */
> +		WARN_ON_ONCE(1);
> +	}
>  
>  	spin_unlock(ptl);
>  
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 27916086ac50..499b24511b1f 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -929,9 +929,12 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
>  				referenced++;
>  		}
>  		pte_unmap(pte);
> -	} else {
> +	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
>  		if (pmdp_clear_flush_young_notify(vma, address, pmd))
>  			referenced++;
> +	} else {
> +		/* unexpected pmd-mapped page? */
> +		WARN_ON_ONCE(1);
>  	}
>  	spin_unlock(ptl);

yes, works for me.

	-ss

--
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] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:09   ` Kirill A. Shutemov
  2015-11-24  9:23     ` Sergey Senozhatsky
@ 2015-11-24  9:36     ` Vladimir Davydov
  2015-11-24  9:46       ` Vladimir Davydov
                         ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: Vladimir Davydov @ 2015-11-24  9:36 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: Sergey Senozhatsky, Andrew Morton, linux-mm, linux-kernel

On Tue, Nov 24, 2015 at 11:09:30AM +0200, Kirill A. Shutemov wrote:
> On Tue, Nov 24, 2015 at 01:29:41PM +0900, Sergey Senozhatsky wrote:
...
> > mm/built-in.o: In function `page_referenced_one':
> > rmap.c:(.text+0x32070): undefined reference to `pmdp_clear_flush_young'
> 
> Something like this?
...
> @@ -929,9 +929,12 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
>  				referenced++;
>  		}
>  		pte_unmap(pte);
> -	} else {
> +	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
>  		if (pmdp_clear_flush_young_notify(vma, address, pmd))
>  			referenced++;
> +	} else {
> +		/* unexpected pmd-mapped page? */
> +		WARN_ON_ONCE(1);
>  	}
>  	spin_unlock(ptl);

I think we'd better compile out page_check_address_transhuge altogether if
CONFIG_TRANSPARENT_HUGEPAGE is disabled and use page_check_address instead.
This would also reduce the kernel size a bit.
---
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index b9eedc63e9e6..77d1ba57d495 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -219,9 +219,20 @@ static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
  * Used by idle page tracking to check if a page was referenced via page
  * tables.
  */
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
 				  unsigned long address, pmd_t **pmdp,
 				  pte_t **ptep, spinlock_t **ptlp);
+#else
+static inline bool page_check_address_transhuge(struct page *page,
+				struct mm_struct *mm, unsigned long address,
+				pmd_t **pmdp, pte_t **ptep, spinlock_t **ptlp)
+{
+	*ptep = page_check_address(page, mm, address, ptlp, 0);
+	*pmdp = NULL;
+	return !!*ptep;
+}
+#endif
 
 /*
  * Used by swapoff to help locate where page is expected in vma.
diff --git a/mm/rmap.c b/mm/rmap.c
index 27916086ac50..6f371261dd12 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -798,6 +798,7 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
 	return 1;
 }
 
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 /*
  * Check that @page is mapped at @address into @mm. In contrast to
  * page_check_address(), this function can handle transparent huge pages.
@@ -885,6 +886,7 @@ found:
 	*ptlp = ptl;
 	return true;
 }
+#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
 
 struct page_referenced_arg {
 	int mapcount;

--
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 related	[flat|nested] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:36     ` Vladimir Davydov
@ 2015-11-24  9:46       ` Vladimir Davydov
  2015-11-24 10:09         ` Sergey Senozhatsky
  2015-11-24  9:57       ` Kirill A. Shutemov
  2015-11-24 18:15       ` Johannes Weiner
  2 siblings, 1 reply; 9+ messages in thread
From: Vladimir Davydov @ 2015-11-24  9:46 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Kirill A. Shutemov, Andrew Morton, linux-mm, linux-kernel

On Tue, Nov 24, 2015 at 12:36:17PM +0300, Vladimir Davydov wrote:
...
> I think we'd better compile out page_check_address_transhuge altogether if
> CONFIG_TRANSPARENT_HUGEPAGE is disabled and use page_check_address instead.
> This would also reduce the kernel size a bit.

Sergey, could you please check if the patch below fixes build for you?

Thanks,
Vladimir

> ---
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index b9eedc63e9e6..77d1ba57d495 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -219,9 +219,20 @@ static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
>   * Used by idle page tracking to check if a page was referenced via page
>   * tables.
>   */
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
>  				  unsigned long address, pmd_t **pmdp,
>  				  pte_t **ptep, spinlock_t **ptlp);
> +#else
> +static inline bool page_check_address_transhuge(struct page *page,
> +				struct mm_struct *mm, unsigned long address,
> +				pmd_t **pmdp, pte_t **ptep, spinlock_t **ptlp)
> +{
> +	*ptep = page_check_address(page, mm, address, ptlp, 0);
> +	*pmdp = NULL;
> +	return !!*ptep;
> +}
> +#endif
>  
>  /*
>   * Used by swapoff to help locate where page is expected in vma.
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 27916086ac50..6f371261dd12 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -798,6 +798,7 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
>  	return 1;
>  }
>  
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  /*
>   * Check that @page is mapped at @address into @mm. In contrast to
>   * page_check_address(), this function can handle transparent huge pages.
> @@ -885,6 +886,7 @@ found:
>  	*ptlp = ptl;
>  	return true;
>  }
> +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>  
>  struct page_referenced_arg {
>  	int mapcount;
> 

--
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] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:36     ` Vladimir Davydov
  2015-11-24  9:46       ` Vladimir Davydov
@ 2015-11-24  9:57       ` Kirill A. Shutemov
  2015-11-24 18:15       ` Johannes Weiner
  2 siblings, 0 replies; 9+ messages in thread
From: Kirill A. Shutemov @ 2015-11-24  9:57 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: Sergey Senozhatsky, Andrew Morton, linux-mm, linux-kernel

On Tue, Nov 24, 2015 at 12:36:17PM +0300, Vladimir Davydov wrote:
> On Tue, Nov 24, 2015 at 11:09:30AM +0200, Kirill A. Shutemov wrote:
> > On Tue, Nov 24, 2015 at 01:29:41PM +0900, Sergey Senozhatsky wrote:
> ...
> > > mm/built-in.o: In function `page_referenced_one':
> > > rmap.c:(.text+0x32070): undefined reference to `pmdp_clear_flush_young'
> > 
> > Something like this?
> ...
> > @@ -929,9 +929,12 @@ static int page_referenced_one(struct page *page, struct vm_area_struct *vma,
> >  				referenced++;
> >  		}
> >  		pte_unmap(pte);
> > -	} else {
> > +	} else if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
> >  		if (pmdp_clear_flush_young_notify(vma, address, pmd))
> >  			referenced++;
> > +	} else {
> > +		/* unexpected pmd-mapped page? */
> > +		WARN_ON_ONCE(1);
> >  	}
> >  	spin_unlock(ptl);
> 
> I think we'd better compile out page_check_address_transhuge altogether if
> CONFIG_TRANSPARENT_HUGEPAGE is disabled and use page_check_address instead.
> This would also reduce the kernel size a bit.

Looks good to me, if compiler is clever enough to remove
pmdp_clear_flush_young_notify() call for !THP. I'm not sure it is.

> ---
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index b9eedc63e9e6..77d1ba57d495 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -219,9 +219,20 @@ static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
>   * Used by idle page tracking to check if a page was referenced via page
>   * tables.
>   */
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
>  				  unsigned long address, pmd_t **pmdp,
>  				  pte_t **ptep, spinlock_t **ptlp);
> +#else
> +static inline bool page_check_address_transhuge(struct page *page,
> +				struct mm_struct *mm, unsigned long address,
> +				pmd_t **pmdp, pte_t **ptep, spinlock_t **ptlp)
> +{
> +	*ptep = page_check_address(page, mm, address, ptlp, 0);
> +	*pmdp = NULL;
> +	return !!*ptep;
> +}
> +#endif
>  
>  /*
>   * Used by swapoff to help locate where page is expected in vma.
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 27916086ac50..6f371261dd12 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -798,6 +798,7 @@ int page_mapped_in_vma(struct page *page, struct vm_area_struct *vma)
>  	return 1;
>  }
>  
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  /*
>   * Check that @page is mapped at @address into @mm. In contrast to
>   * page_check_address(), this function can handle transparent huge pages.
> @@ -885,6 +886,7 @@ found:
>  	*ptlp = ptl;
>  	return true;
>  }
> +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
>  
>  struct page_referenced_arg {
>  	int mapcount;

-- 
 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] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:46       ` Vladimir Davydov
@ 2015-11-24 10:09         ` Sergey Senozhatsky
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2015-11-24 10:09 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: Sergey Senozhatsky, Kirill A. Shutemov, Andrew Morton, linux-mm,
	linux-kernel

Hello,

On (11/24/15 12:46), Vladimir Davydov wrote:
> 
> Sergey, could you please check if the patch below fixes build for you?

yes, it does.

add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-649 (-649)
function                                     old     new   delta
__warned                                    2632    2631      -1
page_referenced_one                          218     159     -59
page_check_address_transhuge                 589       -    -589

	-ss

--
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] 9+ messages in thread

* Re: [PATCH -mm v2] mm: add page_check_address_transhuge helper
  2015-11-24  9:36     ` Vladimir Davydov
  2015-11-24  9:46       ` Vladimir Davydov
  2015-11-24  9:57       ` Kirill A. Shutemov
@ 2015-11-24 18:15       ` Johannes Weiner
  2 siblings, 0 replies; 9+ messages in thread
From: Johannes Weiner @ 2015-11-24 18:15 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: Kirill A. Shutemov, Sergey Senozhatsky, Andrew Morton, linux-mm,
	linux-kernel

On Tue, Nov 24, 2015 at 12:36:17PM +0300, Vladimir Davydov wrote:
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index b9eedc63e9e6..77d1ba57d495 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -219,9 +219,20 @@ static inline pte_t *page_check_address(struct page *page, struct mm_struct *mm,
>   * Used by idle page tracking to check if a page was referenced via page
>   * tables.
>   */
> +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  bool page_check_address_transhuge(struct page *page, struct mm_struct *mm,
>  				  unsigned long address, pmd_t **pmdp,
>  				  pte_t **ptep, spinlock_t **ptlp);
> +#else
> +static inline bool page_check_address_transhuge(struct page *page,
> +				struct mm_struct *mm, unsigned long address,
> +				pmd_t **pmdp, pte_t **ptep, spinlock_t **ptlp)
> +{
> +	*ptep = page_check_address(page, mm, address, ptlp, 0);
> +	*pmdp = NULL;
> +	return !!*ptep;
> +}
> +#endif

Tested-by: Johannes Weiner <hannes@cmpxchg.org>

--
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] 9+ messages in thread

end of thread, other threads:[~2015-11-24 18:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-20  9:31 [PATCH -mm v2] mm: add page_check_address_transhuge helper Vladimir Davydov
2015-11-24  4:29 ` Sergey Senozhatsky
2015-11-24  9:09   ` Kirill A. Shutemov
2015-11-24  9:23     ` Sergey Senozhatsky
2015-11-24  9:36     ` Vladimir Davydov
2015-11-24  9:46       ` Vladimir Davydov
2015-11-24 10:09         ` Sergey Senozhatsky
2015-11-24  9:57       ` Kirill A. Shutemov
2015-11-24 18:15       ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).