Skip to contentSkip to conversation

mm/migrate: clean up useless code in migrate_vma_collect_pmd()

PATCH Superseded Pingfan Liu 4 participants 15 messages Aug 6, 2019 – Aug 26, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 mm/migrate: clean up useless code in migrate_vma_collect_pmd()

Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
mm/migrate.c +1 -4
index 8992741..c2ec614 100644
@@ -2230,7 +2230,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 		if (pte_none(pte)) {
 			mpfn = MIGRATE_PFN_MIGRATE;
 			migrate->cpages++;
-			pfn = 0;
 			goto next;
 		}
 
@@ -2255,7 +2254,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 			if (is_zero_pfn(pfn)) {
 				mpfn = MIGRATE_PFN_MIGRATE;
 				migrate->cpages++;
-				pfn = 0;
 				goto next;
 			}
 			page = vm_normal_page(migrate->vma, addr, pte);
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
 		/* FIXME support THP */
 		if (!page || !page->mapping || PageTransCompound(page)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 			goto next;
 		}
-		pfn = page_to_pfn(page);
 
 		/*
 		 * By getting a reference on the page we pin it and that blocks
Signature · 1 line
2.7.5
#1 lore raw

PATCH 2/3 mm/migrate: see hole as invalid source page

MIGRATE_PFN_MIGRATE marks a valid pfn, further more, suitable to migrate. As for hole, there is no valid pfn, not to mention migration.

Before this patch, hole has already relied on the following code to be filtered out. Hence it is more reasonable to see hole as invalid source page.
migrate_vma_prepare()

{
		struct page *page = migrate_pfn_to_page(migrate->src[i]);

		if (!page || (migrate->src[i] & MIGRATE_PFN_MIGRATE))
		     \_ this condition
}
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/migrate.c +2 -4
index c2ec614..832483f 100644
@@ -2136,10 +2136,9 @@ static int migrate_vma_collect_hole(unsigned long start,
 	unsigned long addr;
 
 	for (addr = start & PAGE_MASK; addr < end; addr += PAGE_SIZE) {
-		migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE;
+		migrate->src[migrate->npages] = 0;
 		migrate->dst[migrate->npages] = 0;
 		migrate->npages++;
-		migrate->cpages++;
 	}
 
 	return 0;
@@ -2228,8 +2227,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 		pfn = pte_pfn(pte);
 
 		if (pte_none(pte)) {
-			mpfn = MIGRATE_PFN_MIGRATE;
-			migrate->cpages++;
+			mpfn = 0;
 			goto next;
 		}
 
Signature · 1 line
2.7.5
#2 lore raw

Re: [PATCH 2/3] mm/migrate: see hole as invalid source page

Quoted 7 lines · Pingfan Liu

MIGRATE_PFN_MIGRATE marks a valid pfn, further more, suitable to migrate. As for hole, there is no valid pfn, not to mention migration.

Before this patch, hole has already relied on the following code to be filtered out. Hence it is more reasonable to see hole as invalid source page.
migrate_vma_prepare()

Quoted 6 lines
{
		struct page *page = migrate_pfn_to_page(migrate->src[i]);

		if (!page || (migrate->src[i] & MIGRATE_PFN_MIGRATE))
		     \_ this condition
}

NAK you break the API, MIGRATE_PFN_MIGRATE is use for 2 things, first it allow the collection code to mark entry that can be migrated, then it use by driver to allow driver to skip migration for some entry (for whatever reason the driver might have), we still need to keep the entry and not clear it so that we can cleanup thing (ie remove migration pte entry).

Quoted 46 lines
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/migrate.c +2 -4
index c2ec614..832483f 100644
@@ -2136,10 +2136,9 @@ static int migrate_vma_collect_hole(unsigned long start,
 	unsigned long addr;
 
 	for (addr = start & PAGE_MASK; addr < end; addr += PAGE_SIZE) {
-		migrate->src[migrate->npages] = MIGRATE_PFN_MIGRATE;
+		migrate->src[migrate->npages] = 0;
 		migrate->dst[migrate->npages] = 0;
 		migrate->npages++;
-		migrate->cpages++;
 	}
 
 	return 0;
@@ -2228,8 +2227,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 		pfn = pte_pfn(pte);
 
 		if (pte_none(pte)) {
-			mpfn = MIGRATE_PFN_MIGRATE;
-			migrate->cpages++;
+			mpfn = 0;
 			goto next;
 		}
 
Signature · 1 line
2.7.5
#3 lore raw

Re: [PATCH 2/3] mm/migrate: see hole as invalid source page

Quoted 15 lines · Jerome Glisse
Quoted 7 lines · Pingfan Liu

MIGRATE_PFN_MIGRATE marks a valid pfn, further more, suitable to migrate. As for hole, there is no valid pfn, not to mention migration.

Before this patch, hole has already relied on the following code to be filtered out. Hence it is more reasonable to see hole as invalid source page.
migrate_vma_prepare()

Quoted 6 lines
{
		struct page *page = migrate_pfn_to_page(migrate->src[i]);

		if (!page || (migrate->src[i] & MIGRATE_PFN_MIGRATE))
		     \_ this condition
}
Quoted 6 lines

NAK you break the API, MIGRATE_PFN_MIGRATE is use for 2 things, first it allow the collection code to mark entry that can be migrated, then it use by driver to allow driver to skip migration for some entry (for whatever reason the driver might have), we still need to keep the entry and not clear it so that we can cleanup thing (ie remove migration pte entry).

Thanks for your kindly review.

I read the code again. Maybe I miss something. But as my understanding, for hole, there is no pte.
As the current code migrate_vma_collect_pmd()

{
	if (pmd_none(*pmdp))
		return migrate_vma_collect_hole(start, end, walk);

...
make_migration_entry()
}

We do not install migration entry for hole, then no need to remove migration pte entry.

And on the driver side, there is way to migrate a hole. The driver just
skip it by
drivers/gpu/drm/nouveau/nouveau_dmem.c: if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE))

                                             ^^^^
Finally, in migrate_vma_finalize(), for a hole,
		if (!page) {
			if (newpage) {
				unlock_page(newpage);
				put_page(newpage);
			}
			continue;
		}

And we do not rely on remove_migration_ptes(page, newpage, false); to restore the orignal pte (and it is impossible).

Thanks,
Pingfan

#4 lore raw

Re: [PATCH 2/3] mm/migrate: see hole as invalid source page

Quoted 49 lines · Pingfan Liu
Quoted 15 lines · Jerome Glisse
Quoted 7 lines · Pingfan Liu

MIGRATE_PFN_MIGRATE marks a valid pfn, further more, suitable to migrate. As for hole, there is no valid pfn, not to mention migration.

Before this patch, hole has already relied on the following code to be filtered out. Hence it is more reasonable to see hole as invalid source page.
migrate_vma_prepare()

Quoted 6 lines
{
		struct page *page = migrate_pfn_to_page(migrate->src[i]);

		if (!page || (migrate->src[i] & MIGRATE_PFN_MIGRATE))
		     \_ this condition
}
Quoted 6 lines

NAK you break the API, MIGRATE_PFN_MIGRATE is use for 2 things, first it allow the collection code to mark entry that can be migrated, then it use by driver to allow driver to skip migration for some entry (for whatever reason the driver might have), we still need to keep the entry and not clear it so that we can cleanup thing (ie remove migration pte entry).

Thanks for your kindly review.

I read the code again. Maybe I miss something. But as my understanding, for hole, there is no pte.
As the current code migrate_vma_collect_pmd()

{
	if (pmd_none(*pmdp))
		return migrate_vma_collect_hole(start, end, walk);

...
make_migration_entry()
}

We do not install migration entry for hole, then no need to remove migration pte entry.

And on the driver side, there is way to migrate a hole. The driver just
skip it by
drivers/gpu/drm/nouveau/nouveau_dmem.c: if (!spage || !(src_pfns[i] & MIGRATE_PFN_MIGRATE))

                                             ^^^^
Finally, in migrate_vma_finalize(), for a hole,
		if (!page) {
			if (newpage) {
				unlock_page(newpage);
				put_page(newpage);
			}
			continue;
		}
Quoted 3 lines

And we do not rely on remove_migration_ptes(page, newpage, false); to restore the orignal pte (and it is impossible).

Hello, do you have any comment?

I think most of important, hole does not use the 'MIGRATE_PFN_MIGRATE' API. Hole has not pte, and there is no way to 'remove migration pte entry'. Further more, we can know the failure on the source side, no need to defer it to driver side.

By this way, [3/3] can unify the code.

Thanks,
Pingfan

#5 lore raw

PATCH 3/3 mm/migrate: remove the duplicated code migrate_vma_collect_hole()

In reply to Pingfan Liu

After the previous patch which sees hole as invalid source, migrate_vma_collect_hole() has the same code as migrate_vma_collect_skip(). Removing the duplicated code.

Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
mm/migrate.c +3 -19
index 832483f..95e038d 100644
@@ -2128,22 +2128,6 @@ struct migrate_vma {
 	unsigned long		end;
 };
 
-static int migrate_vma_collect_hole(unsigned long start,
-				    unsigned long end,
-				    struct mm_walk *walk)
-{
-	struct migrate_vma *migrate = walk->private;
-	unsigned long addr;
-
-	for (addr = start & PAGE_MASK; addr < end; addr += PAGE_SIZE) {
-		migrate->src[migrate->npages] = 0;
-		migrate->dst[migrate->npages] = 0;
-		migrate->npages++;
-	}
-
-	return 0;
-}
-
 static int migrate_vma_collect_skip(unsigned long start,
 				    unsigned long end,
 				    struct mm_walk *walk)
@@ -2173,7 +2157,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
 again:
 	if (pmd_none(*pmdp))
-		return migrate_vma_collect_hole(start, end, walk);
+		return migrate_vma_collect_skip(start, end, walk);
 
 	if (pmd_trans_huge(*pmdp)) {
 		struct page *page;
@@ -2206,7 +2190,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 				return migrate_vma_collect_skip(start, end,
 								walk);
 			if (pmd_none(*pmdp))
-				return migrate_vma_collect_hole(start, end,
+				return migrate_vma_collect_skip(start, end,
 								walk);
 		}
 	}
@@ -2337,7 +2321,7 @@ static void migrate_vma_collect(struct migrate_vma *migrate)
 
 	mm_walk.pmd_entry = migrate_vma_collect_pmd;
 	mm_walk.pte_entry = NULL;
-	mm_walk.pte_hole = migrate_vma_collect_hole;
+	mm_walk.pte_hole = migrate_vma_collect_skip;
 	mm_walk.hugetlb_entry = NULL;
 	mm_walk.test_walk = NULL;
 	mm_walk.vma = migrate->vma;
Signature · 1 line
2.7.5
#6 lore raw

Re: [PATCH 3/3] mm/migrate: remove the duplicated code migrate_vma_collect_hole()

Quoted 3 lines · Pingfan Liu

After the previous patch which sees hole as invalid source, migrate_vma_collect_hole() has the same code as migrate_vma_collect_skip(). Removing the duplicated code.

NAK this one too given previous NAK.

Quoted 74 lines
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)
mm/migrate.c +3 -19
index 832483f..95e038d 100644
@@ -2128,22 +2128,6 @@ struct migrate_vma {
 	unsigned long		end;
 };
 
-static int migrate_vma_collect_hole(unsigned long start,
-				    unsigned long end,
-				    struct mm_walk *walk)
-{
-	struct migrate_vma *migrate = walk->private;
-	unsigned long addr;
-
-	for (addr = start & PAGE_MASK; addr < end; addr += PAGE_SIZE) {
-		migrate->src[migrate->npages] = 0;
-		migrate->dst[migrate->npages] = 0;
-		migrate->npages++;
-	}
-
-	return 0;
-}
-
 static int migrate_vma_collect_skip(unsigned long start,
 				    unsigned long end,
 				    struct mm_walk *walk)
@@ -2173,7 +2157,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
 again:
 	if (pmd_none(*pmdp))
-		return migrate_vma_collect_hole(start, end, walk);
+		return migrate_vma_collect_skip(start, end, walk);
 
 	if (pmd_trans_huge(*pmdp)) {
 		struct page *page;
@@ -2206,7 +2190,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 				return migrate_vma_collect_skip(start, end,
 								walk);
 			if (pmd_none(*pmdp))
-				return migrate_vma_collect_hole(start, end,
+				return migrate_vma_collect_skip(start, end,
 								walk);
 		}
 	}
@@ -2337,7 +2321,7 @@ static void migrate_vma_collect(struct migrate_vma *migrate)
 
 	mm_walk.pmd_entry = migrate_vma_collect_pmd;
 	mm_walk.pte_entry = NULL;
-	mm_walk.pte_hole = migrate_vma_collect_hole;
+	mm_walk.pte_hole = migrate_vma_collect_skip;
 	mm_walk.hugetlb_entry = NULL;
 	mm_walk.test_walk = NULL;
 	mm_walk.vma = migrate->vma;
Signature · 1 line
2.7.5
Reviewed-by on v1 1/3
#7 lore raw
In reply to Pingfan Liu

This needs something beyond the subject line. Maybe ...

After these assignments, we either restart the loop with a fresh variable, or we assign to the variable again without using the value we've assigned.

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 3 lines
mm/migrate.c +0 -1
 			goto next;
 		}
-		pfn = page_to_pfn(page);

After you've done all this, as far as I can tell, the 'pfn' variable is only used in one arm of the conditions, so it can be moved there.

ie something like:

- unsigned long mpfn, pfn;
+ unsigned long mpfn;
...
- pfn = pte_pfn(pte);
...
+ unsigned long pfn = pte_pfn(pte);
+

#8 lore raw
Quoted 18 lines · Matthew Wilcox

This needs something beyond the subject line. Maybe ...

After these assignments, we either restart the loop with a fresh variable, or we assign to the variable again without using the value we've assigned.

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 3 lines
mm/migrate.c +0 -1
 			goto next;
 		}
-		pfn = page_to_pfn(page);

After you've done all this, as far as I can tell, the 'pfn' variable is only used in one arm of the conditions, so it can be moved there.

ie something like:

Review

Quoted 7 lines
(quoted diff) +3 -2
-               unsigned long mpfn, pfn;
+               unsigned long mpfn;
...
-               pfn = pte_pfn(pte);
...
+                       unsigned long pfn = pte_pfn(pte);
+

This makes code better. Thank you for the suggestion. Will send v2 for this patch.

Regards,
Pingfan

#9 lore raw

PATCH v2 1/1 mm/migrate: clean up useless code in migrate_vma_collect_pmd()

Clean up useless 'pfn' variable.

Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate.c +3 -6
index 8992741..d483a55 100644
@@ -2225,17 +2225,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 		pte_t pte;
 
 		pte = *ptep;
-		pfn = pte_pfn(pte);
 
 		if (pte_none(pte)) {
 			mpfn = MIGRATE_PFN_MIGRATE;
 			migrate->cpages++;
-			pfn = 0;
 			goto next;
 		}
 
 		if (!pte_present(pte)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 
 			/*
 			 * Only care about unaddressable device page special
@@ -2252,10 +2250,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 			if (is_write_device_private_entry(entry))
 				mpfn |= MIGRATE_PFN_WRITE;
 		} else {
+			pfn = pte_pfn(pte);
 			if (is_zero_pfn(pfn)) {
 				mpfn = MIGRATE_PFN_MIGRATE;
 				migrate->cpages++;
-				pfn = 0;
 				goto next;
 			}
 			page = vm_normal_page(migrate->vma, addr, pte);
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
 		/* FIXME support THP */
 		if (!page || !page->mapping || PageTransCompound(page)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 			goto next;
 		}
