FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-14-2008, 11:29 PM
Nagy Gabor
 
Default _alpm_db_add_pkgincache rework

>From 7490b62443a0bd08a06fa3c97976a27de5b85665 Mon Sep 17 00:00:00 2001
From: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Date: Tue, 15 Jul 2008 01:07:22 +0200
Subject: [PATCH] _alpm_db_add_pkgincache rework

Commit 8240da6cb3ff95ad480efe3e1876104024398fae broke some alpm hierarchy
and introduced a new memleak (trans->packages was never freed in case of add
transaction, even if the transaction wasn't committed), so it is reverted
now.

We follow a different approach to reduce memory usage:
_alpm_db_add_pkgincache doesn't duplicate the whole package before adding
it to the cache, only the package name and version (INFRQ_BASE).
This method needs very small extra memory (compared to the reverted method),
and after transaction commit we use less memory than before (since the
big 'files' fields are not copied to cache), this is useful in GUIs.

Note: The old add_pkgincache was a bit broken, since pkg->origin wasn't
filled in correctly.

Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
---
lib/libalpm/cache.c | 22 ++++++++++++++++++++--
lib/libalpm/trans.c | 3 +--
2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index b140476..032cc97 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -98,17 +98,35 @@ alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
return(db->pkgcache);
}

+/* "duplicate" pkg with BASE info (to spare some memory) then add it to pkgcache */
int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
{
+ pmpkg_t *newpkg;
+
ALPM_LOG_FUNC;

if(db == NULL || pkg == NULL) {
return(-1);
}

+ newpkg = _alpm_pkg_new();
+ if(newpkg == NULL) {
+ return(-1);
+ }
+ newpkg->name = strdup(pkg->name);
+ newpkg->version = strdup(pkg->version);
+ if(newpkg->name == NULL || newpkg->version == NULL) {
+ pm_errno = PM_ERR_MEMORY;
+ _alpm_pkg_free(newpkg);
+ return(-1);
+ }
+ newpkg->origin = PKG_FROM_CACHE;
+ newpkg->origin_data.db = db;
+ newpkg->infolevel = INFRQ_BASE;
+
_alpm_log(PM_LOG_DEBUG, "adding entry '%s' in '%s' cache
",
- alpm_pkg_get_name(pkg), db->treename);
- db->pkgcache = alpm_list_add_sorted(db->pkgcache, pkg, _alpm_pkg_cmp);
+ alpm_pkg_get_name(newpkg), db->treename);
+ db->pkgcache = alpm_list_add_sorted(db->pkgcache, newpkg, _alpm_pkg_cmp);

_alpm_db_free_grpcache(db);

diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 06084ae..d6b165d 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -251,8 +251,7 @@ void _alpm_trans_free(pmtrans_t *trans)

if(trans->type == PM_TRANS_TYPE_SYNC) {
alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_sync_free);
- } else if (trans->type == PM_TRANS_TYPE_REMOVE ||
- trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
+ } else {
alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_pkg_free);
}
alpm_list_free(trans->packages);
--
1.5.6.2


_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 07-15-2008, 06:37 AM
Xavier
 
Default _alpm_db_add_pkgincache rework

Nagy Gabor wrote:
>>From 7490b62443a0bd08a06fa3c97976a27de5b85665 Mon Sep 17 00:00:00 2001
> From: Nagy Gabor <ngaba@bibl.u-szeged.hu>
> Date: Tue, 15 Jul 2008 01:07:22 +0200
> Subject: [PATCH] _alpm_db_add_pkgincache rework
>
> Commit 8240da6cb3ff95ad480efe3e1876104024398fae broke some alpm hierarchy
> and introduced a new memleak (trans->packages was never freed in case of add
> transaction, even if the transaction wasn't committed), so it is reverted
> now.
>
> We follow a different approach to reduce memory usage:
> _alpm_db_add_pkgincache doesn't duplicate the whole package before adding
> it to the cache, only the package name and version (INFRQ_BASE).
> This method needs very small extra memory (compared to the reverted method),
> and after transaction commit we use less memory than before (since the
> big 'files' fields are not copied to cache), this is useful in GUIs.
>
> Note: The old add_pkgincache was a bit broken, since pkg->origin wasn't
> filled in correctly.
>
> Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>

Acked-by: Xavier Chantry <shiningxc@gmail.com>




_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 
Old 07-16-2008, 12:18 AM
"Dan McGee"
 
Default _alpm_db_add_pkgincache rework

On Tue, Jul 15, 2008 at 1:37 AM, Xavier <shiningxc@gmail.com> wrote:
> Nagy Gabor wrote:
>>>From 7490b62443a0bd08a06fa3c97976a27de5b85665 Mon Sep 17 00:00:00 2001
>> From: Nagy Gabor <ngaba@bibl.u-szeged.hu>
>> Date: Tue, 15 Jul 2008 01:07:22 +0200
>> Subject: [PATCH] _alpm_db_add_pkgincache rework
>>
>> Commit 8240da6cb3ff95ad480efe3e1876104024398fae broke some alpm hierarchy
>> and introduced a new memleak (trans->packages was never freed in case of add
>> transaction, even if the transaction wasn't committed), so it is reverted
>> now.
>>
>> We follow a different approach to reduce memory usage:
>> _alpm_db_add_pkgincache doesn't duplicate the whole package before adding
>> it to the cache, only the package name and version (INFRQ_BASE).
>> This method needs very small extra memory (compared to the reverted method),
>> and after transaction commit we use less memory than before (since the
>> big 'files' fields are not copied to cache), this is useful in GUIs.
>>
>> Note: The old add_pkgincache was a bit broken, since pkg->origin wasn't
>> filled in correctly.
>>
>> Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
>
> Acked-by: Xavier Chantry <shiningxc@gmail.com>

Now we just need to get rid of this silly REMOVEUPGRADE business
completely. Applied, thanks.

-Dan

_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
 

Thread Tools




All times are GMT. The time now is 12:58 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org