summaryrefslogtreecommitdiff
path: root/apt-pkg/pkgcachegen.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2021-02-03 22:41:56 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2021-02-04 11:00:00 +0100
commita158e78152316f56b1a324a42a2f00f0a8662ac3 (patch)
treed73790729fd92807a452c04a2f7e0147cf96c0aa /apt-pkg/pkgcachegen.cc
parentc31ba27ecf7e35e03af34c3d74d3c6c93976f89c (diff)
Use size of the old cache as APT::Cache-Start default
Depending on your configured source 25 MB is hardly enough, so the mmap housing the cache while it is build has to grow. Repeatedly. We can cut down on the repeats of this by keeping a record of the size of the old cache assuming the sizes will remain roughly in the same ballpark.
Diffstat (limited to 'apt-pkg/pkgcachegen.cc')
-rw-r--r--apt-pkg/pkgcachegen.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc
index 6f2e3268c..b4fd0641e 100644
--- a/apt-pkg/pkgcachegen.cc
+++ b/apt-pkg/pkgcachegen.cc
@@ -37,6 +37,8 @@
#include <apti18n.h>
/*}}}*/
+constexpr auto APT_CACHE_START_DEFAULT = 24 * 1024 * 1024;
+
template<class T> using Dynamic = pkgCacheGenerator::Dynamic<T>;
typedef std::vector<pkgIndexFile *>::iterator FileIterator;
template <typename Iter> std::vector<Iter*> pkgCacheGenerator::Dynamic<Iter>::toReMap;
@@ -1383,6 +1385,13 @@ static bool CheckValidity(FileFd &CacheFile, std::string const &CacheFileName,
return false;
}
+ if (_config->FindI("APT::Cache-Start", 0) == 0)
+ {
+ auto const size = CacheFile.FileSize();
+ if (std::numeric_limits<int>::max() >= size && size > APT_CACHE_START_DEFAULT)
+ _config->Set("APT::Cache-Start", size);
+ }
+
if (List.GetLastModifiedTime() > CacheFile.ModificationTime())
{
if (Debug == true)
@@ -1591,7 +1600,7 @@ static bool BuildCache(pkgCacheGenerator &Gen,
where it builds the cache 'fast' into a memory buffer. */
static DynamicMMap* CreateDynamicMMap(FileFd * const CacheF, unsigned long Flags)
{
- map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", 24*1024*1024);
+ map_filesize_t const MapStart = _config->FindI("APT::Cache-Start", APT_CACHE_START_DEFAULT);
map_filesize_t const MapGrow = _config->FindI("APT::Cache-Grow", 1*1024*1024);
map_filesize_t const MapLimit = _config->FindI("APT::Cache-Limit", 0);
Flags |= MMap::Moveable;