Sat Nov 29 12:23:08 GMT 2008  Steve Cotton <steve@s.cotton.clara.co.uk>
  * 380509: set the size of the DynamicMMap based on the size of the package files
  This changes pkgMakeStatusCache, but not pkgMakeOnlyStatusCache.
  The latter is appears to only be called from debDpkgDB::ReadyPkgCache, which
  itself is exported, but only called in two test files scratch.cc and
  testextract.cc (searched Apt and Aptitude for others).
diff -rN -u old-apt-0.7.18.steve.2/apt-pkg/pkgcachegen.cc new-apt-0.7.18.steve.2/apt-pkg/pkgcachegen.cc
--- old-apt-0.7.18.steve.2/apt-pkg/pkgcachegen.cc	2008-11-29 12:40:25.000000000 +0000
+++ new-apt-0.7.18.steve.2/apt-pkg/pkgcachegen.cc	2008-11-29 12:40:25.000000000 +0000
@@ -793,8 +793,6 @@
 bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress,
 			MMap **OutMap,bool AllowMem)
 {
-   unsigned long MapSize = _config->FindI("APT::Cache-Limit",24*1024*1024);
-   
    vector<pkgIndexFile *> Files;
    for (vector<metaIndex *>::const_iterator i = List.begin();
         i != List.end();
@@ -836,7 +834,10 @@
    }
    
    /* At this point we know we need to reconstruct the package cache,
-      begin. */
+      begin by allocating an mmap'd file as large as the total of the
+      input files; all unused space will be truncated afterwards. */
+   unsigned long DefaultMapSize = ComputeSize(Files.begin(),Files.end());
+   unsigned long MapSize = _config->FindI("APT::Cache-Limit", DefaultMapSize);
    SPtr<FileFd> CacheF;
    SPtr<DynamicMMap> Map;
    if (Writeable == true && CacheFile.empty() == false)


