2 * Copyright (C) 2010 Timo Kokkonen <kaapeli@itanic.dy.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;
95 #define KPAGEFLAGS_NUM 22
122 struct kpageflag_str {
127 extern struct kpageflag_str kpageflag_str[];
129 static inline int kpageflag_is_set(struct pageframe *p, int flag)
131 return !!(BITRANGE(flag, flag) & p->kpageflags);
134 static inline char *kpageflag_to_str(int flag)
138 for (i = 0; i < KPAGEFLAGS_NUM; i++)
139 if (kpageflag_str[i].flag == flag)
140 return kpageflag_str[i].str;
146 struct list_head list;
148 /* Memory segment of a mapping */
153 long int pages_present;
154 long int pages_swapped;
156 /* Name of the mapping, such as library name or something else */
158 int pid; /* Process which address space the mapping belongs to */
159 int tid; /* thread id */
162 #define list_to_maps(list_head) \
163 container_of((list_head), struct maps, list)
167 struct list_head list;
172 long int pages_present;
173 long int pages_swapped;
174 long int pages_unique;
179 #define PARSE_PID 0x1
180 #define PARSE_MAP_NAME 0x2
181 #define PARSE_DUMP 0x8
182 #define PARSE_NOADD_TREE 0x10
183 #define PARSE_SHARED_MAPPING 0x20
186 struct list_head list;
192 struct list_head pidlist;
199 static inline void init_parse_opts(struct parse_opts *p)
201 memset(p, 0, sizeof(*p));
202 INIT_LIST_HEAD(&p->pidlist);
205 static inline struct pidlist *alloc_pidlist(void)
207 struct pidlist *p = calloc(sizeof(*p), 1);
212 INIT_LIST_HEAD(&p->list);
217 #define is_parse_option(parse_opts, flag) \
218 (!!((parse_opts)->parse_mask & (flag)))