mm/migrate_device: Try to handle swapcache pages.
Subsystems (2)
PATCH 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.
As a detail, do not mess with shmem pages, as they handle swap internally.
--- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
mm/migrate_device.c +10 -2
@@ -12,6 +12,7 @@#include <linux/mmu_notifier.h> #include <linux/oom.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <linux/rmap.h> #include <linux/swapops.h> #include <asm/tlbflush.h>
@@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns,/* * For now only support anonymous memory migrating to * device private or coherent memory. +* +* Try to get rid of swap cache if possible. +* Leave shmem pages alone, they handle swap internally +* */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; -continue ; +if (shmem_mapping (mapping) || + !folio_free_swap (page_folio (page))) { + src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; +continue ; + } } }else if (is_zone_device_page (newpage)) {/*
Signature · 1 line
2.17.1
Quoted 34 lines · [email protected] writes:
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.
As a detail, do not mess with shmem pages, as they handle swap internally.
Cc Alistair Popple <[email protected]>Cc John Hubbard <[email protected]>Cc Ralph Campbell <[email protected]>Signed-off-by Mika Penttilä <[email protected]>--- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)mm/migrate_device.c +1
-0@@ -12,6 +12,7 @@#include <linux/mmu_notifier.h> #include <linux/oom.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <linux/rmap.h> #include <linux/swapops.h> #include <asm/tlbflush.h> @@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns,/* * For now only support anonymous memory migrating to * device private or coherent memory.
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 761
Quoted 10 lines
mm/migrate_device.c +6
-2+* +* Try to get rid of swap cache if possible. +* Leave shmem pages alone, they handle swap internally +* */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; -continue ; +if (shmem_mapping (mapping) || + !folio_free_swap (page_folio (page))) {
Should we filter out file pages firstly?
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 767
Quoted 6 lines
mm/migrate_device.c +3
-0+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; +continue ; + } } }else if (is_zone_device_page (newpage)) {/*
Best Regards,
Huang, Ying
H,
Quoted 40 lines · Ying
Quoted 38 lines · [email protected] writes:
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.
As a detail, do not mess with shmem pages, as they handle swap internally.
Cc Alistair Popple <[email protected]>Cc John Hubbard <[email protected]>Cc Ralph Campbell <[email protected]>Signed-off-by Mika Penttilä <[email protected]>--- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)mm/migrate_device.c +5
-0@@ -12,6 +12,7 @@#include <linux/mmu_notifier.h> #include <linux/oom.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <linux/rmap.h> #include <linux/swapops.h> #include <asm/tlbflush.h> @@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns,/* * For now only support anonymous memory migrating to * device private or coherent memory. +* +* Try to get rid of swap cache if possible. +* Leave shmem pages alone, they handle swap internally +*
Quoted 8 lines
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 761
Quoted 6 lines
mm/migrate_device.c +2
-2*/ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; -continue ; +if (shmem_mapping (mapping) || + !folio_free_swap (page_folio (page))) {Should we filter out file pages firstly?
folio_free_swap() checks first and returns false if not swapcache page (ie including normal file pages) so think that is enough, but maybe for clarity and not depending on it, could be good explicitly check for swapcache before calling folio_free_swap().
Quoted 11 lines
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 767
Quoted 7 lines
mm/migrate_device.c +3
-0+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; +continue ; + } } }else if (is_zone_device_page (newpage)) {/* Best Regards,
Huang, Ying
Thanks,
Mika
Quoted 52 lines · Mika Penttilä
H,
Quoted 39 lines · Ying
Quoted 37 lines · [email protected] writes:
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.
As a detail, do not mess with shmem pages, as they handle swap internally.
Cc Alistair Popple <[email protected]>Cc John Hubbard <[email protected]>Cc Ralph Campbell <[email protected]>Signed-off-by Mika Penttil <[email protected]>--- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)mm/migrate_device.c +4
-0@@ -12,6 +12,7 @@#include <linux/mmu_notifier.h> #include <linux/oom.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <linux/rmap.h> #include <linux/swapops.h> #include <asm/tlbflush.h> @@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns,/* * For now only support anonymous memory migrating to * device private or coherent memory. +* +* Try to get rid of swap cache if possible. +* Leave shmem pages alone, they handle swap internally Quoted 8 lines
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 761
Quoted 7 lines
mm/migrate_device.c +3
-2+* */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; -continue ; +if (shmem_mapping (mapping) || + !folio_free_swap (page_folio (page))) {Should we filter out file pages firstly?
Quoted 2 lines
folio_free_swap()checks first and returns false if not swapcache page (ie including normal file pages) so think that is enough,
You are right. folio_free_swap() will call folio_test_swapcache(), and which will check folio_test_swapbacked().
And, IIUC, we don't need to check shmem too. Because folio_free_swap() will not return true for shmem pages.
Quoted 2 lines
but maybe for clarity and not depending on it, could be good explicitly check for swapcache before calling
folio_free_swap().
Yes. That will be more clear. I suggest to use folio_test_anon(), that will filter out shmem pages too.
Quoted 7 lines
Quoted 7 lines
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 767
Quoted 7 lines
mm/migrate_device.c +3
-0+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; +continue ; + } } }else if (is_zone_device_page (newpage)) {/*
Best Regards,
Huang, Ying
Hi,
Quoted 54 lines · Ying
Quoted 52 lines · Mika Penttilä
H,
Quoted 47 lines · Ying
Quoted 34 lines · [email protected] writes:
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.
As a detail, do not mess with shmem pages, as they handle swap internally.
Cc Alistair Popple <[email protected]>Cc John Hubbard <[email protected]>Cc Ralph Campbell <[email protected]>Signed-off-by Mika Penttil <[email protected]>--- mm/migrate_device.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)mm/migrate_device.c +1
-0@@ -12,6 +12,7 @@#include <linux/mmu_notifier.h> #include <linux/oom.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include <linux/rmap.h> #include <linux/swapops.h> #include <asm/tlbflush.h> @@ -750,10 +751,17 @@ static void __migrate_device_pages(unsigned long *src_pfns,/* * For now only support anonymous memory migrating to * device private or coherent memory. mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 761
Quoted 10 lines
mm/migrate_device.c +6
-2+* +* Try to get rid of swap cache if possible. +* Leave shmem pages alone, they handle swap internally +* */ if (mapping) { - src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; -continue ; +if (shmem_mapping (mapping) || + !folio_free_swap (page_folio (page))) {Should we filter out file pages firstly?
Quoted 8 lines
Quoted 2 lines
folio_free_swap()checks first and returns false if not swapcache page (ie including normal file pages) so think that is enough,You are right.
folio_free_swap()will callfolio_test_swapcache(), and which will checkfolio_test_swapbacked().And, IIUC, we don't need to check shmem too. Because
folio_free_swap()will not return true for shmem pages.
Ah yes true, for not written out shmem page folio_free_swap() returns false (because !swapcache). And written out (but in swap cache) returns false because folio_swapped() == true
Quoted 6 lines
Quoted 3 lines
but maybe for clarity and not depending on it, could be good explicitly check for swapcache before calling
folio_free_swap().Yes. That will be more clear. I suggest to use
folio_test_anon(), that will filter out shmem pages too.
Agreed.
Quoted 12 lines
Quoted 8 lines
Quoted 8 lines
mm/migrate_device.c static void __migrate_device_pages(unsigned long *src_pfns, · line 767
Quoted 8 lines
mm/migrate_device.c +3
-0+ src_pfns[i] &= ~MIGRATE_PFN_MIGRATE ; +continue ; + } } }else if (is_zone_device_page (newpage)) {/* Best Regards,
Huang, Ying
Thanks,
Mika