From dcdf1ef18b37c243fc707869149f7761d964915c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 9 Jul 2010 17:00:28 +0200 Subject: * doc/apt.conf.5.xml: - add and document APT::Cache-{Start,Grow,Limit} options for mmap control --- apt-pkg/contrib/mmap.cc | 2 ++ apt-pkg/pkgcachegen.cc | 22 ++++++++++++++++------ apt-pkg/pkgcachegen.h | 1 + debian/changelog | 4 +++- doc/apt.conf.5.xml | 17 ++++++++++++++--- doc/examples/configure-index | 4 +++- 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc index aa184b130..69fb61fca 100644 --- a/apt-pkg/contrib/mmap.cc +++ b/apt-pkg/contrib/mmap.cc @@ -398,6 +398,8 @@ bool DynamicMMap::Grow() { if (Limit != 0 && WorkSpace >= Limit) return _error->Error(_("Unable to increase the size of the MMap as the " "limit of %lu bytes is already reached."), Limit); + if (GrowFactor <= 0) + return _error->Error(_("Unable to increase size of the MMap as automatic growing is disabled by user.")); unsigned long const newSize = WorkSpace + GrowFactor; diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 18bad6727..7ca8fbfda 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -1094,6 +1094,18 @@ static bool BuildCache(pkgCacheGenerator &Gen, return true; } /*}}}*/ +DynamicMMap* pkgCacheGenerator::CreateDynamicMMap(FileFd *CacheF, unsigned long Flags) { + unsigned long const MapStart = _config->FindI("APT::Cache-Start", 24*1024*1024); + unsigned long const MapGrow = _config->FindI("APT::Cache-Grow", 1*1024*1024); + unsigned long const MapLimit = _config->FindI("APT::Cache-Limit", 0); + Flags |= MMap::Moveable; + if (_config->FindB("APT::Cache-Fallback", false) == true) + Flags |= MMap::Fallback; + if (CacheF != NULL) + return new DynamicMMap(*CacheF, Flags, MapStart, MapGrow, MapLimit); + else + return new DynamicMMap(Flags, MapStart, MapGrow, MapLimit); +} // CacheGenerator::MakeStatusCache - Construct the status cache /*{{{*/ // --------------------------------------------------------------------- /* This makes sure that the status cache (the cache that has all @@ -1109,7 +1121,6 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress MMap **OutMap,bool AllowMem) { bool const Debug = _config->FindB("Debug::pkgCacheGen", false); - unsigned long const MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024); vector Files; for (vector::const_iterator i = List.begin(); @@ -1181,7 +1192,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress unlink(CacheFile.c_str()); CacheF = new FileFd(CacheFile,FileFd::WriteEmpty); fchmod(CacheF->Fd(),0644); - Map = new DynamicMMap(*CacheF,MMap::Public | MMap::Moveable, MapSize); + Map = CreateDynamicMMap(CacheF, MMap::Public); if (_error->PendingError() == true) return false; if (Debug == true) @@ -1190,7 +1201,7 @@ bool pkgCacheGenerator::MakeStatusCache(pkgSourceList &List,OpProgress *Progress else { // Just build it in memory.. - Map = new DynamicMMap(MMap::Moveable, MapSize); + Map = CreateDynamicMMap(NULL); if (Debug == true) std::clog << "Open memory Map (not filebased)" << std::endl; } @@ -1297,13 +1308,12 @@ __deprecated bool pkgMakeOnlyStatusCache(OpProgress &Progress,DynamicMMap **OutM { return pkgCacheGenerator::MakeOnlyStatusCache(&Progress, OutMap); } bool pkgCacheGenerator::MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap) { - unsigned long MapSize = _config->FindI("APT::Cache-Limit",20*1024*1024); vector Files; unsigned long EndOfSource = Files.size(); if (_system->AddStatusFiles(Files) == false) return false; - - SPtr Map = new DynamicMMap(MMap::Moveable, MapSize); + + SPtr Map = CreateDynamicMMap(NULL); unsigned long CurrentSize = 0; unsigned long TotalSize = 0; diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 3bee1f958..20dd28030 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -101,6 +101,7 @@ class pkgCacheGenerator /*{{{*/ static bool MakeStatusCache(pkgSourceList &List,OpProgress *Progress, MMap **OutMap = 0,bool AllowMem = false); static bool MakeOnlyStatusCache(OpProgress *Progress,DynamicMMap **OutMap); + static DynamicMMap* CreateDynamicMMap(FileFd *CacheF, unsigned long Flags = 0); void ReMap(void const * const oldMap, void const * const newMap); diff --git a/debian/changelog b/debian/changelog index dab703c6b..f819908ad 100644 --- a/debian/changelog +++ b/debian/changelog @@ -40,6 +40,8 @@ apt (0.7.26~exp8) UNRELEASED; urgency=low * apt-pkg/pkgcachegen.{cc,h}: - make the used MMap moveable (and therefore dynamic resizeable) by applying (some) mad pointer magic (Closes: #195018) + * doc/apt.conf.5.xml: + - add and document APT::Cache-{Start,Grow,Limit} options for mmap control [ Julian Andres Klode ] * methods/ftp.h: @@ -55,7 +57,7 @@ apt (0.7.26~exp8) UNRELEASED; urgency=low * debian/control: - Set Standards-Version to 3.9.0 - -- David Kalnischkies Mon, 05 Jul 2010 12:05:30 +0200 + -- David Kalnischkies Fri, 09 Jul 2010 16:55:53 +0200 apt (0.7.26~exp7) experimental; urgency=low diff --git a/doc/apt.conf.5.xml b/doc/apt.conf.5.xml index 39e2c8e6b..7b7290794 100644 --- a/doc/apt.conf.5.xml +++ b/doc/apt.conf.5.xml @@ -199,9 +199,20 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";}; anything that those packages depend on. - Cache-Limit - APT uses a fixed size memory mapped cache file to store the 'available' - information. This sets the size of that cache (in bytes). + Cache-Start, Cache-Grow and Cache-Limit + APT uses since version 0.7.26 a resizable memory mapped cache file to store the 'available' + information. Cache-Start acts as a hint to which size the Cache will grow + and is therefore the amount of memory APT will request at startup. The default value is + 20971520 bytes (~20 MB). Note that these amount of space need to be available for APT + otherwise it will likely fail ungracefully, so for memory restricted devices these value should + be lowered while on systems with a lot of configured sources this might be increased. + Cache-Grow defines in byte with the default of 1048576 (~1 MB) how much + the Cache size will be increased in the event the space defined by Cache-Start + is not enough. These value will be applied again and again until either the cache is big + enough to store all information or the size of the cache reaches the Cache-Limit. + The default of Cache-Limit is 0 which stands for no limit. + If Cache-Grow is set to 0 the automatic grow of the cache is disabled. + Build-Essential diff --git a/doc/examples/configure-index b/doc/examples/configure-index index fdec32c2c..26fb53fec 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -95,7 +95,9 @@ APT Clean-Installed "true"; Immediate-Configure "true"; // DO NOT turn this off, see the man page Force-LoopBreak "false"; // DO NOT turn this on, see the man page - Cache-Limit "4194304"; + Cache-Start "20971520"; + Cache-Grow "1048576"; + Cache-Limit "0"; Default-Release ""; // consider Recommends, Suggests as important dependencies that should -- cgit v1.2.3 From 7635093c1c015e385a9e72bdd8a089fd9d48ab57 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 9 Jul 2010 19:51:19 +0200 Subject: switch from std::set to std::vector as it is way more simple, a bit faster and still provides everything we need for the Cache generator --- apt-pkg/pkgcachegen.cc | 16 ++++++++-------- apt-pkg/pkgcachegen.h | 12 +++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index 7ca8fbfda..1175d5129 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -36,7 +36,7 @@ #include /*}}}*/ typedef vector::iterator FileIterator; -template std::set pkgCacheGenerator::Dynamic::toReMap; +template std::vector pkgCacheGenerator::Dynamic::toReMap(6); // CacheGenerator::pkgCacheGenerator - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -113,25 +113,25 @@ void pkgCacheGenerator::ReMap(void const * const oldMap, void const * const newM if (UniqHash[i] != 0) UniqHash[i] += (pkgCache::StringItem*) newMap - (pkgCache::StringItem*) oldMap; - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); - for (std::set::const_iterator i = Dynamic::toReMap.begin(); + for (std::vector::const_iterator i = Dynamic::toReMap.begin(); i != Dynamic::toReMap.end(); ++i) (*i)->ReOwn(Cache, oldMap, newMap); } /*}}}*/ diff --git a/apt-pkg/pkgcachegen.h b/apt-pkg/pkgcachegen.h index 20dd28030..ff198833a 100644 --- a/apt-pkg/pkgcachegen.h +++ b/apt-pkg/pkgcachegen.h @@ -23,7 +23,7 @@ #include #include -#include +#include class pkgSourceList; class OpProgress; @@ -46,16 +46,14 @@ class pkgCacheGenerator /*{{{*/ friend class ListParser; template class Dynamic { - Iter *I; - public: - static std::set toReMap; - Dynamic(Iter &It) : I(&It) { - toReMap.insert(I); + static std::vector toReMap; + Dynamic(Iter &I) { + toReMap.push_back(&I); } ~Dynamic() { - toReMap.erase(I); + toReMap.pop_back(); } }; -- cgit v1.2.3 From 62d073d937742baf8621a11c3094e0320aa846cd Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 9 Jul 2010 21:46:42 +0200 Subject: check the state of the FileFd before renaming as otherwise the rename will be tried twice e.g. in an "apt-get update" run and every other piece of code closing the FileFd manual before the destructor will do it again. --- apt-pkg/contrib/fileutl.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index 62d42e4da..8f7791a8a 100644 --- a/apt-pkg/contrib/fileutl.cc +++ b/apt-pkg/contrib/fileutl.cc @@ -843,19 +843,21 @@ bool FileFd::Close() bool Res = true; if ((Flags & AutoClose) == AutoClose) if (iFd >= 0 && close(iFd) != 0) - Res &= _error->Errno("close",_("Problem closing the file")); - iFd = -1; + Res &= _error->Errno("close",_("Problem closing the file %s"), FileName.c_str()); - if ((Flags & Replace) == Replace) { + if ((Flags & Replace) == Replace && iFd >= 0) { if (rename(TemporaryFileName.c_str(), FileName.c_str()) != 0) - Res &= _error->Errno("rename",_("Problem renaming the file")); + Res &= _error->Errno("rename",_("Problem renaming the file %s to %s"), TemporaryFileName.c_str(), FileName.c_str()); + FileName = TemporaryFileName; // for the unlink() below. } - + + iFd = -1; + if ((Flags & Fail) == Fail && (Flags & DelOnFail) == DelOnFail && FileName.empty() == false) if (unlink(FileName.c_str()) != 0) - Res &= _error->WarningE("unlnk",_("Problem unlinking the file")); + Res &= _error->WarningE("unlnk",_("Problem unlinking the file %s"), FileName.c_str()); return Res; -- cgit v1.2.3