-		pfn = page_to_pfn(page);
 
 		/*
 		 * By getting a reference on the page we pin it and that blocks
Signature · 1 line
2.7.5
Reviewed-by on v2 1/1
#10 lore raw
Quoted 56 lines · Pingfan Liu

Clean up useless 'pfn' variable.

Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
  mm/migrate.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate.c +2 -4
index 8992741..d483a55 100644
@@ -2225,17 +2225,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  		pte_t pte;
 
  		pte = *ptep;
-		pfn = pte_pfn(pte);
 
  		if (pte_none(pte)) {
  			mpfn = MIGRATE_PFN_MIGRATE;
  			migrate->cpages++;
-			pfn = 0;
  			goto next;
  		}
 
  		if (!pte_present(pte)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 
  			/*
  			 * Only care about unaddressable device page special
@@ -2252,10 +2250,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  			if (is_write_device_private_entry(entry))
  				mpfn |= MIGRATE_PFN_WRITE;
  		} else {
+			pfn = pte_pfn(pte);
  			if (is_zero_pfn(pfn)) {
  				mpfn = MIGRATE_PFN_MIGRATE;
  				migrate->cpages++;
-				pfn = 0;
  				goto next;
  			}
  			page = vm_normal_page(migrate->vma, addr, pte);
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 10 lines
mm/migrate.c +1 -2
  		/* FIXME support THP */
  		if (!page || !page->mapping || PageTransCompound(page)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
  			goto next;
  		}
