Skip to contentSkip to conversation

mm/migrate_device: Try to handle swapcache pages

PATCH Superseded [email protected] 3 participants 8 messages Jun 6, 2023 – Jun 12, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mm/migrate_device: Try to handle swapcache pages

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Things can however be improved, for swapcache pages. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages.

---

v3:
- Adjust comments
- Add Reviewed-bys

v2:
- use folio_test_anon() (Huang, Ying)

 mm/migrate_device.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)
mm/migrate_device.c +16 -6
index d30c9de60b0d..f76ebccfe067 100644
@@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 
 		if (is_device_private_page(newpage) ||
 		    is_device_coherent_page(newpage)) {
-			/*
-			 * For now only support anonymous memory migrating to
-			 * device private or coherent memory.
-			 */
+
 			if (mapping) {
-				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-				continue;
+				struct folio *folio;
+
+				folio = page_folio(page);
+
+				/*
+				 * For now only support anonymous memory migrating to
+				 * device private or coherent memory.
+				 *
+				 * Try to get rid of swap cache if possible.
+				 *
+				 */
+				if (!folio_test_anon(folio) || !folio_free_swap(folio)) {
+					src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+					continue;
+				}
 			}
 		} else if (is_zone_device_page(newpage)) {
 			/*
Signature · 1 line
2.17.1
#1 lore raw
Quoted 47 lines · On 06.06.23 07:01, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Things can however be improved, for swapcache pages. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages.

---

v3:
- Adjust comments
- Add Reviewed-bys

v2:
- use folio_test_anon() (Huang, Ying)

  mm/migrate_device.c | 22 ++++++++++++++++------
  1 file changed, 16 insertions(+), 6 deletions(-)
mm/migrate_device.c +5 -6
index d30c9de60b0d..f76ebccfe067 100644
@@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 
  		if (is_device_private_page(newpage) ||
  		    is_device_coherent_page(newpage)) {
-			/*
-			 * For now only support anonymous memory migrating to
-			 * device private or coherent memory.
-			 */
+
  			if (mapping) {
-				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-				continue;
+				struct folio *folio;
+
+				folio = page_folio(page);
+

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 765

Quoted 10 lines
mm/migrate_device.c +10 -0
+				/*
+				 * For now only support anonymous memory migrating to
+				 * device private or coherent memory.
+				 *
+				 * Try to get rid of swap cache if possible.
+				 *
+				 */
+				if (!folio_test_anon(folio) || !folio_free_swap(folio)) {
+					src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+					continue;

I'm pretty sure the folio has to be locked in order to call folio_free_swap().

Signature · 3 lines
Cheers,

David / dhildenb
#2 lore raw
Quoted 53 lines · David Hildenbrand
Quoted 52 lines · On 06.06.23 07:01, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Things can however be improved, for swapcache pages. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages.

---

v3:
- Adjust comments
- Add Reviewed-bys

v2:
- use folio_test_anon() (Huang, Ying)

   mm/migrate_device.c | 22 ++++++++++++++++------
   1 file changed, 16 insertions(+), 6 deletions(-)
mm/migrate_device.c +10 -6
index d30c9de60b0d..f76ebccfe067 100644
@@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned long *src_pfns,
 
   		if (is_device_private_page(newpage) ||
   		    is_device_coherent_page(newpage)) {
-			/*
-			 * For now only support anonymous memory migrating to
-			 * device private or coherent memory.
-			 */
+
   			if (mapping) {
-				src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-				continue;
+				struct folio *folio;
+
+				folio = page_folio(page);
+
+				/*
+				 * For now only support anonymous memory migrating to
+				 * device private or coherent memory.
+				 *
+				 * Try to get rid of swap cache if possible.
Quoted 9 lines

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 765

Quoted 5 lines
mm/migrate_device.c +5 -0
+				 *
+				 */
+				if (!folio_test_anon(folio) || !folio_free_swap(folio)) {
+					src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
+					continue;

I'm pretty sure the folio has to be locked in order to call folio_free_swap().

Oh, staring at the bigger context, I assume we locked the folios via migrate_device_range(), correct?

Signature · 3 lines
Cheers,

David / dhildenb
#3 lore raw

Hi,

Quoted 65 lines · David Hildenbrand
Quoted 54 lines · David Hildenbrand
Quoted 53 lines · On 06.06.23 07:01, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Things can however be improved, for swapcache pages. Try to get rid of the swap cache, and if successful, go ahead as with other anonymous pages.

---

v3:
    - Adjust comments
    - Add Reviewed-bys

v2:
    - use folio_test_anon() (Huang, Ying)

   mm/migrate_device.c | 22 ++++++++++++++++------

   1 file changed, 16 insertions(+), 6 deletions(-)
mm/migrate_device.c +0 -0
index d30c9de60b0d..f76ebccfe067 100644
@@ -747,13 +747,23 @@ static void __migrate_device_pages(unsigned 
 long *src_pfns,

           if (is_device_private_page(newpage) || is_device_coherent_page(newpage)) {
-            /*
-             * For now only support anonymous memory migrating to -             * device private or coherent memory.
-             */
+
               if (mapping) {
-                src_pfns[i] &= ~MIGRATE_PFN_MIGRATE;
-                continue;
+                struct folio *folio;

mm/migrate_device.c +9 -0
+
+                folio = page_folio(page);
+
+                /*
+                 * For now only support anonymous memory migrating to
+                 * device private or coherent memory.
+                 *
+                 * Try to get rid of swap cache if possible.
+                 *
Quoted 9 lines
Quoted 5 lines

+                 */
+                if (!folio_test_anon(folio) || !folio_free_swap(folio)) {
+                    src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; +                    continue;

I'm pretty sure the folio has to be locked in order to call folio_free_swap().

Quoted 2 lines

Oh, staring at the bigger context, I assume we locked the folios via migrate_device_range(), correct?

Yes either that, or when migrating via virtual addresses migrate_vma_collect_pmd() has trylock_page() and we migrate only pages which succeed locking.

--Mika

#4 lore raw
In reply to [email protected]
Quoted 4 lines · On Tue, Jun 06, 2023 at 08:01:49AM +0300, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Please fix the commit log formatting, it should not exceed 7 lines.

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 751

Quoted 8 lines
mm/migrate_device.c +1 -4
 		if (is_device_private_page(newpage) ||
 		    is_device_coherent_page(newpage)) {
-			/*
-			 * For now only support anonymous memory migrating to
-			 * device private or coherent memory.
-			 */
+
 			if (mapping) {

Very nitpicky, but this empty line looks odd. Also isn't the comment still (mostly) correct given that file backed memory is still not supported?

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 763

Quoted 8 lines
mm/migrate_device.c +8 -0
+				/*
+				 * For now only support anonymous memory migrating to
+				 * device private or coherent memory.
+				 *
+				 * Try to get rid of swap cache if possible.
+				 *
+				 */
+				if (!folio_test_anon(folio) || !folio_free_swap(folio)) {

Please avoid the overly long lines.

#5 lore raw

Hi,

Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · On Tue, Jun 06, 2023 at 08:01:49AM +0300, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Please fix the commit log formatting, it should not exceed 7 lines.

Quoted 12 lines

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 751

Quoted 8 lines
  		if (is_device_private_page(newpage) ||
  		    is_device_coherent_page(newpage)) {
mm/migrate_device.c +1 -4
-			/*
-			 * For now only support anonymous memory migrating to
-			 * device private or coherent memory.
-			 */
+
  			if (mapping) {

Very nitpicky, but this empty line looks odd. Also isn't the comment still (mostly) correct given that file backed memory is still not supported?

Yes the comment is mostly correct and moved a few lines lower, complemented with a comment about the swap cache.

Quoted 12 lines

mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 763

Quoted 9 lines
mm/migrate_device.c +8 -0
+				/*
+				 * For now only support anonymous memory migrating to
+				 * device private or coherent memory.
+				 *
+				 * Try to get rid of swap cache if possible.
+				 *
+				 */
+				if (!folio_test_anon(folio) || !folio_free_swap(folio)) {

Please avoid the overly long lines.

Thanks,
Mika

#6 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · On Tue, Jun 06, 2023 at 08:01:49AM +0300, [email protected] wrote:

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Please fix the commit log formatting, it should not exceed 7 lines.

Not sure what you mean should not exceed 7 lines..?

#7 lore raw
Quoted 4 lines · Mika Penttilä
Quoted 1 line · Christoph Hellwig

On Tue, Jun 06, 2023 at 08:01:49AM +0300, [email protected] wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

From: Mika Penttilä <[email protected]>

Migrating file pages and swapcache pages into device memory is not supported. The decision is done based on page_mapping(). For now, swapcache pages are not migrated.

Please fix the commit log formatting, it should not exceed 7 lines.

Not sure what you mean should not exceed 7 lines..?

Sorry, this should be 73.