Skip to content

Commit 2397f78

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm/swap: convert try_to_free_swap to use a folio
Save a few calls to compound_head by converting the passed page to a folio. Reduces kernel text size by 74 bytes. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a2d33b5 commit 2397f78

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

mm/swapfile.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,16 +1568,15 @@ static bool swap_page_trans_huge_swapped(struct swap_info_struct *si,
15681568
return ret;
15691569
}
15701570

1571-
static bool page_swapped(struct page *page)
1571+
static bool folio_swapped(struct folio *folio)
15721572
{
15731573
swp_entry_t entry;
15741574
struct swap_info_struct *si;
15751575

1576-
if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!PageTransCompound(page)))
1577-
return page_swapcount(page) != 0;
1576+
if (!IS_ENABLED(CONFIG_THP_SWAP) || likely(!folio_test_large(folio)))
1577+
return page_swapcount(&folio->page) != 0;
15781578

1579-
page = compound_head(page);
1580-
entry.val = page_private(page);
1579+
entry = folio_swap_entry(folio);
15811580
si = _swap_info_get(entry);
15821581
if (si)
15831582
return swap_page_trans_huge_swapped(si, entry);
@@ -1590,13 +1589,14 @@ static bool page_swapped(struct page *page)
15901589
*/
15911590
int try_to_free_swap(struct page *page)
15921591
{
1593-
VM_BUG_ON_PAGE(!PageLocked(page), page);
1592+
struct folio *folio = page_folio(page);
1593+
VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
15941594

1595-
if (!PageSwapCache(page))
1595+
if (!folio_test_swapcache(folio))
15961596
return 0;
1597-
if (PageWriteback(page))
1597+
if (folio_test_writeback(folio))
15981598
return 0;
1599-
if (page_swapped(page))
1599+
if (folio_swapped(folio))
16001600
return 0;
16011601

16021602
/*
@@ -1617,9 +1617,8 @@ int try_to_free_swap(struct page *page)
16171617
if (pm_suspended_storage())
16181618
return 0;
16191619

1620-
page = compound_head(page);
1621-
delete_from_swap_cache(page);
1622-
SetPageDirty(page);
1620+
delete_from_swap_cache(&folio->page);
1621+
folio_set_dirty(folio);
16231622
return 1;
16241623
}
16251624

0 commit comments

Comments
 (0)