-		pfn = page_to_pfn(page);
 
  		/*
  		 * By getting a reference on the page we pin it and that blocks

Thanks, I was planning to do this too.

#11 lore raw
In reply to Pingfan Liu
Quoted 1 line · Pingfan Liu

Clean up useless 'pfn' variable.

NAK there is a bug see below:

Quoted 53 lines
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
 mm/migrate.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate.c +2 -4
index 8992741..d483a55 100644
@@ -2225,17 +2225,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 		pte_t pte;
 
 		pte = *ptep;
-		pfn = pte_pfn(pte);
 
 		if (pte_none(pte)) {
 			mpfn = MIGRATE_PFN_MIGRATE;
 			migrate->cpages++;
-			pfn = 0;
 			goto next;
 		}
 
 		if (!pte_present(pte)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 
 			/*
 			 * Only care about unaddressable device page special
@@ -2252,10 +2250,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 			if (is_write_device_private_entry(entry))
 				mpfn |= MIGRATE_PFN_WRITE;
 		} else {
+			pfn = pte_pfn(pte);
 			if (is_zero_pfn(pfn)) {
 				mpfn = MIGRATE_PFN_MIGRATE;
 				migrate->cpages++;
-				pfn = 0;
 				goto next;
 			}
 			page = vm_normal_page(migrate->vma, addr, pte);

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 8 lines
mm/migrate.c +1 -2
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
 		/* FIXME support THP */
 		if (!page || !page->mapping || PageTransCompound(page)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 			goto next;
 		}
