Use the number of pages in the folio to check the reference count as
preparation for supporting shmem mTHP collapse.
Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
mm/khugepaged.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index f11b4f172e61..60d95f08610c 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -1994,7 +1994,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
/*
* We control three references to the folio:
* - we hold a pin on it;
- * - one reference from page cache;
+ * - nr_pages reference from page cache;
* - one from lru_isolate_folio;
* If those are the only references, then any new usage
* of the folio will have to fetch it from the page
@@ -2002,7 +2002,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
* truncate, so any new usage will be blocked until we
* unlock folio after collapse/during rollback.
*/
- if (folio_ref_count(folio) != 3) {
+ if (folio_ref_count(folio) != 2 + folio_nr_pages(folio)) {
result = SCAN_PAGE_COUNT;
xas_unlock_irq(&xas);
folio_putback_lru(folio);
@@ -2185,7 +2185,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
folio_clear_active(folio);
folio_clear_unevictable(folio);
folio_unlock(folio);
- folio_put_refs(folio, 3);
+ folio_put_refs(folio, 2 + folio_nr_pages(folio));
}
goto out;
--
2.39.3
On 19.08.24 10:14, Baolin Wang wrote:
> Use the number of pages in the folio to check the reference count as
> preparation for supporting shmem mTHP collapse.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> mm/khugepaged.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index f11b4f172e61..60d95f08610c 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -1994,7 +1994,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
> /*
> * We control three references to the folio:
^ "three" is wrong now.
> * - we hold a pin on it;
> - * - one reference from page cache;
> + * - nr_pages reference from page cache;
> * - one from lru_isolate_folio;
> * If those are the only references, then any new usage
> * of the folio will have to fetch it from the page
> @@ -2002,7 +2002,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
> * truncate, so any new usage will be blocked until we
> * unlock folio after collapse/during rollback.
> */
> - if (folio_ref_count(folio) != 3) {
> + if (folio_ref_count(folio) != 2 + folio_nr_pages(folio)) {
> result = SCAN_PAGE_COUNT;
> xas_unlock_irq(&xas);
> folio_putback_lru(folio);
> @@ -2185,7 +2185,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
> folio_clear_active(folio);
> folio_clear_unevictable(folio);
> folio_unlock(folio);
> - folio_put_refs(folio, 3);
> + folio_put_refs(folio, 2 + folio_nr_pages(folio));
> }
>
> goto out;
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
On 2024/8/19 17:40, David Hildenbrand wrote:
> On 19.08.24 10:14, Baolin Wang wrote:
>> Use the number of pages in the folio to check the reference count as
>> preparation for supporting shmem mTHP collapse.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> mm/khugepaged.c | 6 +++---
>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
>> index f11b4f172e61..60d95f08610c 100644
>> --- a/mm/khugepaged.c
>> +++ b/mm/khugepaged.c
>> @@ -1994,7 +1994,7 @@ static int collapse_file(struct mm_struct *mm,
>> unsigned long addr,
>> /*
>> * We control three references to the folio:
>
> ^ "three" is wrong now.
Ah, good catch. Will change to '2 + nr_pages'.
>
>> * - we hold a pin on it;
>> - * - one reference from page cache;
>> + * - nr_pages reference from page cache;
>> * - one from lru_isolate_folio;
>> * If those are the only references, then any new usage
>> * of the folio will have to fetch it from the page
>> @@ -2002,7 +2002,7 @@ static int collapse_file(struct mm_struct *mm,
>> unsigned long addr,
>> * truncate, so any new usage will be blocked until we
>> * unlock folio after collapse/during rollback.
>> */
>> - if (folio_ref_count(folio) != 3) {
>> + if (folio_ref_count(folio) != 2 + folio_nr_pages(folio)) {
>> result = SCAN_PAGE_COUNT;
>> xas_unlock_irq(&xas);
>> folio_putback_lru(folio);
>> @@ -2185,7 +2185,7 @@ static int collapse_file(struct mm_struct *mm,
>> unsigned long addr,
>> folio_clear_active(folio);
>> folio_clear_unevictable(folio);
>> folio_unlock(folio);
>> - folio_put_refs(folio, 3);
>> + folio_put_refs(folio, 2 + folio_nr_pages(folio));
>> }
>> goto out;
>
> Acked-by: David Hildenbrand <david@redhat.com>
Thanks for reviewing.
© 2016 - 2026 Red Hat, Inc.