Skip to content

Commit 5288153

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: migrate: split folio_migrate_mapping()
The folio refcount check is moved out for both !mapping and mapping folio, also update comment from page to folio for folio_migrate_mapping(). No functional change intended. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kefeng Wang <[email protected]> Cc: Alistair Popple <[email protected]> Cc: Benjamin LaHaise <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jane Chu <[email protected]> Cc: Jérôme Glisse <[email protected]> Cc: Jiaqi Yan <[email protected]> Cc: Lance Yang <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Muchun Song <[email protected]> Cc: Naoya Horiguchi <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Tony Luck <[email protected]> Cc: Vishal Moola (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 02f4ee5 commit 5288153

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

mm/migrate.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -393,28 +393,23 @@ static int folio_expected_refs(struct address_space *mapping,
393393
}
394394

395395
/*
396-
* Replace the page in the mapping.
396+
* Replace the folio in the mapping.
397397
*
398398
* The number of remaining references must be:
399-
* 1 for anonymous pages without a mapping
400-
* 2 for pages with a mapping
401-
* 3 for pages with a mapping and PagePrivate/PagePrivate2 set.
399+
* 1 for anonymous folios without a mapping
400+
* 2 for folios with a mapping
401+
* 3 for folios with a mapping and PagePrivate/PagePrivate2 set.
402402
*/
403-
int folio_migrate_mapping(struct address_space *mapping,
404-
struct folio *newfolio, struct folio *folio, int extra_count)
403+
static int __folio_migrate_mapping(struct address_space *mapping,
404+
struct folio *newfolio, struct folio *folio, int expected_count)
405405
{
406406
XA_STATE(xas, &mapping->i_pages, folio_index(folio));
407407
struct zone *oldzone, *newzone;
408408
int dirty;
409-
int expected_count = folio_expected_refs(mapping, folio) + extra_count;
410409
long nr = folio_nr_pages(folio);
411410
long entries, i;
412411

413412
if (!mapping) {
414-
/* Anonymous page without mapping */
415-
if (folio_ref_count(folio) != expected_count)
416-
return -EAGAIN;
417-
418413
/* Take off deferred split queue while frozen and memcg set */
419414
if (folio_test_large(folio) &&
420415
folio_test_large_rmappable(folio)) {
@@ -465,7 +460,7 @@ int folio_migrate_mapping(struct address_space *mapping,
465460
entries = 1;
466461
}
467462

468-
/* Move dirty while page refs frozen and newpage not yet exposed */
463+
/* Move dirty while folio refs frozen and newfolio not yet exposed */
469464
dirty = folio_test_dirty(folio);
470465
if (dirty) {
471466
folio_clear_dirty(folio);
@@ -479,7 +474,7 @@ int folio_migrate_mapping(struct address_space *mapping,
479474
}
480475

481476
/*
482-
* Drop cache reference from old page by unfreezing
477+
* Drop cache reference from old folio by unfreezing
483478
* to one less reference.
484479
* We know this isn't the last reference.
485480
*/
@@ -490,11 +485,11 @@ int folio_migrate_mapping(struct address_space *mapping,
490485

491486
/*
492487
* If moved to a different zone then also account
493-
* the page for that zone. Other VM counters will be
488+
* the folio for that zone. Other VM counters will be
494489
* taken care of when we establish references to the
495-
* new page and drop references to the old page.
490+
* new folio and drop references to the old folio.
496491
*
497-
* Note that anonymous pages are accounted for
492+
* Note that anonymous folios are accounted for
498493
* via NR_FILE_PAGES and NR_ANON_MAPPED if they
499494
* are mapped to swap space.
500495
*/
@@ -534,6 +529,17 @@ int folio_migrate_mapping(struct address_space *mapping,
534529

535530
return MIGRATEPAGE_SUCCESS;
536531
}
532+
533+
int folio_migrate_mapping(struct address_space *mapping,
534+
struct folio *newfolio, struct folio *folio, int extra_count)
535+
{
536+
int expected_count = folio_expected_refs(mapping, folio) + extra_count;
537+
538+
if (folio_ref_count(folio) != expected_count)
539+
return -EAGAIN;
540+
541+
return __folio_migrate_mapping(mapping, newfolio, folio, expected_count);
542+
}
537543
EXPORT_SYMBOL(folio_migrate_mapping);
538544

539545
/*

0 commit comments

Comments
 (0)