swap_state.c (cfeed8ffe55b37fa10286aaaa1369da00cb88440) swap_state.c (3d2c908768877714a354ee6d7bf93e801400d5e2)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/swap_state.c
4 *
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
6 * Swap reorganised 29.12.95, Stephen Tweedie
7 *
8 * Rewritten to use page cache, (C) 1998 Stephen Tweedie

--- 86 unchanged lines hidden (view full) ---

95 xas_set_update(&xas, workingset_update_node);
96
97 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
98 VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio);
99 VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio);
100
101 folio_ref_add(folio, nr);
102 folio_set_swapcache(folio);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/swap_state.c
4 *
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
6 * Swap reorganised 29.12.95, Stephen Tweedie
7 *
8 * Rewritten to use page cache, (C) 1998 Stephen Tweedie

--- 86 unchanged lines hidden (view full) ---

95 xas_set_update(&xas, workingset_update_node);
96
97 VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
98 VM_BUG_ON_FOLIO(folio_test_swapcache(folio), folio);
99 VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio);
100
101 folio_ref_add(folio, nr);
102 folio_set_swapcache(folio);
103 folio_set_swap_entry(folio, entry);
103 folio->swap = entry;
104
105 do {
106 xas_lock_irq(&xas);
107 xas_create_range(&xas);
108 if (xas_error(&xas))
109 goto unlock;
110 for (i = 0; i < nr; i++) {
111 VM_BUG_ON_FOLIO(xas.xa_index != idx + i, folio);

--- 39 unchanged lines hidden (view full) ---

151 VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio);
152 VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio);
153
154 for (i = 0; i < nr; i++) {
155 void *entry = xas_store(&xas, shadow);
156 VM_BUG_ON_PAGE(entry != folio, entry);
157 xas_next(&xas);
158 }
104
105 do {
106 xas_lock_irq(&xas);
107 xas_create_range(&xas);
108 if (xas_error(&xas))
109 goto unlock;
110 for (i = 0; i < nr; i++) {
111 VM_BUG_ON_FOLIO(xas.xa_index != idx + i, folio);

--- 39 unchanged lines hidden (view full) ---

151 VM_BUG_ON_FOLIO(!folio_test_swapcache(folio), folio);
152 VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio);
153
154 for (i = 0; i < nr; i++) {
155 void *entry = xas_store(&xas, shadow);
156 VM_BUG_ON_PAGE(entry != folio, entry);
157 xas_next(&xas);
158 }
159 entry.val = 0;
160 folio_set_swap_entry(folio, entry);
159 folio->swap.val = 0;
161 folio_clear_swapcache(folio);
162 address_space->nrpages -= nr;
163 __node_stat_mod_folio(folio, NR_FILE_PAGES, -nr);
164 __lruvec_stat_mod_folio(folio, NR_SWAPCACHE, -nr);
165}
166
167/**
168 * add_to_swap - allocate swap space for a folio

--- 59 unchanged lines hidden (view full) ---

228/*
229 * This must be called only on folios that have
230 * been verified to be in the swap cache and locked.
231 * It will never put the folio into the free list,
232 * the caller has a reference on the folio.
233 */
234void delete_from_swap_cache(struct folio *folio)
235{
160 folio_clear_swapcache(folio);
161 address_space->nrpages -= nr;
162 __node_stat_mod_folio(folio, NR_FILE_PAGES, -nr);
163 __lruvec_stat_mod_folio(folio, NR_SWAPCACHE, -nr);
164}
165
166/**
167 * add_to_swap - allocate swap space for a folio

--- 59 unchanged lines hidden (view full) ---

227/*
228 * This must be called only on folios that have
229 * been verified to be in the swap cache and locked.
230 * It will never put the folio into the free list,
231 * the caller has a reference on the folio.
232 */
233void delete_from_swap_cache(struct folio *folio)
234{
236 swp_entry_t entry = folio_swap_entry(folio);
235 swp_entry_t entry = folio->swap;
237 struct address_space *address_space = swap_address_space(entry);
238
239 xa_lock_irq(&address_space->i_pages);
240 __delete_from_swap_cache(folio, entry, NULL);
241 xa_unlock_irq(&address_space->i_pages);
242
243 put_swap_folio(folio, entry);
244 folio_ref_sub(folio, folio_nr_pages(folio));

--- 670 unchanged lines hidden ---
236 struct address_space *address_space = swap_address_space(entry);
237
238 xa_lock_irq(&address_space->i_pages);
239 __delete_from_swap_cache(folio, entry, NULL);
240 xa_unlock_irq(&address_space->i_pages);
241
242 put_swap_folio(folio, entry);
243 folio_ref_sub(folio, folio_nr_pages(folio));

--- 670 unchanged lines hidden ---