From: Jo-Philipp Wich Date: Mon, 13 Feb 2017 13:31:24 +0000 (+0100) Subject: pkg: move active_list structure out of pkg_t X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ba12c7133602244bb13dc026a78ea2fababb1967;p=oweals%2Fopkg-lede.git pkg: move active_list structure out of pkg_t 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 --- diff --git a/libopkg/active_list.h b/libopkg/active_list.h index 396e051..e20a338 100644 --- a/libopkg/active_list.h +++ b/libopkg/active_list.h @@ -19,11 +19,13 @@ #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); diff --git a/libopkg/opkg.c b/libopkg/opkg.c index 61c7306..9e278cd 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -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); diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index c50d8f9..8fc846a 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -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); diff --git a/libopkg/opkg_upgrade.c b/libopkg/opkg_upgrade.c index e4eca11..1489931 100644 --- a/libopkg/opkg_upgrade.c +++ b/libopkg/opkg_upgrade.c @@ -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); diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 2a393a7..a1ee5a2 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -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) { diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 7fdbea2..2c645aa 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -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; diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 4ffe73a..ebd763a 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -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]);