xref: /linux/include/linux/swap.h (revision 334fbe734e687404f346eba7d5d96ed2b44d35ab) !
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_SWAP_H
3 #define _LINUX_SWAP_H
4 
5 #include <linux/spinlock.h>
6 #include <linux/linkage.h>
7 #include <linux/mmzone.h>
8 #include <linux/list.h>
9 #include <linux/memcontrol.h>
10 #include <linux/sched.h>
11 #include <linux/node.h>
12 #include <linux/fs.h>
13 #include <linux/pagemap.h>
14 #include <linux/atomic.h>
15 #include <linux/page-flags.h>
16 #include <uapi/linux/mempolicy.h>
17 #include <asm/page.h>
18 
19 struct notifier_block;
20 
21 struct bio;
22 
23 #define SWAP_FLAG_PREFER	0x8000	/* set if swap priority specified */
24 #define SWAP_FLAG_PRIO_MASK	0x7fff
25 #define SWAP_FLAG_DISCARD	0x10000 /* enable discard for swap */
26 #define SWAP_FLAG_DISCARD_ONCE	0x20000 /* discard swap area at swapon-time */
27 #define SWAP_FLAG_DISCARD_PAGES 0x40000 /* discard page-clusters after use */
28 
29 #define SWAP_FLAGS_VALID	(SWAP_FLAG_PRIO_MASK | SWAP_FLAG_PREFER | \
30 				 SWAP_FLAG_DISCARD | SWAP_FLAG_DISCARD_ONCE | \
31 				 SWAP_FLAG_DISCARD_PAGES)
32 #define SWAP_BATCH 64
33 
34 static inline int current_is_kswapd(void)
35 {
36 	return current->flags & PF_KSWAPD;
37 }
38 
39 /*
40  * MAX_SWAPFILES defines the maximum number of swaptypes: things which can
41  * be swapped to.  The swap type and the offset into that swap type are
42  * encoded into pte's and into pgoff_t's in the swapcache.  Using five bits
43  * for the type means that the maximum number of swapcache pages is 27 bits
44  * on 32-bit-pgoff_t architectures.  And that assumes that the architecture packs
45  * the type/offset into the pte as 5/27 as well.
46  */
47 #define MAX_SWAPFILES_SHIFT	5
48 
49 /*
50  * Use some of the swap files numbers for other purposes. This
51  * is a convenient way to hook into the VM to trigger special
52  * actions on faults.
53  */
54 
55 /*
56  * PTE markers are used to persist information onto PTEs that otherwise
57  * should be a none pte.  As its name "PTE" hints, it should only be
58  * applied to the leaves of pgtables.
59  */
60 #define SWP_PTE_MARKER_NUM 1
61 #define SWP_PTE_MARKER     (MAX_SWAPFILES + SWP_HWPOISON_NUM + \
62 			    SWP_MIGRATION_NUM + SWP_DEVICE_NUM)
63 
64 /*
65  * Unaddressable device memory support. See include/linux/hmm.h and
66  * Documentation/mm/hmm.rst. Short description is we need struct pages for
67  * device memory that is unaddressable (inaccessible) by CPU, so that we can
68  * migrate part of a process memory to device memory.
69  *
70  * When a page is migrated from CPU to device, we set the CPU page table entry
71  * to a special SWP_DEVICE_{READ|WRITE} entry.
72  *
73  * When a page is mapped by the device for exclusive access we set the CPU page
74  * table entries to a special SWP_DEVICE_EXCLUSIVE entry.
75  */
76 #ifdef CONFIG_DEVICE_PRIVATE
77 #define SWP_DEVICE_NUM 3
78 #define SWP_DEVICE_WRITE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM)
79 #define SWP_DEVICE_READ (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+1)
80 #define SWP_DEVICE_EXCLUSIVE (MAX_SWAPFILES+SWP_HWPOISON_NUM+SWP_MIGRATION_NUM+2)
81 #else
82 #define SWP_DEVICE_NUM 0
83 #endif
84 
85 /*
86  * Page migration support.
87  *
88  * SWP_MIGRATION_READ_EXCLUSIVE is only applicable to anonymous pages and
89  * indicates that the referenced (part of) an anonymous page is exclusive to
90  * a single process. For SWP_MIGRATION_WRITE, that information is implicit:
91  * (part of) an anonymous page that are mapped writable are exclusive to a
92  * single process.
93  */
94 #ifdef CONFIG_MIGRATION
95 #define SWP_MIGRATION_NUM 3
96 #define SWP_MIGRATION_READ (MAX_SWAPFILES + SWP_HWPOISON_NUM)
97 #define SWP_MIGRATION_READ_EXCLUSIVE (MAX_SWAPFILES + SWP_HWPOISON_NUM + 1)
98 #define SWP_MIGRATION_WRITE (MAX_SWAPFILES + SWP_HWPOISON_NUM + 2)
99 #else
100 #define SWP_MIGRATION_NUM 0
101 #endif
102 
103 /*
104  * Handling of hardware poisoned pages with memory corruption.
105  */
106 #ifdef CONFIG_MEMORY_FAILURE
107 #define SWP_HWPOISON_NUM 1
108 #define SWP_HWPOISON		MAX_SWAPFILES
109 #else
110 #define SWP_HWPOISON_NUM 0
111 #endif
112 
113 #define MAX_SWAPFILES \
114 	((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
115 	SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
116 	SWP_PTE_MARKER_NUM)
117 
118 /*
119  * Magic header for a swap area. The first part of the union is
120  * what the swap magic looks like for the old (limited to 128MB)
121  * swap area format, the second part of the union adds - in the
122  * old reserved area - some extra information. Note that the first
123  * kilobyte is reserved for boot loader or disk label stuff...
124  *
125  * Having the magic at the end of the PAGE_SIZE makes detecting swap
126  * areas somewhat tricky on machines that support multiple page sizes.
127  * For 2.5 we'll probably want to move the magic to just beyond the
128  * bootbits...
129  */
130 union swap_header {
131 	struct {
132 		char reserved[PAGE_SIZE - 10];
133 		char magic[10];			/* SWAP-SPACE or SWAPSPACE2 */
134 	} magic;
135 	struct {
136 		char		bootbits[1024];	/* Space for disklabel etc. */
137 		__u32		version;
138 		__u32		last_page;
139 		__u32		nr_badpages;
140 		unsigned char	sws_uuid[16];
141 		unsigned char	sws_volume[16];
142 		__u32		padding[117];
143 		__u32		badpages[1];
144 	} info;
145 };
146 
147 /*
148  * current->reclaim_state points to one of these when a task is running
149  * memory reclaim
150  */
151 struct reclaim_state {
152 	/* pages reclaimed outside of LRU-based reclaim */
153 	unsigned long reclaimed;
154 #ifdef CONFIG_LRU_GEN
155 	/* per-thread mm walk data */
156 	struct lru_gen_mm_walk *mm_walk;
157 #endif
158 };
159 
160 /*
161  * mm_account_reclaimed_pages(): account reclaimed pages outside of LRU-based
162  * reclaim
163  * @pages: number of pages reclaimed
164  *
165  * If the current process is undergoing a reclaim operation, increment the
166  * number of reclaimed pages by @pages.
167  */
168 static inline void mm_account_reclaimed_pages(unsigned long pages)
169 {
170 	if (current->reclaim_state)
171 		current->reclaim_state->reclaimed += pages;
172 }
173 
174 #ifdef __KERNEL__
175 
176 struct address_space;
177 struct sysinfo;
178 struct writeback_control;
179 struct zone;
180 
181 /*
182  * A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of
183  * disk blocks.  A rbtree of swap extents maps the entire swapfile (Where the
184  * term `swapfile' refers to either a blockdevice or an IS_REG file). Apart
185  * from setup, they're handled identically.
186  *
187  * We always assume that blocks are of size PAGE_SIZE.
188  */
189 struct swap_extent {
190 	struct rb_node rb_node;
191 	pgoff_t start_page;
192 	pgoff_t nr_pages;
193 	sector_t start_block;
194 };
195 
196 /*
197  * Max bad pages in the new format..
198  */
199 #define MAX_SWAP_BADPAGES \
200 	((offsetof(union swap_header, magic.magic) - \
201 	  offsetof(union swap_header, info.badpages)) / sizeof(int))
202 
203 enum {
204 	SWP_USED	= (1 << 0),	/* is slot in swap_info[] used? */
205 	SWP_WRITEOK	= (1 << 1),	/* ok to write to this swap?	*/
206 	SWP_DISCARDABLE = (1 << 2),	/* blkdev support discard */
207 	SWP_DISCARDING	= (1 << 3),	/* now discarding a free cluster */
208 	SWP_SOLIDSTATE	= (1 << 4),	/* blkdev seeks are cheap */
209 	SWP_BLKDEV	= (1 << 6),	/* its a block device */
210 	SWP_ACTIVATED	= (1 << 7),	/* set after swap_activate success */
211 	SWP_FS_OPS	= (1 << 8),	/* swapfile operations go through fs */
212 	SWP_AREA_DISCARD = (1 << 9),	/* single-time swap area discards */
213 	SWP_PAGE_DISCARD = (1 << 10),	/* freed swap page-cluster discards */
214 	SWP_STABLE_WRITES = (1 << 11),	/* no overwrite PG_writeback pages */
215 	SWP_SYNCHRONOUS_IO = (1 << 12),	/* synchronous IO is efficient */
216 					/* add others here before... */
217 };
218 
219 #define SWAP_CLUSTER_MAX 32UL
220 #define SWAP_CLUSTER_MAX_SKIPPED (SWAP_CLUSTER_MAX << 10)
221 #define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX
222 
223 /*
224  * The first page in the swap file is the swap header, which is always marked
225  * bad to prevent it from being allocated as an entry. This also prevents the
226  * cluster to which it belongs being marked free. Therefore 0 is safe to use as
227  * a sentinel to indicate an entry is not valid.
228  */
229 #define SWAP_ENTRY_INVALID	0
230 
231 #ifdef CONFIG_THP_SWAP
232 #define SWAP_NR_ORDERS		(PMD_ORDER + 1)
233 #else
234 #define SWAP_NR_ORDERS		1
235 #endif
236 
237 /*
238  * We keep using same cluster for rotational device so IO will be sequential.
239  * The purpose is to optimize SWAP throughput on these device.
240  */
241 struct swap_sequential_cluster {
242 	unsigned int next[SWAP_NR_ORDERS]; /* Likely next allocation offset */
243 };
244 
245 /*
246  * The in-memory structure used to track swap areas.
247  */
248 struct swap_info_struct {
249 	struct percpu_ref users;	/* indicate and keep swap device valid. */
250 	unsigned long	flags;		/* SWP_USED etc: see above */
251 	signed short	prio;		/* swap priority of this type */
252 	struct plist_node list;		/* entry in swap_active_head */
253 	signed char	type;		/* strange name for an index */
254 	unsigned int	max;		/* size of this swap device */
255 	unsigned long *zeromap;		/* kvmalloc'ed bitmap to track zero pages */
256 	struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */
257 	struct list_head free_clusters; /* free clusters list */
258 	struct list_head full_clusters; /* full clusters list */
259 	struct list_head nonfull_clusters[SWAP_NR_ORDERS];
260 					/* list of cluster that contains at least one free slot */
261 	struct list_head frag_clusters[SWAP_NR_ORDERS];
262 					/* list of cluster that are fragmented or contented */
263 	unsigned int pages;		/* total of usable pages of swap */
264 	atomic_long_t inuse_pages;	/* number of those currently in use */
265 	struct swap_sequential_cluster *global_cluster; /* Use one global cluster for rotating device */
266 	spinlock_t global_cluster_lock;	/* Serialize usage of global cluster */
267 	struct rb_root swap_extent_root;/* root of the swap extent rbtree */
268 	struct block_device *bdev;	/* swap device or bdev of swap file */
269 	struct file *swap_file;		/* seldom referenced */
270 	struct completion comp;		/* seldom referenced */
271 	spinlock_t lock;		/*
272 					 * protect map scan related fields like
273 					 * inuse_pages and all cluster lists.
274 					 * Other fields are only changed
275 					 * at swapon/swapoff, so are protected
276 					 * by swap_lock. changing flags need
277 					 * hold this lock and swap_lock. If
278 					 * both locks need hold, hold swap_lock
279 					 * first.
280 					 */
281 	struct work_struct discard_work; /* discard worker */
282 	struct work_struct reclaim_work; /* reclaim worker */
283 	struct list_head discard_clusters; /* discard clusters list */
284 	struct plist_node avail_list;   /* entry in swap_avail_head */
285 };
286 
287 static inline swp_entry_t page_swap_entry(struct page *page)
288 {
289 	struct folio *folio = page_folio(page);
290 	swp_entry_t entry = folio->swap;
291 
292 	entry.val += folio_page_idx(folio, page);
293 	return entry;
294 }
295 
296 /* linux/mm/workingset.c */
297 bool workingset_test_recent(void *shadow, bool file, bool *workingset,
298 				bool flush);
299 void workingset_age_nonresident(struct lruvec *lruvec, unsigned long nr_pages);
300 void *workingset_eviction(struct folio *folio, struct mem_cgroup *target_memcg);
301 void workingset_refault(struct folio *folio, void *shadow);
302 void workingset_activation(struct folio *folio);
303 
304 /* linux/mm/page_alloc.c */
305 extern unsigned long totalreserve_pages;
306 
307 /* Definition of global_zone_page_state not available yet */
308 #define nr_free_pages() global_zone_page_state(NR_FREE_PAGES)
309 
310 
311 /* linux/mm/swap.c */
312 void lru_note_cost_unlock_irq(struct lruvec *lruvec, bool file,
313 		unsigned int nr_io, unsigned int nr_rotated)
314 		__releases(lruvec->lru_lock);
315 void lru_note_cost_refault(struct folio *);
316 void folio_add_lru(struct folio *);
317 void folio_add_lru_vma(struct folio *, struct vm_area_struct *);
318 void mark_page_accessed(struct page *);
319 void folio_mark_accessed(struct folio *);
320 
321 static inline bool folio_may_be_lru_cached(struct folio *folio)
322 {
323 	/*
324 	 * Holding PMD-sized folios in per-CPU LRU cache unbalances accounting.
325 	 * Holding small numbers of low-order mTHP folios in per-CPU LRU cache
326 	 * will be sensible, but nobody has implemented and tested that yet.
327 	 */
328 	return !folio_test_large(folio);
329 }
330 
331 extern atomic_t lru_disable_count;
332 
333 static inline bool lru_cache_disabled(void)
334 {
335 	return atomic_read(&lru_disable_count);
336 }
337 
338 static inline void lru_cache_enable(void)
339 {
340 	atomic_dec(&lru_disable_count);
341 }
342 
343 extern void lru_cache_disable(void);
344 extern void lru_add_drain(void);
345 extern void lru_add_drain_cpu(int cpu);
346 extern void lru_add_drain_cpu_zone(struct zone *zone);
347 extern void lru_add_drain_all(void);
348 void folio_deactivate(struct folio *folio);
349 void folio_mark_lazyfree(struct folio *folio);
350 extern void swap_setup(void);
351 
352 /* linux/mm/vmscan.c */
353 extern unsigned long zone_reclaimable_pages(struct zone *zone);
354 extern unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
355 					gfp_t gfp_mask, nodemask_t *mask);
356 
357 #define MEMCG_RECLAIM_MAY_SWAP (1 << 1)
358 #define MEMCG_RECLAIM_PROACTIVE (1 << 2)
359 #define MIN_SWAPPINESS 0
360 #define MAX_SWAPPINESS 200
361 
362 /* Just reclaim from anon folios in proactive memory reclaim */
363 #define SWAPPINESS_ANON_ONLY (MAX_SWAPPINESS + 1)
364 
365 extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,
366 						  unsigned long nr_pages,
367 						  gfp_t gfp_mask,
368 						  unsigned int reclaim_options,
369 						  int *swappiness);
370 extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem,
371 						gfp_t gfp_mask, bool noswap,
372 						pg_data_t *pgdat,
373 						unsigned long *nr_scanned);
374 extern unsigned long shrink_all_memory(unsigned long nr_pages);
375 extern int vm_swappiness;
376 long remove_mapping(struct address_space *mapping, struct folio *folio);
377 
378 #if defined(CONFIG_SYSFS) && defined(CONFIG_NUMA)
379 extern int reclaim_register_node(struct node *node);
380 extern void reclaim_unregister_node(struct node *node);
381 
382 #else
383 
384 static inline int reclaim_register_node(struct node *node)
385 {
386 	return 0;
387 }
388 
389 static inline void reclaim_unregister_node(struct node *node)
390 {
391 }
392 #endif /* CONFIG_SYSFS && CONFIG_NUMA */
393 
394 #ifdef CONFIG_NUMA
395 extern int sysctl_min_unmapped_ratio;
396 extern int sysctl_min_slab_ratio;
397 #endif
398 
399 void check_move_unevictable_folios(struct folio_batch *fbatch);
400 
401 extern void __meminit kswapd_run(int nid);
402 extern void __meminit kswapd_stop(int nid);
403 
404 #ifdef CONFIG_SWAP
405 
406 int add_swap_extent(struct swap_info_struct *sis, unsigned long start_page,
407 		unsigned long nr_pages, sector_t start_block);
408 int generic_swapfile_activate(struct swap_info_struct *, struct file *,
409 		sector_t *);
410 
411 static inline unsigned long total_swapcache_pages(void)
412 {
413 	return global_node_page_state(NR_SWAPCACHE);
414 }
415 
416 void free_swap_cache(struct folio *folio);
417 void free_folio_and_swap_cache(struct folio *folio);
418 void free_pages_and_swap_cache(struct encoded_page **, int);
419 /* linux/mm/swapfile.c */
420 extern atomic_long_t nr_swap_pages;
421 extern long total_swap_pages;
422 extern atomic_t nr_rotate_swap;
423 
424 /* Swap 50% full? Release swapcache more aggressively.. */
425 static inline bool vm_swap_full(void)
426 {
427 	return atomic_long_read(&nr_swap_pages) * 2 < total_swap_pages;
428 }
429 
430 static inline long get_nr_swap_pages(void)
431 {
432 	return atomic_long_read(&nr_swap_pages);
433 }
434 
435 extern void si_swapinfo(struct sysinfo *);
436 int swap_type_of(dev_t device, sector_t offset);
437 int find_first_swap(dev_t *device);
438 extern unsigned int count_swap_pages(int, int);
439 extern sector_t swapdev_block(int, pgoff_t);
440 extern int __swap_count(swp_entry_t entry);
441 extern bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry);
442 extern int swp_swapcount(swp_entry_t entry);
443 struct backing_dev_info;
444 extern struct swap_info_struct *get_swap_device(swp_entry_t entry);
445 sector_t swap_folio_sector(struct folio *folio);
446 
447 /*
448  * If there is an existing swap slot reference (swap entry) and the caller
449  * guarantees that there is no race modification of it (e.g., PTL
450  * protecting the swap entry in page table; shmem's cmpxchg protects t
451  * he swap entry in shmem mapping), these two helpers below can be used
452  * to put/dup the entries directly.
453  *
454  * All entries must be allocated by folio_alloc_swap(). And they must have
455  * a swap count > 1. See comments of folio_*_swap helpers for more info.
456  */
457 int swap_dup_entry_direct(swp_entry_t entry);
458 void swap_put_entries_direct(swp_entry_t entry, int nr);
459 
460 /*
461  * folio_free_swap tries to free the swap entries pinned by a swap cache
462  * folio, it has to be here to be called by other components.
463  */
464 bool folio_free_swap(struct folio *folio);
465 
466 /* Allocate / free (hibernation) exclusive entries */
467 swp_entry_t swap_alloc_hibernation_slot(int type);
468 void swap_free_hibernation_slot(swp_entry_t entry);
469 
470 static inline void put_swap_device(struct swap_info_struct *si)
471 {
472 	percpu_ref_put(&si->users);
473 }
474 
475 #else /* CONFIG_SWAP */
476 static inline struct swap_info_struct *get_swap_device(swp_entry_t entry)
477 {
478 	return NULL;
479 }
480 
481 static inline void put_swap_device(struct swap_info_struct *si)
482 {
483 }
484 
485 #define get_nr_swap_pages()			0L
486 #define total_swap_pages			0L
487 #define total_swapcache_pages()			0UL
488 #define vm_swap_full()				0
489 
490 #define si_swapinfo(val) \
491 	do { (val)->freeswap = (val)->totalswap = 0; } while (0)
492 #define free_folio_and_swap_cache(folio) \
493 	folio_put(folio)
494 #define free_pages_and_swap_cache(pages, nr) \
495 	release_pages((pages), (nr));
496 
497 static inline void free_swap_cache(struct folio *folio)
498 {
499 }
500 
501 static inline int swap_dup_entry_direct(swp_entry_t ent)
502 {
503 	return 0;
504 }
505 
506 static inline void swap_put_entries_direct(swp_entry_t ent, int nr)
507 {
508 }
509 
510 static inline int __swap_count(swp_entry_t entry)
511 {
512 	return 0;
513 }
514 
515 static inline bool swap_entry_swapped(struct swap_info_struct *si, swp_entry_t entry)
516 {
517 	return false;
518 }
519 
520 static inline int swp_swapcount(swp_entry_t entry)
521 {
522 	return 0;
523 }
524 
525 static inline bool folio_free_swap(struct folio *folio)
526 {
527 	return false;
528 }
529 
530 static inline int add_swap_extent(struct swap_info_struct *sis,
531 				  unsigned long start_page,
532 				  unsigned long nr_pages, sector_t start_block)
533 {
534 	return -EINVAL;
535 }
536 #endif /* CONFIG_SWAP */
537 #ifdef CONFIG_MEMCG
538 static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg)
539 {
540 	/* Cgroup2 doesn't have per-cgroup swappiness */
541 	if (cgroup_subsys_on_dfl(memory_cgrp_subsys))
542 		return READ_ONCE(vm_swappiness);
543 
544 	/* root ? */
545 	if (mem_cgroup_disabled() || mem_cgroup_is_root(memcg))
546 		return READ_ONCE(vm_swappiness);
547 
548 	return READ_ONCE(memcg->swappiness);
549 }
550 #else
551 static inline int mem_cgroup_swappiness(struct mem_cgroup *mem)
552 {
553 	return READ_ONCE(vm_swappiness);
554 }
555 #endif
556 
557 #if defined(CONFIG_SWAP) && defined(CONFIG_MEMCG) && defined(CONFIG_BLK_CGROUP)
558 void __folio_throttle_swaprate(struct folio *folio, gfp_t gfp);
559 static inline void folio_throttle_swaprate(struct folio *folio, gfp_t gfp)
560 {
561 	if (mem_cgroup_disabled())
562 		return;
563 	__folio_throttle_swaprate(folio, gfp);
564 }
565 #else
566 static inline void folio_throttle_swaprate(struct folio *folio, gfp_t gfp)
567 {
568 }
569 #endif
570 
571 #if defined(CONFIG_MEMCG) && defined(CONFIG_SWAP)
572 int __mem_cgroup_try_charge_swap(struct folio *folio, swp_entry_t entry);
573 static inline int mem_cgroup_try_charge_swap(struct folio *folio,
574 		swp_entry_t entry)
575 {
576 	if (mem_cgroup_disabled())
577 		return 0;
578 	return __mem_cgroup_try_charge_swap(folio, entry);
579 }
580 
581 extern void __mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages);
582 static inline void mem_cgroup_uncharge_swap(swp_entry_t entry, unsigned int nr_pages)
583 {
584 	if (mem_cgroup_disabled())
585 		return;
586 	__mem_cgroup_uncharge_swap(entry, nr_pages);
587 }
588 
589 extern long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg);
590 extern bool mem_cgroup_swap_full(struct folio *folio);
591 #else
592 static inline int mem_cgroup_try_charge_swap(struct folio *folio,
593 					     swp_entry_t entry)
594 {
595 	return 0;
596 }
597 
598 static inline void mem_cgroup_uncharge_swap(swp_entry_t entry,
599 					    unsigned int nr_pages)
600 {
601 }
602 
603 static inline long mem_cgroup_get_nr_swap_pages(struct mem_cgroup *memcg)
604 {
605 	return get_nr_swap_pages();
606 }
607 
608 static inline bool mem_cgroup_swap_full(struct folio *folio)
609 {
610 	return vm_swap_full();
611 }
612 #endif
613 
614 #endif /* __KERNEL__*/
615 #endif /* _LINUX_SWAP_H */
616