pkg: move active_list structure out of pkg_t
authorJo-Philipp Wich <jo@mein.io>
Mon, 13 Feb 2017 13:31:24 +0000 (14:31 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 13 Feb 2017 16:14:47 +0000 (17:14 +0100)
The active list head is only used by a tiny fraction of the allocated
package structures in memory so do not waste heap memory by allocating
space for it in all loaded packages.

Instead allocate active list heads dynamically where needed and point
them to the corresponding packages.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
libopkg/active_list.h
libopkg/opkg.c
libopkg/opkg_cmd.c
libopkg/opkg_upgrade.c
libopkg/pkg.c
libopkg/pkg.h
libopkg/pkg_depends.c

index 396e0512aba9a6daaa06850704c9a90004d7bc30..e20a3380e4a05bf489ac29ebfcc35c20f225448b 100644 (file)
 #define ACTIVE_LIST_H
 
 #include "list.h"
+#include "pkg.h"
 
 struct active_list {
        struct list_head node;
        struct list_head depend;
        struct active_list *depended;
+       pkg_t *pkg;
 };
 
 struct active_list *active_list_head_new(void);
index 61c73065c5457f53d37cbe4865263e573908c3bc..9e278cd7af621a1b47eb90fc73a96f146c2aa8e4 100644 (file)
@@ -707,7 +707,7 @@ opkg_list_upgradable_packages(opkg_package_callback_t callback, void *user_data)
        head = prepare_upgrade_list();
        for (node = active_list_next(head, head); node;
             node = active_list_next(head, node)) {
-               old = list_entry(node, pkg_t, list);
+               old = node->pkg;
                new =
                    pkg_hash_fetch_best_installation_candidate_by_name(old->
                                                                       name);
index c50d8f9cf8f72582bc20c55da8510d29f33efb5f..8fc846ad57aeab890c2c927fc0471fbcd42e1e63 100644 (file)
@@ -665,7 +665,7 @@ static int opkg_list_upgradable_cmd(int argc, char **argv)
        char *old_v, *new_v;
        for (node = active_list_next(head, head); node;
             node = active_list_next(head, node)) {
-               _old_pkg = list_entry(node, pkg_t, list);
+               _old_pkg = node->pkg;
                _new_pkg =
                    pkg_hash_fetch_best_installation_candidate_by_name
                    (_old_pkg->name);
index e4eca11d465095e2e3e485ab7801b82c413cfeff..148993131611dae41ca0e160ba72cd3a2886b4f8 100644 (file)
@@ -82,7 +82,7 @@ static void
 pkg_hash_check_installed_pkg_helper(const char *pkg_name, void *entry,
                                    void *data)
 {
-       struct active_list *head = (struct active_list *)data;
+       struct active_list *item, *head = (struct active_list *)data;
        abstract_pkg_t *ab_pkg = (abstract_pkg_t *) entry;
        pkg_vec_t *pkg_vec = ab_pkg->pkgs;
        int j;
@@ -93,8 +93,12 @@ pkg_hash_check_installed_pkg_helper(const char *pkg_name, void *entry,
        for (j = 0; j < pkg_vec->len; j++) {
                pkg_t *pkg = pkg_vec->pkgs[j];
                if (pkg->state_status == SS_INSTALLED
-                   || pkg->state_status == SS_UNPACKED)
-                       active_list_add(head, &pkg->list);
+                   || pkg->state_status == SS_UNPACKED) {
+                       printf("alloc item for pkg=%p\n", pkg);
+                       item = active_list_head_new();
+                       item->pkg = pkg;
+                       active_list_add(head, item);
+               }
        }
 }
 
@@ -114,7 +118,7 @@ struct active_list *prepare_upgrade_list(void)
                pkg_t *old, *new;
                int cmp;
 
-               old = list_entry(node, pkg_t, list);
+               old = node->pkg;
                new =
                    pkg_hash_fetch_best_installation_candidate_by_name(old->
                                                                       name);
@@ -125,7 +129,7 @@ struct active_list *prepare_upgrade_list(void)
                cmp = pkg_compare_versions(old, new);
 
                if (cmp < 0) {
-                       node = active_list_move_node(all, head, &old->list);
+                       node = active_list_move_node(all, head, node);
                }
        }
        active_list_head_delete(all);
index 2a393a7e7736cec894ad44e87f809f6d947ea92a..a1ee5a2ba8121537e4885f9011f6bf57dba0fefd 100644 (file)
@@ -80,8 +80,6 @@ static void pkg_init(pkg_t * pkg)
        pkg->state_flag = SF_OK;
        pkg->state_status = SS_NOT_INSTALLED;
 
-       active_list_init(&pkg->list);
-
        pkg->installed_files = NULL;
        pkg->installed_files_ref_cnt = 0;
        pkg->essential = 0;
@@ -189,8 +187,6 @@ void pkg_deinit(pkg_t * pkg)
        pkg->state_flag = SF_OK;
        pkg->state_status = SS_NOT_INSTALLED;
 
-       active_list_clear(&pkg->list);
-
        deps = pkg_get_ptr(pkg, PKG_DEPENDS);
 
        if (deps) {
index 7fdbea2386d9d2379c52c6501db3f9992fa72b02..2c645aade2e5da7e9900453e2083090ed93428cd 100644 (file)
@@ -148,7 +148,6 @@ struct pkg {
        pkg_state_want_t state_want:3;
        pkg_state_flag_t state_flag:10;
        pkg_state_status_t state_status:4;
-       struct active_list list;        /* Used for installing|upgrading */
 
        abstract_pkg_t *parent;
 
index 4ffe73ac93dacd67e093611bb6f166969e13268f..ebd763a8d7e4d4bb48b5f8012b8fa063d99679b6 100644 (file)
@@ -763,7 +763,6 @@ void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg)
        abstract_pkg_vec_insert(ab_pkg->provided_by, ab_pkg);
        pkg->provides = xcalloc(pkg->provides_count, sizeof(abstract_pkg_t *));
        pkg->provides[0] = ab_pkg;
-
        for (i = 1; i < pkg->provides_count; i++) {
                abstract_pkg_t *provided_abpkg =
                    ensure_abstract_pkg_by_name(pkg->provides_str[i - 1]);