#define list_to_maps_list(list_head) \
container_of((list_head), struct maps_list, list)
+#define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
+
struct pageframe {
struct bintree tree;
struct maps_list ml; /* List to mappings which point to this pfn */
- unsigned long pfn; /* page frame number */
- int swap_type;
- int swap_offset;
- int page_shift;
- int page_swapped;
- int page_present;
+
+ unsigned long long pf; /* page frame entry from /proc/pid/pagemap */
+
int refcount;
};
#define tree_to_pageframe(tree_struct) \
container_of((tree_struct), struct pageframe, tree)
+static inline int page_present(struct pageframe *p)
+{
+ return !!(BITRANGE(63, 63) & p->pf);
+}
+
+static inline int page_swapped(struct pageframe *p)
+{
+ return !!(BITRANGE(62, 62) & p->pf);
+}
+
+static inline int page_shift(struct pageframe *p)
+{
+ return (BITRANGE(55, 60) & p->pf) >> 55;
+}
+
+static inline long int pfn(struct pageframe *p)
+{
+ return (BITRANGE(0, 54) & p->pf);
+}
+
+static inline int swap_type(struct pageframe *p)
+{
+ return (BITRANGE(0, 4) & p->pf);
+}
+
+static inline int swap_offset(struct pageframe *p)
+{
+ return (BITRANGE(5, 54) & p->pf) >> 5;
+}
+
struct maps {
struct list_head list;
return pageframe;
}
-#define BITRANGE(first, last) (((2ll << (last - first)) - 1) << first)
-
-static void pageframe_to_struct(unsigned long long p, struct pageframe *pf)
-{
- /* Refer Documentation/vm/pagemap.txt for the format */
- pf->page_present = !!(BITRANGE(63, 63) & p);
- pf->page_swapped = !!(BITRANGE(62, 62) & p);
- pf->page_shift = (BITRANGE(55, 60) & p) >> 55;
- pf->pfn = (BITRANGE(0, 54) & p);
- pf->swap_type = (BITRANGE(0, 4) & p);
- pf->swap_offset = (BITRANGE(5, 54) & p) >> 5;
-#if 0
- printf("pfn: %lx shift: %d present: %d swapped %d\n",
- pf->pfn, pf->page_shift, pf->page_present, pf->page_swapped);
-#endif
-}
-
static int compare_pageframe(struct bintree *at, struct bintree *bt)
{
struct pageframe *a, *b;
a = tree_to_pageframe(at);
b = tree_to_pageframe(bt);
- return a->pfn - b->pfn;
+ return a->pf - b->pf;
}
struct bintree_ops pageframe_ops = {
if (!pf[ret / sizeof(pf[0])])
continue;
- pageframe_to_struct(pf[ret / sizeof(pf[0])], pageframe);
+ pageframe->pf = (pf[ret / sizeof(pf[0])]);
/* ignore unused pages */
- if (!(pageframe->page_swapped ||
- pageframe->page_present))
+ if (!(page_swapped(pageframe) ||
+ page_present(pageframe)))
continue;
if (should_add_to_tree(opts, pageframe, map)) {
tmp->map = map;
list_add(&tmp->list, &match->ml.list);
- if (match->page_present)
+ if (page_present(match))
map->pages_present++;
- else if (match->page_swapped)
+ else if (page_swapped(match))
map->pages_swapped++;
}
}