-		pfn = page_to_pfn(page);

You can not remove that one ! Otherwise it will break the device private case.

#12 lore raw
Quoted 59 lines · Jerome Glisse
Quoted 1 line · Pingfan Liu

Clean up useless 'pfn' variable.

NAK there is a bug see below:

Quoted 54 lines
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
  mm/migrate.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate.c +2 -4
index 8992741..d483a55 100644
@@ -2225,17 +2225,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  		pte_t pte;
 
  		pte = *ptep;
-		pfn = pte_pfn(pte);
 
  		if (pte_none(pte)) {
  			mpfn = MIGRATE_PFN_MIGRATE;
  			migrate->cpages++;
-			pfn = 0;
  			goto next;
  		}
 
  		if (!pte_present(pte)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
 
  			/*
  			 * Only care about unaddressable device page special
@@ -2252,10 +2250,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  			if (is_write_device_private_entry(entry))
  				mpfn |= MIGRATE_PFN_WRITE;
  		} else {
+			pfn = pte_pfn(pte);
  			if (is_zero_pfn(pfn)) {
  				mpfn = MIGRATE_PFN_MIGRATE;
  				migrate->cpages++;
-				pfn = 0;
  				goto next;
  			}
  			page = vm_normal_page(migrate->vma, addr, pte);
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
 
Quoted 11 lines

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 7 lines
mm/migrate.c +1 -2
  		/* FIXME support THP */
  		if (!page || !page->mapping || PageTransCompound(page)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
  			goto next;
  		}
-		pfn = page_to_pfn(page);

You can not remove that one ! Otherwise it will break the device private case.

I don't understand. The only use of "pfn" I see is in the "else" clause above where it is set just before using it.

#13 lore raw
Quoted 68 lines · Ralph Campbell
Quoted 56 lines · Jerome Glisse
Quoted 1 line · Pingfan Liu

Clean up useless 'pfn' variable.

NAK there is a bug see below:

Quoted 51 lines
Cc "Jérôme Glisse" <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Mel Gorman <[email protected]>
Cc Jan Kara <[email protected]>
Cc "Kirill A. Shutemov" <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Kravetz <[email protected]>
Cc Andrea Arcangeli <[email protected]>
Cc Matthew Wilcox <[email protected]>

To: [email protected]
Cc: [email protected]

---
  mm/migrate.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
mm/migrate.c +2 -4
index 8992741..d483a55 100644
@@ -2225,17 +2225,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  		pte_t pte;
  		pte = *ptep;
-		pfn = pte_pfn(pte);
  		if (pte_none(pte)) {
  			mpfn = MIGRATE_PFN_MIGRATE;
  			migrate->cpages++;
-			pfn = 0;
  			goto next;
  		}
  		if (!pte_present(pte)) {
-			mpfn = pfn = 0;
+			mpfn = 0;
  			/*
  			 * Only care about unaddressable device page special
@@ -2252,10 +2250,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  			if (is_write_device_private_entry(entry))
  				mpfn |= MIGRATE_PFN_WRITE;
  		} else {
+			pfn = pte_pfn(pte);
  			if (is_zero_pfn(pfn)) {
  				mpfn = MIGRATE_PFN_MIGRATE;
  				migrate->cpages++;
-				pfn = 0;
  				goto next;
  			}
  			page = vm_normal_page(migrate->vma, addr, pte);
@@ -2265,10 +2263,9 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp,
  		/* FIXME support THP */
  		if (!page || !page->mapping || PageTransCompound(page)) {
Quoted 9 lines

mm/migrate.c static int migrate_vma_collect_pmd(pmd_t *pmdp, · line 2271

Quoted 5 lines
mm/migrate.c +1 -2
-			mpfn = pfn = 0;
+			mpfn = 0;
  			goto next;
  		}
-		pfn = page_to_pfn(page);

You can not remove that one ! Otherwise it will break the device private case.

Quoted 2 lines

I don't understand. The only use of "pfn" I see is in the "else" clause above where it is set just before using it.

Ok i managed to confuse myself with mpfn and probably with old version of the code. Sorry for reading too quickly. Can we move unsigned long pfn; into the else { branch so that there is no more confusion to its scope.

Cheers,
Jérôme

#14 lore raw
Quoted 10 lines · Jerome Glisse

On Thu, Aug 15, 2019 at 12:23:44PM -0700, Ralph Campbell wrote:
[...]

Quoted 3 lines

I don't understand. The only use of "pfn" I see is in the "else" clause above where it is set just before using it.

Ok i managed to confuse myself with mpfn and probably with old version of the code. Sorry for reading too quickly. Can we move unsigned long pfn; into the else { branch so that there is no more confusion to its scope.

Looks better, I will update v3.

Thanks,
Pingfan