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.
28 #define PAGE_SIZE (1 << PAGE_SHIFT)
34 struct list_head list;
36 #define list_to_maps_list(list_head) \
37 container_of((list_head), struct maps_list, list)
39 #define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
43 struct list_head ml; /* List of mappings which refer to this pfn */
45 unsigned long long pf; /* page frame entry from /proc/pid/pagemap */
46 unsigned long long kpageflags;
47 unsigned long long kpagecount;
52 #define tree_to_pageframe(tree_struct) \
53 container_of((tree_struct), struct pageframe, tree)
55 static inline void clear_pageframe(struct pageframe *pf)
57 memset(pf, 0, sizeof(*pf));
58 INIT_LIST_HEAD(&pf->ml);
61 static inline int page_present(struct pageframe *p)
63 return !!(BITRANGE(63, 63) & p->pf);
66 static inline int page_swapped(struct pageframe *p)
68 return !!(BITRANGE(62, 62) & p->pf);
71 static inline int page_shift(struct pageframe *p)
73 return (BITRANGE(55, 60) & p->pf) >> 55;
76 static inline long int pfn(struct pageframe *p)
78 return (BITRANGE(0, 54) & p->pf);
81 static inline int swap_type(struct pageframe *p)
83 return (BITRANGE(0, 4) & p->pf);
86 static inline int swap_offset(struct pageframe *p)
88 return (BITRANGE(5, 54) & p->pf) >> 5;
91 #define KPAGEFLAGS_NUM 22
118 struct kpageflag_str {
123 extern struct kpageflag_str kpageflag_str[];
125 static inline int kpageflag_is_set(struct pageframe *p, int flag)
127 return !!(BITRANGE(flag, flag) & p->kpageflags);
130 static inline char *kpageflag_to_str(int flag)
134 for (i = 0; i < KPAGEFLAGS_NUM; i++)
135 if (kpageflag_str[i].flag == flag)
136 return kpageflag_str[i].str;
142 struct list_head list;
144 /* Memory segment of a mapping */
149 long int pages_present;
150 long int pages_swapped;
152 /* Name of the mapping, such as library name or something else */
154 int pid; /* Process which address space the mapping belongs to */
155 int tid; /* thread id */
158 #define list_to_maps(list_head) \
159 container_of((list_head), struct maps, list)
163 struct list_head list;
168 long int pages_present;
169 long int pages_swapped;
170 long int pages_unique;
175 #define PARSE_PID 0x1
176 #define PARSE_MAP_NAME 0x2
177 #define PARSE_DUMP 0x8
178 #define PARSE_NOADD_TREE 0x10
179 #define PARSE_SHARED_MAPPING 0x20
182 struct list_head list;
188 struct list_head pidlist;
195 static inline void init_parse_opts(struct parse_opts *p)
197 memset(p, 0, sizeof(*p));
198 INIT_LIST_HEAD(&p->pidlist);
201 static inline struct pidlist *alloc_pidlist(void)
203 struct pidlist *p = calloc(sizeof(*p), 1);
208 INIT_LIST_HEAD(&p->list);
213 #define is_parse_option(parse_opts, flag) \
214 (!!((parse_opts)->parse_mask & (flag)))