Skip to content

Commit 0b43b8b

Browse files
shivankgarg98akpm00
authored andcommitted
mm/khugepaged: clean up refcount check using folio_expected_ref_count()
Use folio_expected_ref_count() instead of open-coded logic in is_refcount_suitable(). This avoids code duplication and improves clarity. Drop is_refcount_suitable() as it is no longer needed. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Shivank Garg <[email protected]> Suggested-by: David Hildenbrand <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Dev Jain <[email protected]> Reviewed-by: Baolin Wang <[email protected]> Cc: Bharata B Rao <[email protected]> Cc: Fengwei Yin <[email protected]> Cc: Liam Howlett <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Mariano Pache <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 66bce7a commit 0b43b8b

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

mm/khugepaged.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -548,19 +548,6 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte,
548548
}
549549
}
550550

551-
static bool is_refcount_suitable(struct folio *folio)
552-
{
553-
int expected_refcount = folio_mapcount(folio);
554-
555-
if (!folio_test_anon(folio) || folio_test_swapcache(folio))
556-
expected_refcount += folio_nr_pages(folio);
557-
558-
if (folio_test_private(folio))
559-
expected_refcount++;
560-
561-
return folio_ref_count(folio) == expected_refcount;
562-
}
563-
564551
static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
565552
unsigned long address,
566553
pte_t *pte,
@@ -652,7 +639,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
652639
* but not from this process. The other process cannot write to
653640
* the page, only trigger CoW.
654641
*/
655-
if (!is_refcount_suitable(folio)) {
642+
if (folio_expected_ref_count(folio) != folio_ref_count(folio)) {
656643
folio_unlock(folio);
657644
result = SCAN_PAGE_COUNT;
658645
goto out;
@@ -1402,7 +1389,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,
14021389
* has excessive GUP pins (i.e. 512). Anyway the same check
14031390
* will be done again later the risk seems low.
14041391
*/
1405-
if (!is_refcount_suitable(folio)) {
1392+
if (folio_expected_ref_count(folio) != folio_ref_count(folio)) {
14061393
result = SCAN_PAGE_COUNT;
14071394
goto out_unmap;
14081395
}

0 commit comments

Comments
 (0)