Hi!

On Sun, 2009-11-22 at 22:35:10 +0100, Stefan Fritsch wrote:
> 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).

I applied the patch with some modifications. Added a check in
configure for posix_fadvise. And moved the code into a
pkg_files_optimize_load() function that will be used whenever FIEMAP
is not available, which gives better improvement.

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

I didn't set this as it's taken care of by AC_USE_SYSTEM_EXTENSIONS.

>  #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);
> +  }

As the time doing this is insignificant compared to the actual
reading, I didn't modify the progress output.

> +  it = iterpkgstart();
> +  while ((pkg = iterpkgnext(it)) != NULL) {
> +    fd = open(pkgadminfile(pkg,LISTFILE), 
> O_RDONLY|O_NOATIME|O_NONBLOCK|O_NOCTTY);

I didn't use O_NOATIME (Linux-specific), nor O_NOCTTY (no file under
admindir should be a device).

> +    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) {

Thanks for the patch!

regards,
guillem



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to