Просмотр исходного кода

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 <guillem@debian.org>
Stefan Fritsch лет назад: 16
Родитель
Сommit
9d81bf92ef
3 измененных файлов с 27 добавлено и 1 удалено
  1. 2 1
      configure.ac
  2. 3 0
      debian/changelog
  3. 22 0
      src/filesdb.c

+ 2 - 1
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

+ 3 - 0
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 <morten@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 <sf@sfritsch.de>. Closes: #557560
 
   [ Modestas Vainius ]
   * Implement symbol patterns (Closes: #563752). From now on, it is possible to

+ 22 - 0
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)