2 * Copyright (C) 2010 Timo Kokkonen <timo.t.kokkonen@iki.fi>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define PAGE_SIZE (1 << PAGE_SHIFT)
35 struct list_head list;
37 #define list_to_maps_list(list_head) \
38 container_of((list_head), struct maps_list, list)
40 #define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
44 struct list_head ml; /* List of mappings which refer to this pfn */
46 unsigned long long pf; /* page frame entry from /proc/pid/pagemap */
47 unsigned long long kpageflags;
48 unsigned long long kpagecount;
53 struct pageframe *pf_insert(struct rb_root *root, struct pageframe *pf);
54 struct pageframe *pf_search(struct rb_root *root, struct pageframe *pf);
56 #define rb_to_pageframe(tree_struct) \
57 container_of((tree_struct), struct pageframe, tree)
59 static inline void clear_pageframe(struct pageframe *pf)
61 memset(pf, 0, sizeof(*pf));
62 INIT_LIST_HEAD(&pf->ml);
65 static inline int page_present(struct pageframe *p)
67 return !!(BITRANGE(63, 63) & p->pf);
70 static inline int page_swapped(struct pageframe *p)
72 return !!(BITRANGE(62, 62) & p->pf);
75 static inline int page_shift(struct pageframe *p)
77 return (BITRANGE(55, 60) & p->pf) >> 55;
80 static inline long int pfn(struct pageframe *p)
82 return (BITRANGE(0, 54) & p->pf);
85 static inline int swap_type(struct pageframe *p)
87 return (BITRANGE(0, 4) & p->pf);
90 static inline int swap_offset(struct pageframe *p)
92 return (BITRANGE(5, 54) & p->pf) >> 5;
122 #define KPAGEFLAGS_NUM __PAGEFLAGS_LAST
124 struct kpageflag_str {
129 extern struct kpageflag_str kpageflag_str[];
131 static inline int kpageflag_is_set(struct pageframe *p, int flag)
133 return !!(BITRANGE(flag, flag) & p->kpageflags);
136 static inline char *kpageflag_to_str(int flag)
140 for (i = 0; i < KPAGEFLAGS_NUM; i++)
141 if (kpageflag_str[i].flag == flag)
142 return kpageflag_str[i].str;
148 struct list_head list;
150 /* Memory segment of a mapping */
155 long int pages_present;
156 long int pages_swapped;
158 /* Name of the mapping, such as library name or something else */
160 int pid; /* Process which address space the mapping belongs to */
161 int tid; /* thread id */
164 #define list_to_maps(list_head) \
165 container_of((list_head), struct maps, list)
169 struct list_head list;
174 long int pages_present;
175 long int pages_swapped;
176 long int pages_unique;
181 #define PARSE_PID 0x1
182 #define PARSE_MAP_NAME 0x2
183 #define PARSE_DUMP 0x8
184 #define PARSE_NOADD_TREE 0x10
185 #define PARSE_SHARED_MAPPING 0x20
188 struct list_head list;
194 struct list_head pidlist;
201 static inline void init_parse_opts(struct parse_opts *p)
203 memset(p, 0, sizeof(*p));
204 INIT_LIST_HEAD(&p->pidlist);
207 static inline struct pidlist *alloc_pidlist(void)
209 struct pidlist *p = calloc(sizeof(*p), 1);
214 INIT_LIST_HEAD(&p->list);
219 #define is_parse_option(parse_opts, flag) \
220 (!!((parse_opts)->parse_mask & (flag)))