include/linux/swap.h
Source file repositories/reference/linux-study-clean/include/linux/swap.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/swap.h- Extension
.h- Size
- 20167 bytes
- Lines
- 637
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/spinlock.hlinux/linkage.hlinux/mmzone.hlinux/list.hlinux/memcontrol.hlinux/sched.hlinux/node.hlinux/fs.hlinux/pagemap.hlinux/atomic.hlinux/page-flags.huapi/linux/mempolicy.hasm/page.h
Detected Declarations
struct notifier_blockstruct biostruct reclaim_statestruct address_spacestruct sysinfostruct writeback_controlstruct zonestruct swap_extentstruct swap_sequential_clusterstruct swap_info_structstruct backing_dev_infofunction current_is_kswapdfunction mm_account_reclaimed_pagesfunction page_swap_entryfunction folio_may_be_lru_cachedfunction lru_cache_disabledfunction lru_cache_enablefunction reclaim_register_nodefunction reclaim_unregister_nodefunction total_swapcache_pagesfunction vm_swap_fullfunction get_nr_swap_pagesfunction put_swap_devicefunction put_swap_devicefunction free_swap_cachefunction swap_put_entries_directfunction swap_entry_swappedfunction swp_swapcountfunction folio_free_swapfunction add_swap_extentfunction mem_cgroup_swappinessfunction mem_cgroup_swappinessfunction folio_throttle_swapratefunction folio_throttle_swapratefunction mem_cgroup_try_charge_swapfunction mem_cgroup_uncharge_swapfunction mem_cgroup_try_charge_swapfunction mem_cgroup_uncharge_swapfunction mem_cgroup_swap_full
Annotated Snippet
struct reclaim_state {
/* pages reclaimed outside of LRU-based reclaim */
unsigned long reclaimed;
#ifdef CONFIG_LRU_GEN
/* per-thread mm walk data */
struct lru_gen_mm_walk *mm_walk;
#endif
};
/*
* mm_account_reclaimed_pages(): account reclaimed pages outside of LRU-based
* reclaim
* @pages: number of pages reclaimed
*
* If the current process is undergoing a reclaim operation, increment the
* number of reclaimed pages by @pages.
*/
static inline void mm_account_reclaimed_pages(unsigned long pages)
{
if (current->reclaim_state)
current->reclaim_state->reclaimed += pages;
}
#ifdef __KERNEL__
struct address_space;
struct sysinfo;
struct writeback_control;
struct zone;
/*
* A swap extent maps a range of a swapfile's PAGE_SIZE pages onto a range of
* disk blocks. A rbtree of swap extents maps the entire swapfile (Where the
* term `swapfile' refers to either a blockdevice or an IS_REG file). Apart
* from setup, they're handled identically.
*
* We always assume that blocks are of size PAGE_SIZE.
*/
struct swap_extent {
struct rb_node rb_node;
pgoff_t start_page;
pgoff_t nr_pages;
sector_t start_block;
};
/*
* Max bad pages in the new format..
*/
#define MAX_SWAP_BADPAGES \
((offsetof(union swap_header, magic.magic) - \
offsetof(union swap_header, info.badpages)) / sizeof(int))
enum {
SWP_USED = (1 << 0), /* is slot in swap_info[] used? */
SWP_WRITEOK = (1 << 1), /* ok to write to this swap? */
SWP_DISCARDABLE = (1 << 2), /* blkdev support discard */
SWP_DISCARDING = (1 << 3), /* now discarding a free cluster */
SWP_SOLIDSTATE = (1 << 4), /* blkdev seeks are cheap */
SWP_BLKDEV = (1 << 6), /* its a block device */
SWP_ACTIVATED = (1 << 7), /* set after swap_activate success */
SWP_FS_OPS = (1 << 8), /* swapfile operations go through fs */
SWP_AREA_DISCARD = (1 << 9), /* single-time swap area discards */
SWP_PAGE_DISCARD = (1 << 10), /* freed swap page-cluster discards */
SWP_STABLE_WRITES = (1 << 11), /* no overwrite PG_writeback pages */
SWP_SYNCHRONOUS_IO = (1 << 12), /* synchronous IO is efficient */
SWP_HIBERNATION = (1 << 13), /* pinned for hibernation */
/* add others here before... */
};
#define SWAP_CLUSTER_MAX 32UL
#define SWAP_CLUSTER_MAX_SKIPPED (SWAP_CLUSTER_MAX << 10)
#define COMPACT_CLUSTER_MAX SWAP_CLUSTER_MAX
/*
* The first page in the swap file is the swap header, which is always marked
* bad to prevent it from being allocated as an entry. This also prevents the
* cluster to which it belongs being marked free. Therefore 0 is safe to use as
* a sentinel to indicate an entry is not valid.
*/
#define SWAP_ENTRY_INVALID 0
#ifdef CONFIG_THP_SWAP
#define SWAP_NR_ORDERS (PMD_ORDER + 1)
#else
#define SWAP_NR_ORDERS 1
#endif
/*
* We keep using same cluster for rotational device so IO will be sequential.
* The purpose is to optimize SWAP throughput on these device.
Annotation
- Immediate include surface: `linux/spinlock.h`, `linux/linkage.h`, `linux/mmzone.h`, `linux/list.h`, `linux/memcontrol.h`, `linux/sched.h`, `linux/node.h`, `linux/fs.h`.
- Detected declarations: `struct notifier_block`, `struct bio`, `struct reclaim_state`, `struct address_space`, `struct sysinfo`, `struct writeback_control`, `struct zone`, `struct swap_extent`, `struct swap_sequential_cluster`, `struct swap_info_struct`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.