Package: dpkg
Version: 1.15.5.2
Severity: wishlist
Tags: patch

By using posix_fadvise with POSIX_FADV_WILLNEED on /var/dpkg/info/*.list, the
time needed to read the database can be reduced in the case where the files are
not yet in the buffer cache. The attached patch gives 20-30% time reduction for
installing one small package on my system (tested with echo 3 >
/proc/sys/vm/drop_caches).
diff -Nru dpkg-1.15.5.2/src/filesdb.c dpkg-1.15.5.2+nmu1/src/filesdb.c
--- dpkg-1.15.5.2/src/filesdb.c	2009-11-18 08:28:44.000000000 +0100
+++ dpkg-1.15.5.2+nmu1/src/filesdb.c	2009-11-22 22:23:24.000000000 +0100
@@ -19,6 +19,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#define _XOPEN_SOURCE 600
+
 #include <config.h>
 #include <compat.h>
 
@@ -257,14 +259,28 @@
   struct pkgiterator *it;
   struct pkginfo *pkg;
   struct progress progress;
+  int fd;
 
   if (allpackagesdone) return;
   if (saidread<2) {
     int max = countpackages();
 
     saidread=1;
-    progress_init(&progress, _("(Reading database ... "), max);
+    progress_init(&progress, _("(Reading database ... "), 2 * max);
+  }
+
+  it = iterpkgstart();
+  while ((pkg = iterpkgnext(it)) != NULL) {
+    fd = open(pkgadminfile(pkg,LISTFILE), O_RDONLY|O_NOATIME|O_NONBLOCK|O_NOCTTY);
+    if (fd != -1) {
+      posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
+      close(fd);
+    }
+  
+    if (saidread == 1)
+      progress_step(&progress);
   }
+  iterpkgend(it);
 
   it= iterpkgstart();
   while ((pkg = iterpkgnext(it)) != NULL) {

Reply via email to