nc/platform/linux-types/linux/swap.rs
1// Copyright (c) 2020 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5//! From `include/linux/swap.h`
6
7/// set if swap priority specified
8pub const SWAP_FLAG_PREFER: i32 = 0x8000;
9pub const SWAP_FLAG_PRIO_MASK: i32 = 0x7fff;
10pub const SWAP_FLAG_PRIO_SHIFT: i32 = 0;
11/// enable discard for swap
12pub const SWAP_FLAG_DISCARD: i32 = 0x10000;
13/// discard swap area at swapon-time
14pub const SWAP_FLAG_DISCARD_ONCE: i32 = 0x20000;
15/// discard page-clusters after use
16pub const SWAP_FLAG_DISCARD_PAGES: i32 = 0x40000;
17
18pub const SWAP_FLAGS_VALID: i32 = SWAP_FLAG_PRIO_MASK
19 | SWAP_FLAG_PREFER
20 | SWAP_FLAG_DISCARD
21 | SWAP_FLAG_DISCARD_ONCE
22 | SWAP_FLAG_DISCARD_PAGES;
23pub const SWAP_BATCH: i32 = 64;
24
25/// `MAX_SWAPFILES` defines the maximum number of swaptypes: things which can
26/// be swapped to.
27///
28/// The swap type and the offset into that swap type are encoded into pte's and
29/// into `pgoff_t's` in the swapcache.
30///
31/// Using five bits for the type means that the maximum number of swapcache pages
32/// is 27 bits on `32-bit-pgoff_t` architectures.
33///
34/// And that assumes that the architecture packs the type/offset into the pte as 5/27 as well.
35pub const MAX_SWAPFILES_SHIFT: i32 = 5;
36
37pub const SWAP_CLUSTER_MAX: usize = 32;
38pub const COMPACT_CLUSTER_MAX: usize = SWAP_CLUSTER_MAX;
39
40/// Bit flag in `swap_map`.
41///
42/// Flag page is cached, in first `swap_map`
43pub const SWAP_HAS_CACHE: i32 = 0x40;
44/// Flag `swap_map` continuation for full count
45pub const COUNT_CONTINUED: i32 = 0x80;
46
47/// Special value in first `swap_map`.
48///
49/// Max count
50pub const SWAP_MAP_MAX: i32 = 0x3e;
51/// Note page is bad
52pub const SWAP_MAP_BAD: i32 = 0x3f;
53/// Owned by shmem/tmpfs
54pub const SWAP_MAP_SHMEM: i32 = 0xbf;
55
56/// Special value in each `swap_map` continuation.
57///
58/// Max count
59pub const SWAP_CONT_MAX: i32 = 0x7f;
60
61/// This cluster is free
62pub const CLUSTER_FLAG_FREE: i32 = 1;
63/// This cluster has no next cluster
64pub const CLUSTER_FLAG_NEXT_NULL: i32 = 2;
65/// This cluster is backing a transparent huge page
66pub const CLUSTER_FLAG_HUGE: i32 = 4;
67
68/// One swap address space for each 64M swap space
69pub const SWAP_ADDRESS_SPACE_SHIFT: i32 = 14;
70pub const SWAP_ADDRESS_SPACE_PAGES: i32 = 1 << SWAP_ADDRESS_SPACE_SHIFT;