mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] mm/migrate_device: Try to handle swapcache pages
@ 2023-06-06  5:01 mpenttil
  2023-06-06  7:44 ` David Hildenbrand
  2023-06-07 14:10 ` Christoph Hellwig
  0 siblings, 2 replies; 8+ messages in thread
From: mpenttil @ 2023-06-06  5:01 UTC (permalink / raw)
  To: linux-kernel, linux-mm
  Cc: Mika Penttilä,
	Alistair Popple, John Hubbard, Ralph Campbell, Huang, Ying

From: Mika Penttilä <mpenttil@redhat.com>

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.

Cc: Alistair Popple <apopple@nvidia.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Ralph Campbell <rcampbell@nvidia.com>
Cc: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Signed-off-by: Mika Penttilä <mpenttil@redhat.com>
---

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(-)

diff --git a/mm/migrate_device.c b/mm/migrate_device.c
index d30c9de60b0d..f76ebccfe067 100644
--- a/mm/migrate_device.c
+++ b/mm/migrate_device.c
@@ -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)) {
 			/*
-- 
2.17.1


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-06  5:01 [PATCH v3] mm/migrate_device: Try to handle swapcache pages mpenttil
@ 2023-06-06  7:44 ` David Hildenbrand
  2023-06-06  7:46   ` David Hildenbrand
  2023-06-07 14:10 ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: David Hildenbrand @ 2023-06-06  7:44 UTC (permalink / raw)
  To: mpenttil, linux-kernel, linux-mm
  Cc: Alistair Popple, John Hubbard, Ralph Campbell, Huang, Ying

On 06.06.23 07:01, mpenttil@redhat.com wrote:
> From: Mika Penttilä <mpenttil@redhat.com>
> 
> 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.
> 
> Cc: Alistair Popple <apopple@nvidia.com>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Ralph Campbell <rcampbell@nvidia.com>
> Cc: "Huang, Ying" <ying.huang@intel.com>
> Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
> Reviewed-by: Alistair Popple <apopple@nvidia.com>
> Signed-off-by: Mika Penttilä <mpenttil@redhat.com>
> ---
> 
> 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(-)
> 
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index d30c9de60b0d..f76ebccfe067 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -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;

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

-- 
Cheers,

David / dhildenb


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-06  7:44 ` David Hildenbrand
@ 2023-06-06  7:46   ` David Hildenbrand
  2023-06-06  7:59     ` Mika Penttilä
  0 siblings, 1 reply; 8+ messages in thread
From: David Hildenbrand @ 2023-06-06  7:46 UTC (permalink / raw)
  To: mpenttil, linux-kernel, linux-mm
  Cc: Alistair Popple, John Hubbard, Ralph Campbell, Huang, Ying

On 06.06.23 09:44, David Hildenbrand wrote:
> On 06.06.23 07:01, mpenttil@redhat.com wrote:
>> From: Mika Penttilä <mpenttil@redhat.com>
>>
>> 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.
>>
>> Cc: Alistair Popple <apopple@nvidia.com>
>> Cc: John Hubbard <jhubbard@nvidia.com>
>> Cc: Ralph Campbell <rcampbell@nvidia.com>
>> Cc: "Huang, Ying" <ying.huang@intel.com>
>> Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
>> Reviewed-by: Alistair Popple <apopple@nvidia.com>
>> Signed-off-by: Mika Penttilä <mpenttil@redhat.com>
>> ---
>>
>> 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(-)
>>
>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>> index d30c9de60b0d..f76ebccfe067 100644
>> --- a/mm/migrate_device.c
>> +++ b/mm/migrate_device.c
>> @@ -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;
> 
> 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?

-- 
Cheers,

David / dhildenb


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-06  7:46   ` David Hildenbrand
@ 2023-06-06  7:59     ` Mika Penttilä
  0 siblings, 0 replies; 8+ messages in thread
From: Mika Penttilä @ 2023-06-06  7:59 UTC (permalink / raw)
  To: David Hildenbrand, linux-kernel, linux-mm
  Cc: Alistair Popple, John Hubbard, Ralph Campbell, Huang, Ying

Hi,

On 6.6.2023 10.46, David Hildenbrand wrote:
> On 06.06.23 09:44, David Hildenbrand wrote:
>> On 06.06.23 07:01, mpenttil@redhat.com wrote:
>>> From: Mika Penttilä <mpenttil@redhat.com>
>>>
>>> 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.
>>>
>>> Cc: Alistair Popple <apopple@nvidia.com>
>>> Cc: John Hubbard <jhubbard@nvidia.com>
>>> Cc: Ralph Campbell <rcampbell@nvidia.com>
>>> Cc: "Huang, Ying" <ying.huang@intel.com>
>>> Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
>>> Reviewed-by: Alistair Popple <apopple@nvidia.com>
>>> Signed-off-by: Mika Penttilä <mpenttil@redhat.com>
>>> ---
>>>
>>> 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(-)
>>>
>>> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
>>> index d30c9de60b0d..f76ebccfe067 100644
>>> --- a/mm/migrate_device.c
>>> +++ b/mm/migrate_device.c
>>> @@ -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;
>>
>> 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?
> 

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



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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-06  5:01 [PATCH v3] mm/migrate_device: Try to handle swapcache pages mpenttil
  2023-06-06  7:44 ` David Hildenbrand
@ 2023-06-07 14:10 ` Christoph Hellwig
  2023-06-07 15:56   ` Mika Penttilä
  2023-06-07 16:06   ` Mika Penttilä
  1 sibling, 2 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-07 14:10 UTC (permalink / raw)
  To: mpenttil
  Cc: linux-kernel, linux-mm, Alistair Popple, John Hubbard,
	Ralph Campbell, Huang, Ying

On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote:
> From: Mika Penttilä <mpenttil@redhat.com>
> 
> 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.

>  		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?

> +				/*
> +				 * 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.


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-07 14:10 ` Christoph Hellwig
@ 2023-06-07 15:56   ` Mika Penttilä
  2023-06-07 16:06   ` Mika Penttilä
  1 sibling, 0 replies; 8+ messages in thread
From: Mika Penttilä @ 2023-06-07 15:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel, linux-mm, Alistair Popple, John Hubbard,
	Ralph Campbell, Huang, Ying

Hi,


On 7.6.2023 17.10, Christoph Hellwig wrote:
> On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote:
>> From: Mika Penttilä <mpenttil@redhat.com>
>>
>> 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.
> 
>>   		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?

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

> 
>> +				/*
>> +				 * 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


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-07 14:10 ` Christoph Hellwig
  2023-06-07 15:56   ` Mika Penttilä
@ 2023-06-07 16:06   ` Mika Penttilä
  2023-06-12  4:53     ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Mika Penttilä @ 2023-06-07 16:06 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel, linux-mm, Alistair Popple, John Hubbard,
	Ralph Campbell, Huang, Ying



On 7.6.2023 17.10, Christoph Hellwig wrote:
> On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote:
>> From: Mika Penttilä <mpenttil@redhat.com>
>>
>> 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..?


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

* Re: [PATCH v3] mm/migrate_device: Try to handle swapcache pages
  2023-06-07 16:06   ` Mika Penttilä
@ 2023-06-12  4:53     ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2023-06-12  4:53 UTC (permalink / raw)
  To: Mika Penttilä
  Cc: Christoph Hellwig, linux-kernel, linux-mm, Alistair Popple,
	John Hubbard, Ralph Campbell, Huang, Ying

On Wed, Jun 07, 2023 at 07:06:06PM +0300, Mika Penttilä wrote:
> 
> 
> On 7.6.2023 17.10, Christoph Hellwig wrote:
> > On Tue, Jun 06, 2023 at 08:01:49AM +0300, mpenttil@redhat.com wrote:
> > > From: Mika Penttilä <mpenttil@redhat.com>
> > > 
> > > 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.


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

end of thread, other threads:[~2023-06-12  4:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06  5:01 [PATCH v3] mm/migrate_device: Try to handle swapcache pages mpenttil
2023-06-06  7:44 ` David Hildenbrand
2023-06-06  7:46   ` David Hildenbrand
2023-06-06  7:59     ` Mika Penttilä
2023-06-07 14:10 ` Christoph Hellwig
2023-06-07 15:56   ` Mika Penttilä
2023-06-07 16:06   ` Mika Penttilä
2023-06-12  4:53     ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®