diff options
| author | David Kalnischkies <david@kalnischkies.de> | 2021-02-03 22:41:56 +0100 |
|---|---|---|
| committer | David Kalnischkies <david@kalnischkies.de> | 2021-02-04 11:00:00 +0100 |
| commit | a158e78152316f56b1a324a42a2f00f0a8662ac3 (patch) | |
| tree | d73790729fd92807a452c04a2f7e0147cf96c0aa /apt-pkg/cachefile.cc | |
| parent | c31ba27ecf7e35e03af34c3d74d3c6c93976f89c (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/cachefile.cc')
| -rw-r--r-- | apt-pkg/cachefile.cc | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/apt-pkg/cachefile.cc b/apt-pkg/cachefile.cc index 8b86fa3e4..5355994d3 100644 --- a/apt-pkg/cachefile.cc +++ b/apt-pkg/cachefile.cc @@ -27,10 +27,13 @@ #include <apt-pkg/progress.h> #include <apt-pkg/sourcelist.h> +#include <limits> #include <memory> #include <string> #include <vector> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <apti18n.h> @@ -288,15 +291,27 @@ bool pkgCacheFile::AddIndexFile(pkgIndexFile * const File) /*{{{*/ // CacheFile::RemoveCaches - remove all cache files from disk /*{{{*/ // --------------------------------------------------------------------- /* */ +static void SetCacheStartBeforeRemovingCache(std::string const &cache) +{ + if (cache.empty()) + return; + auto const CacheStart = _config->FindI("APT::Cache-Start", 0); + constexpr auto CacheStartDefault = 24 * 1024 * 1024; + struct stat Buf; + if (stat(cache.c_str(), &Buf) == 0 && (Buf.st_mode & S_IFREG) != 0) + { + RemoveFile("RemoveCaches", cache); + if (CacheStart == 0 && std::numeric_limits<decltype(CacheStart)>::max() >= Buf.st_size && Buf.st_size > CacheStartDefault) + _config->Set("APT::Cache-Start", Buf.st_size); + } +} void pkgCacheFile::RemoveCaches() { std::string const pkgcache = _config->FindFile("Dir::cache::pkgcache"); + SetCacheStartBeforeRemovingCache(pkgcache); std::string const srcpkgcache = _config->FindFile("Dir::cache::srcpkgcache"); + SetCacheStartBeforeRemovingCache(srcpkgcache); - if (pkgcache.empty() == false && RealFileExists(pkgcache) == true) - RemoveFile("RemoveCaches", pkgcache); - if (srcpkgcache.empty() == false && RealFileExists(srcpkgcache) == true) - RemoveFile("RemoveCaches", srcpkgcache); if (pkgcache.empty() == false) { std::string cachedir = flNotFile(pkgcache); |
