[PATCH v3 5/6] mm: swap: make should_try_to_free_swap() support large-folio

Barry Song posted 6 patches 1 year, 9 months ago
There is a newer version of this series
[PATCH v3 5/6] mm: swap: make should_try_to_free_swap() support large-folio
Posted by Barry Song 1 year, 9 months ago
From: Chuanhua Han <hanchuanhua@oppo.com>

The function should_try_to_free_swap() operates under the assumption
that swap-in always occurs at the normal page granularity,
i.e., folio_nr_pages() = 1. However, in reality, for large folios,
add_to_swap_cache() will invoke folio_ref_add(folio, nr).  To accommodate
large folio swap-in, this patch eliminates this assumption.

Signed-off-by: Chuanhua Han <hanchuanhua@oppo.com>
Co-developed-by: Barry Song <v-songbaohua@oppo.com>
Signed-off-by: Barry Song <v-songbaohua@oppo.com>
Acked-by: Chris Li <chrisl@kernel.org>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index 74cdefd58f5f..22e7c33cc747 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3877,7 +3877,7 @@ static inline bool should_try_to_free_swap(struct folio *folio,
 	 * reference only in case it's likely that we'll be the exlusive user.
 	 */
 	return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) &&
-		folio_ref_count(folio) == 2;
+		folio_ref_count(folio) == (1 + folio_nr_pages(folio));
 }
 
 static vm_fault_t pte_marker_clear(struct vm_fault *vmf)
-- 
2.34.1
Re: [PATCH v3 5/6] mm: swap: make should_try_to_free_swap() support large-folio
Posted by David Hildenbrand 1 year, 9 months ago
On 03.05.24 02:50, Barry Song wrote:
> From: Chuanhua Han <hanchuanhua@oppo.com>
> 
> The function should_try_to_free_swap() operates under the assumption
> that swap-in always occurs at the normal page granularity,
> i.e., folio_nr_pages() = 1. However, in reality, for large folios,
> add_to_swap_cache() will invoke folio_ref_add(folio, nr).  To accommodate
> large folio swap-in, this patch eliminates this assumption.
> 
> Signed-off-by: Chuanhua Han <hanchuanhua@oppo.com>
> Co-developed-by: Barry Song <v-songbaohua@oppo.com>
> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> Acked-by: Chris Li <chrisl@kernel.org>
> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
> ---
>   mm/memory.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 74cdefd58f5f..22e7c33cc747 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3877,7 +3877,7 @@ static inline bool should_try_to_free_swap(struct folio *folio,
>   	 * reference only in case it's likely that we'll be the exlusive user.
>   	 */
>   	return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) &&
> -		folio_ref_count(folio) == 2;
> +		folio_ref_count(folio) == (1 + folio_nr_pages(folio));
>   }
>   
>   static vm_fault_t pte_marker_clear(struct vm_fault *vmf)


Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb