The following commit has been merged in the master branch:
commit 9d81bf92ef791ad4644f36d3b5f7361e883134d6
Author: Stefan Fritsch <s...@sfritsch.de>
Date:   Sat Feb 27 06:31:47 2010 +0100

    dpkg: Use posix_fadvise on non-Linux to speed up .list files loading
    
    When FIEMAP is not available try to use posix_fadvise() to request
    the preloading of the .list files. A search with dpkg-query went
    from 28 to 17 seconds, giving around 40% improvement.
    
    Closes: #557560
    
    Signed-off-by: Guillem Jover <guil...@debian.org>

diff --git a/configure.ac b/configure.ac
index 967f8c1..15cdfb0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,7 +124,8 @@ DPKG_CHECK_DECL([WCOREDUMP], [sys/wait.h])
 DPKG_CHECK_COMPAT_FUNCS([getopt getopt_long obstack_free \
                          strnlen strerror strsignal \
                          scandir alphasort unsetenv])
-AC_CHECK_FUNCS([strtoul isascii bcopy memcpy lchown setsid getdtablesize])
+AC_CHECK_FUNCS([strtoul isascii bcopy memcpy lchown setsid getdtablesize \
+                posix_fadvise])
 
 AC_DEFINE(LIBDPKG_VOLATILE_API, 1, [Acknowledge the volatility of the API.])
 DPKG_COMPILER_WARNINGS
diff --git a/debian/changelog b/debian/changelog
index f498569..f4a58f0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -151,6 +151,9 @@ dpkg (1.15.6) UNRELEASED; urgency=low
   * Use FIEMAP when available (on Linux based systems) to sort the .list
     files loading order. With a cold cache it improves up to a 70%.
     Thanks to Morten Hustveit <mor...@debian.org>.
+  * When FIEMAP is not available use posix_fadvise() to start preloading the
+    .list files before loading them. With a cold cache it improves up to 40%.
+    Thanks to Stefan Fritsch <s...@sfritsch.de>. Closes: #557560
 
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to
diff --git a/src/filesdb.c b/src/filesdb.c
index 1ec8e93..4e6471d 100644
--- a/src/filesdb.c
+++ b/src/filesdb.c
@@ -324,6 +324,28 @@ pkg_files_optimize_load(struct pkg_array *array)
 
   pkg_array_sort(array, pkg_sorter_by_listfile_phys_offs);
 }
+#elif defined(HAVE_POSIX_FADVISE)
+static void
+pkg_files_optimize_load(struct pkg_array *array)
+{
+  int i;
+
+  /* Ask the kernel to start preloading the list files, so as to get a
+   * boost when later we actually load them. */
+  for (i = 0; i < array->n_pkgs; i++) {
+    struct pkginfo *pkg = array->pkgs[i];
+    const char *listfile;
+    int fd;
+
+    listfile = pkgadminfile(pkg, LISTFILE);
+
+    fd = open(listfile, O_RDONLY | O_NONBLOCK);
+    if (fd != -1) {
+      posix_fadvise(fd, 0, 0, POSIX_FADV_WILLNEED);
+      close(fd);
+    }
+  }
+}
 #else
 static void
 pkg_files_optimize_load(struct pkg_array *array)

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to