2024-04-09 08:28:24

by Barry Song

[permalink] [raw]
Subject: [PATCH v2 2/5] mm: swap: make should_try_to_free_swap() support large-folio

From: Chuanhua Han <[email protected]>

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 <[email protected]>
Co-developed-by: Barry Song <[email protected]>
Signed-off-by: Barry Song <[email protected]>
Acked-by: Chris Li <[email protected]>
Reviewed-by: Ryan Roberts <[email protected]>
---
mm/memory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index 78422d1c7381..2702d449880e 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3856,7 +3856,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



2024-04-15 07:13:24

by Huang, Ying

[permalink] [raw]
Subject: Re: [PATCH v2 2/5] mm: swap: make should_try_to_free_swap() support large-folio

Barry Song <[email protected]> writes:

> From: Chuanhua Han <[email protected]>
>
> 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
~~~~~~~~~~~~~~

nits: folio_nr_pages() is better for understanding.

Otherwise, LGTM, Thanks!

Reviewed-by: "Huang, Ying" <[email protected]>

> = 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 <[email protected]>
> Co-developed-by: Barry Song <[email protected]>
> Signed-off-by: Barry Song <[email protected]>
> Acked-by: Chris Li <[email protected]>
> Reviewed-by: Ryan Roberts <[email protected]>

> ---
> mm/memory.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 78422d1c7381..2702d449880e 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3856,7 +3856,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)