|
1 | 1 | use crate::{process::Pfn, FileWrapper, ProcResult};
|
2 | 2 |
|
3 |
| -use bitflags::bitflags; |
4 | 3 | use std::{
|
5 | 4 | io::{BufReader, Read, Seek, SeekFrom},
|
6 | 5 | mem::size_of,
|
7 | 6 | path::Path,
|
8 | 7 | };
|
9 | 8 |
|
10 |
| -#[cfg(feature = "serde1")] |
11 |
| -use serde::{Deserialize, Serialize}; |
12 |
| - |
13 |
| -//const fn genmask(high: usize, low: usize) -> u64 { |
14 |
| -// let mask_bits = size_of::<u64>() * 8; |
15 |
| -// (!0 - (1 << low) + 1) & (!0 >> (mask_bits - 1 - high)) |
16 |
| -//} |
17 |
| - |
18 |
| -bitflags! { |
19 |
| - /// Represents the fields and flags in a page table entry for a memory page. |
20 |
| - #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))] |
21 |
| - #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, PartialOrd, Ord)] |
22 |
| - pub struct PhysicalPageFlags: u64 { |
23 |
| - /// The page is being locked for exclusive access, e.g. by undergoing read/write IO |
24 |
| - const LOCKED = 1 << 0; |
25 |
| - /// IO error occurred |
26 |
| - const ERROR = 1 << 1; |
27 |
| - /// The page has been referenced since last LRU list enqueue/requeue |
28 |
| - const REFERENCED = 1 << 2; |
29 |
| - /// The page has up-to-date data. ie. for file backed page: (in-memory data revision >= on-disk one) |
30 |
| - const UPTODATE = 1 << 3; |
31 |
| - /// The page has been written to, hence contains new data. i.e. for file backed page: (in-memory data revision > on-disk one) |
32 |
| - const DIRTY = 1 << 4; |
33 |
| - /// The page is in one of the LRU lists |
34 |
| - const LRU = 1 << 5; |
35 |
| - /// The page is in the active LRU list |
36 |
| - const ACTIVE = 1 << 6; |
37 |
| - /// The page is managed by the SLAB/SLOB/SLUB/SLQB kernel memory allocator. When compound page is used, SLUB/SLQB will only set this flag on the head page; SLOB will not flag it at all |
38 |
| - const SLAB = 1 << 7; |
39 |
| - /// The page is being synced to disk |
40 |
| - const WRITEBACK = 1 << 8; |
41 |
| - /// The page will be reclaimed soon after its pageout IO completed |
42 |
| - const RECLAIM = 1 << 9; |
43 |
| - /// A free memory block managed by the buddy system allocator. The buddy system organizes free memory in blocks of various orders. An order N block has 2^N physically contiguous pages, with the BUDDY flag set for and _only_ for the first page |
44 |
| - const BUDDY = 1 << 10; |
45 |
| - /// A memory mapped page |
46 |
| - const MMAP = 1 << 11; |
47 |
| - /// A memory mapped page that is not part of a file |
48 |
| - const ANON = 1 << 12; |
49 |
| - /// The page is mapped to swap space, i.e. has an associated swap entry |
50 |
| - const SWAPCACHE = 1 << 13; |
51 |
| - /// The page is backed by swap/RAM |
52 |
| - const SWAPBACKED = 1 << 14; |
53 |
| - /// A compound page with order N consists of 2^N physically contiguous pages. A compound page with order 2 takes the form of “HTTT”, where H donates its head page and T donates its tail page(s). The major consumers of compound pages are hugeTLB pages (<https://www.kernel.org/doc/html/latest/admin-guide/mm/hugetlbpage.html#hugetlbpage>), the SLUB etc. memory allocators and various device drivers. However in this interface, only huge/giga pages are made visible to end users |
54 |
| - const COMPOUND_HEAD = 1 << 15; |
55 |
| - /// A compound page tail (see description above) |
56 |
| - const COMPOUND_TAIL = 1 << 16; |
57 |
| - /// This is an integral part of a HugeTLB page |
58 |
| - const HUGE = 1 << 17; |
59 |
| - /// The page is in the unevictable (non-)LRU list It is somehow pinned and not a candidate for LRU page reclaims, e.g. ramfs pages, shmctl(SHM_LOCK) and mlock() memory segments |
60 |
| - const UNEVICTABLE = 1 << 18; |
61 |
| - /// Hardware detected memory corruption on this page: don’t touch the data! |
62 |
| - const HWPOISON = 1 << 19; |
63 |
| - /// No page frame exists at the requested address |
64 |
| - const NOPAGE = 1 << 20; |
65 |
| - /// Identical memory pages dynamically shared between one or more processes |
66 |
| - const KSM = 1 << 21; |
67 |
| - /// Contiguous pages which construct transparent hugepages |
68 |
| - const THP = 1 << 22; |
69 |
| - /// The page is logically offline |
70 |
| - const OFFLINE = 1 << 23; |
71 |
| - /// Zero page for pfn_zero or huge_zero page |
72 |
| - const ZERO_PAGE = 1 << 24; |
73 |
| - /// The page has not been accessed since it was marked idle (see <https://www.kernel.org/doc/html/latest/admin-guide/mm/idle_page_tracking.html#idle-page-tracking>). Note that this flag may be stale in case the page was accessed via a PTE. To make sure the flag is up-to-date one has to read /sys/kernel/mm/page_idle/bitmap first |
74 |
| - const IDLE = 1 << 25; |
75 |
| - /// The page is in use as a page table |
76 |
| - const PGTABLE = 1 << 26; |
77 |
| - |
78 |
| - } |
79 |
| -} |
80 |
| - |
81 |
| -impl PhysicalPageFlags { |
82 |
| - pub(crate) fn parse_info(info: u64) -> Self { |
83 |
| - PhysicalPageFlags::from_bits_truncate(info) |
84 |
| - } |
85 |
| -} |
| 9 | +pub use procfs_core::PhysicalPageFlags; |
86 | 10 |
|
87 | 11 | /// Parse physical memory flags accessing `/proc/kpageflags`.
|
88 | 12 | ///
|
|
0 commit comments