]> git.itanic.dy.fi Git - scan-pagemap/commitdiff
pagemaps: Optimize memory usage
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 3 Jul 2010 20:06:54 +0000 (23:06 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 3 Jul 2010 20:06:54 +0000 (23:06 +0300)
Do not make a new copy of the maps structure for each pageframe. Just
store a pointer to it instead.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
pagemap.h
parse.c

index a46e5d1ba31969c71e65626f978d06563a179eab..e06a00ca1509d33c0a628a9c1a8cefe8d9018179 100644 (file)
--- a/pagemap.h
+++ b/pagemap.h
 
 struct maps;
 
+struct maps_list {
+       struct maps *map;
+       struct list_head list;
+};
+
 struct pageframe {
        struct bintree tree;
-       struct maps *maps;      /* List to mappings which point to this pfn */
+       struct maps_list *ml;   /* List to mappings which point to this pfn */
        unsigned long pfn;      /* page frame number */
        int swap_type;
        int swap_offset;
diff --git a/parse.c b/parse.c
index 5b7933ba7afd6be735b481d9ad97a434e7166199..55d6402f8e8d8d64cfc7f83b79e87f9c45e5901b 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -6,6 +6,20 @@
 #include "parse.h"
 #include "pagemap.h"
 
+static struct maps_list *alloc_maplist(void)
+{
+       struct maps_list *map;
+
+       map = malloc(sizeof *map);
+       if (map == NULL)
+               goto err;
+
+       memset(map, 0, sizeof(*map));
+       INIT_LIST_HEAD(&map->list);
+err:
+       return map;
+}
+
 static struct maps *alloc_map(void)
 {
        struct maps *map;
@@ -113,7 +127,8 @@ struct bintree_ops pageframe_ops = {
 static int parse_pageframe(FILE *file, struct pageframe *pf_tree,
                        struct maps *maps)
 {
-       struct maps *map, *tmp;
+       struct maps *map;
+       struct maps_list *tmp;
        struct pageframe *match, *pageframe;
        long start, len, i;
        unsigned long long pf;
@@ -159,14 +174,13 @@ static int parse_pageframe(FILE *file, struct pageframe *pf_tree,
                         * Add a link from the physical page to this
                         * process's page map
                         */
-                       if (!match->maps) {
-                               match->maps = alloc_map();
-                               *match->maps = *map;
-                               INIT_LIST_HEAD(&match->maps->list);
+                       if (!match->ml) {
+                               match->ml = alloc_maplist();
+                               match->ml->map = map;
                        } else {
-                               tmp = alloc_map();
-                               *tmp = *map;
-                               list_add(&match->maps->list, &tmp->list);
+                               tmp = alloc_maplist();
+                               tmp->map = map;
+                               list_add(&match->ml->list, &tmp->list);
                        }
                }
        }