Commit a4c366f0 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton

mm/swap: convert add_to_swap_cache() to take a folio

With all callers using folios, we can convert add_to_swap_cache() to take
a folio and use it throughout.

Link: https://lkml.kernel.org/r/20220902194653.1739778-13-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent a0d3374b
...@@ -1406,7 +1406,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) ...@@ -1406,7 +1406,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
if (list_empty(&info->swaplist)) if (list_empty(&info->swaplist))
list_add(&info->swaplist, &shmem_swaplist); list_add(&info->swaplist, &shmem_swaplist);
if (add_to_swap_cache(&folio->page, swap, if (add_to_swap_cache(folio, swap,
__GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN, __GFP_HIGH | __GFP_NOMEMALLOC | __GFP_NOWARN,
NULL) == 0) { NULL) == 0) {
spin_lock_irq(&info->lock); spin_lock_irq(&info->lock);
......
...@@ -32,7 +32,7 @@ extern struct address_space *swapper_spaces[]; ...@@ -32,7 +32,7 @@ extern struct address_space *swapper_spaces[];
void show_swap_cache_info(void); void show_swap_cache_info(void);
bool add_to_swap(struct folio *folio); bool add_to_swap(struct folio *folio);
void *get_shadow_from_swap_cache(swp_entry_t entry); void *get_shadow_from_swap_cache(swp_entry_t entry);
int add_to_swap_cache(struct page *page, swp_entry_t entry, int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
gfp_t gfp, void **shadowp); gfp_t gfp, void **shadowp);
void __delete_from_swap_cache(struct folio *folio, void __delete_from_swap_cache(struct folio *folio,
swp_entry_t entry, void *shadow); swp_entry_t entry, void *shadow);
...@@ -122,7 +122,7 @@ static inline void *get_shadow_from_swap_cache(swp_entry_t entry) ...@@ -122,7 +122,7 @@ static inline void *get_shadow_from_swap_cache(swp_entry_t entry)
return NULL; return NULL;
} }
static inline int add_to_swap_cache(struct page *page, swp_entry_t entry, static inline int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
gfp_t gfp_mask, void **shadowp) gfp_t gfp_mask, void **shadowp)
{ {
return -1; return -1;
......
...@@ -85,21 +85,21 @@ void *get_shadow_from_swap_cache(swp_entry_t entry) ...@@ -85,21 +85,21 @@ void *get_shadow_from_swap_cache(swp_entry_t entry)
* add_to_swap_cache resembles filemap_add_folio on swapper_space, * add_to_swap_cache resembles filemap_add_folio on swapper_space,
* but sets SwapCache flag and private instead of mapping and index. * but sets SwapCache flag and private instead of mapping and index.
*/ */
int add_to_swap_cache(struct page *page, swp_entry_t entry, int add_to_swap_cache(struct folio *folio, swp_entry_t entry,
gfp_t gfp, void **shadowp) gfp_t gfp, void **shadowp)
{ {
struct address_space *address_space = swap_address_space(entry); struct address_space *address_space = swap_address_space(entry);
pgoff_t idx = swp_offset(entry); pgoff_t idx = swp_offset(entry);
XA_STATE_ORDER(xas, &address_space->i_pages, idx, compound_order(page)); XA_STATE_ORDER(xas, &address_space->i_pages, idx, folio_order(folio));
unsigned long i, nr = thp_nr_pages(page); unsigned long i, nr = folio_nr_pages(folio);
void *old; void *old;
VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
VM_BUG_ON_PAGE(PageSwapCache(page), page); VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio);
VM_BUG_ON_PAGE(!PageSwapBacked(page), page); VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio);
page_ref_add(page, nr); folio_ref_add(folio, nr);
SetPageSwapCache(page); folio_set_swapcache(folio);
do { do {
xas_lock_irq(&xas); xas_lock_irq(&xas);
...@@ -107,19 +107,19 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry, ...@@ -107,19 +107,19 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
if (xas_error(&xas)) if (xas_error(&xas))
goto unlock; goto unlock;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
VM_BUG_ON_PAGE(xas.xa_index != idx + i, page); VM_BUG_ON_FOLIO(xas.xa_index != idx + i, folio);
old = xas_load(&xas); old = xas_load(&xas);
if (xa_is_value(old)) { if (xa_is_value(old)) {
if (shadowp) if (shadowp)
*shadowp = old; *shadowp = old;
} }
set_page_private(page + i, entry.val + i); set_page_private(folio_page(folio, i), entry.val + i);
xas_store(&xas, page); xas_store(&xas, folio);
xas_next(&xas); xas_next(&xas);
} }
address_space->nrpages += nr; address_space->nrpages += nr;
__mod_node_page_state(page_pgdat(page), NR_FILE_PAGES, nr); __node_stat_mod_folio(folio, NR_FILE_PAGES, nr);
__mod_lruvec_page_state(page, NR_SWAPCACHE, nr); __lruvec_stat_mod_folio(folio, NR_SWAPCACHE, nr);
unlock: unlock:
xas_unlock_irq(&xas); xas_unlock_irq(&xas);
} while (xas_nomem(&xas, gfp)); } while (xas_nomem(&xas, gfp));
...@@ -127,8 +127,8 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry, ...@@ -127,8 +127,8 @@ int add_to_swap_cache(struct page *page, swp_entry_t entry,
if (!xas_error(&xas)) if (!xas_error(&xas))
return 0; return 0;
ClearPageSwapCache(page); folio_clear_swapcache(folio);
page_ref_sub(page, nr); folio_ref_sub(folio, nr);
return xas_error(&xas); return xas_error(&xas);
} }
...@@ -194,7 +194,7 @@ bool add_to_swap(struct folio *folio) ...@@ -194,7 +194,7 @@ bool add_to_swap(struct folio *folio)
/* /*
* Add it to the swap cache. * Add it to the swap cache.
*/ */
err = add_to_swap_cache(&folio->page, entry, err = add_to_swap_cache(folio, entry,
__GFP_HIGH|__GFP_NOMEMALLOC|__GFP_NOWARN, NULL); __GFP_HIGH|__GFP_NOMEMALLOC|__GFP_NOWARN, NULL);
if (err) if (err)
/* /*
...@@ -484,7 +484,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask, ...@@ -484,7 +484,7 @@ struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
goto fail_unlock; goto fail_unlock;
/* May fail (-ENOMEM) if XArray node allocation failed. */ /* May fail (-ENOMEM) if XArray node allocation failed. */
if (add_to_swap_cache(&folio->page, entry, gfp_mask & GFP_RECLAIM_MASK, &shadow)) if (add_to_swap_cache(folio, entry, gfp_mask & GFP_RECLAIM_MASK, &shadow))
goto fail_unlock; goto fail_unlock;
mem_cgroup_swapin_uncharge_swap(entry); mem_cgroup_swapin_uncharge_swap(entry);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment