]> git.itanic.dy.fi Git - scan-pagemap/blob - pagemap.h
Compact pageframe structure
[scan-pagemap] / pagemap.h
1 #ifndef _PAGEMAP_H
2 #define _PAGEMAP_H
3
4 #include "utils.h"
5 #include "list.h"
6 #include "bintree.h"
7
8 #define PAGE_SHIFT      12
9 #define PAGE_SIZE       (1 << PAGE_SHIFT)
10
11 struct maps;
12
13 struct maps_list {
14         struct maps *map;
15         struct list_head list;
16 };
17 #define list_to_maps_list(list_head)                            \
18         container_of((list_head), struct maps_list, list)
19
20 #define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
21
22 struct pageframe {
23         struct bintree tree;
24         struct maps_list ml;    /* List to mappings which point to this pfn */
25
26         unsigned long long pf;  /* page frame entry from /proc/pid/pagemap */
27
28         int refcount;
29 };
30
31 #define tree_to_pageframe(tree_struct)                          \
32         container_of((tree_struct), struct pageframe, tree)
33
34 static inline int page_present(struct pageframe *p)
35 {
36         return !!(BITRANGE(63, 63) & p->pf);
37 }
38
39 static inline int page_swapped(struct pageframe *p)
40 {
41         return !!(BITRANGE(62, 62) & p->pf);
42 }
43
44 static inline int page_shift(struct pageframe *p)
45 {
46         return (BITRANGE(55, 60) & p->pf) >> 55;
47 }
48
49 static inline long int pfn(struct pageframe *p)
50 {
51         return (BITRANGE(0, 54) & p->pf);
52 }
53
54 static inline int swap_type(struct pageframe *p)
55 {
56         return (BITRANGE(0, 4) & p->pf);
57 }
58
59 static inline int swap_offset(struct pageframe *p)
60 {
61         return (BITRANGE(5, 54) & p->pf) >> 5;
62 }
63
64 struct maps {
65         struct list_head list;
66
67         /* Memory segment of a mapping */
68         unsigned long start;
69         unsigned long end;
70         unsigned long size;
71
72         long int pages_present;
73         long int pages_swapped;
74
75         /* Name of the mapping, such as library name or something else */
76         char name[128];
77         int pid; /* Process which address space the mapping belongs to */
78         int tid; /* thread id */
79 };
80
81 #define list_to_maps(list_head)                         \
82         container_of((list_head), struct maps, list)
83
84 struct process {
85         struct maps *maps;
86         struct list_head list;
87         int pid;
88         int tid;
89         char name[256];
90
91         long int pages_present;
92         long int pages_swapped;
93 };
94
95 #define PARSE_PID               0x1
96 #define PARSE_MAP_NAME          0x2
97 #define PARSE_PROCESS_NAME      0x4
98 #define PARSE_DUMP              0x8
99 #define PARSE_NOADD_TREE        0x10
100
101 struct parse_opts {
102         int parse_mask;
103         int pid;
104         char *name;
105         int with_threads;
106 };
107
108 #endif