Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm/swapfile: convert try_to_free_swap() to folio_free_swap()

Add kernel-doc for folio_free_swap() and make it return bool. Add a
try_to_free_swap() compatibility wrapper.

Link: https://lkml.kernel.org/r/20220902194653.1739778-11-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
bdb0ed54 14d01ee9

+32 -15
+6
include/linux/swap.h
··· 490 490 491 491 extern void si_swapinfo(struct sysinfo *); 492 492 swp_entry_t folio_alloc_swap(struct folio *folio); 493 + bool folio_free_swap(struct folio *folio); 493 494 extern void put_swap_page(struct page *page, swp_entry_t entry); 494 495 extern swp_entry_t get_swap_page_of_type(int); 495 496 extern int get_swap_pages(int n, swp_entry_t swp_entries[], int entry_size); ··· 605 604 swp_entry_t entry; 606 605 entry.val = 0; 607 606 return entry; 607 + } 608 + 609 + static inline bool folio_free_swap(struct folio *folio) 610 + { 611 + return false; 608 612 } 609 613 610 614 static inline int add_swap_extent(struct swap_info_struct *sis,
+7
mm/folio-compat.c
··· 146 146 { 147 147 folio_putback_lru(page_folio(page)); 148 148 } 149 + 150 + #ifdef CONFIG_SWAP 151 + int try_to_free_swap(struct page *page) 152 + { 153 + return folio_free_swap(page_folio(page)); 154 + } 155 + #endif
+18 -14
mm/swapfile.c
··· 1567 1567 return swap_page_trans_huge_swapped(si, entry); 1568 1568 } 1569 1569 1570 - /* 1571 - * If swap is getting full, or if there are no more mappings of this page, 1572 - * then try_to_free_swap is called to free its swap space. 1570 + /** 1571 + * folio_free_swap() - Free the swap space used for this folio. 1572 + * @folio: The folio to remove. 1573 + * 1574 + * If swap is getting full, or if there are no more mappings of this folio, 1575 + * then call folio_free_swap to free its swap space. 1576 + * 1577 + * Return: true if we were able to release the swap space. 1573 1578 */ 1574 - int try_to_free_swap(struct page *page) 1579 + bool folio_free_swap(struct folio *folio) 1575 1580 { 1576 - struct folio *folio = page_folio(page); 1577 1581 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); 1578 1582 1579 1583 if (!folio_test_swapcache(folio)) 1580 - return 0; 1584 + return false; 1581 1585 if (folio_test_writeback(folio)) 1582 - return 0; 1586 + return false; 1583 1587 if (folio_swapped(folio)) 1584 - return 0; 1588 + return false; 1585 1589 1586 1590 /* 1587 1591 * Once hibernation has begun to create its image of memory, 1588 - * there's a danger that one of the calls to try_to_free_swap() 1592 + * there's a danger that one of the calls to folio_free_swap() 1589 1593 * - most probably a call from __try_to_reclaim_swap() while 1590 1594 * hibernation is allocating its own swap pages for the image, 1591 1595 * but conceivably even a call from memory reclaim - will free 1592 - * the swap from a page which has already been recorded in the 1593 - * image as a clean swapcache page, and then reuse its swap for 1596 + * the swap from a folio which has already been recorded in the 1597 + * image as a clean swapcache folio, and then reuse its swap for 1594 1598 * another page of the image. On waking from hibernation, the 1595 - * original page might be freed under memory pressure, then 1599 + * original folio might be freed under memory pressure, then 1596 1600 * later read back in from swap, now with the wrong data. 1597 1601 * 1598 1602 * Hibernation suspends storage while it is writing the image 1599 1603 * to disk so check that here. 1600 1604 */ 1601 1605 if (pm_suspended_storage()) 1602 - return 0; 1606 + return false; 1603 1607 1604 1608 delete_from_swap_cache(folio); 1605 1609 folio_set_dirty(folio); 1606 - return 1; 1610 + return true; 1607 1611 } 1608 1612 1609 1613 /*
+1 -1
mm/vmscan.c
··· 2049 2049 if (folio_test_swapcache(folio) && 2050 2050 (mem_cgroup_swap_full(&folio->page) || 2051 2051 folio_test_mlocked(folio))) 2052 - try_to_free_swap(&folio->page); 2052 + folio_free_swap(folio); 2053 2053 VM_BUG_ON_FOLIO(folio_test_active(folio), folio); 2054 2054 if (!folio_test_mlocked(folio)) { 2055 2055 int type = folio_is_file_lru(folio);