Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Jun 2015 14:44:18 +0000
From:      "emaste (Ed Maste)" <phabric-noreply@FreeBSD.org>
To:        freebsd-toolchain@freebsd.org
Subject:   [Differential] [Request, 20 lines] D2933: Significantly speed up ar(1) on UFS file systems
Message-ID:  <differential-rev-PHID-DREV-hkid5hylfsbts6yuvnph-req@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

--b1_6a703d38f4991d5770a85cd3a93d4c9e
Content-Type: text/plain; charset = "utf-8"
Content-Transfer-Encoding: 8bit

emaste created this revision.
emaste added a reviewer: kib.
emaste added subscribers: davide, dim, freebsd-toolchain-list, kib.

REVISION SUMMARY
  Fault in the buffer prior to writing as a workaround for poor performance due to interaction with kernel fs deadlock avoidance code. See the comment prior to vn_io_fault_doio() in vfs_vnops.c for details of the issue.
  
  Thanks @kib for diagnosing, providing an explanation of the issue and workaround.

TEST PLAN
  ```
  % truncate -s 16M obj.o
  % ar r out.a obj.o
  ```
  
  Total time with stock and patched ar(1):
  ```
  x ar.r284891
  + ar.patched
  +----------------------------------------------------------------------+   
  |+                                                                     |   
  |+                                                                    x|   
  |+                                                                   xx|   
  |A                                                                   |A|   
  +----------------------------------------------------------------------+   
      N         Min          Max        Median           Avg        Stddev   
  x   3       1.307        1.321         1.315     1.3143333  0.0070237692   
  +   3        0.02        0.023         0.022   0.021666667  0.0015275252   
  Difference at 95.0% confidence
          -1.29267 +/- 0.0115203
          -98.3515% +/- 0.876513%
          (Student's t, pooled s = 0.00508265)
  ```

REVISION DETAIL
  https://reviews.freebsd.org/D2933

AFFECTED FILES
  usr.bin/ar/write.c

CHANGE DETAILS
  diff --git a/usr.bin/ar/write.c b/usr.bin/ar/write.c
  --- a/usr.bin/ar/write.c
  +++ b/usr.bin/ar/write.c
  @@ -41,6 +41,7 @@
   #include <stdlib.h>
   #include <string.h>
   #include <sysexits.h>
  +#include <unistd.h>
   
   #include "ar.h"
   
  @@ -61,6 +62,7 @@
   static void	free_obj(struct bsdar *bsdar, struct ar_obj *obj);
   static void	insert_obj(struct bsdar *bsdar, struct ar_obj *obj,
   		    struct ar_obj *pos);
  +static void	prefault_buffer(const char *buf, size_t s);
   static void	read_objs(struct bsdar *bsdar, const char *archive,
   		    int checkargv);
   static void	write_archive(struct bsdar *bsdar, char mode);
  @@ -551,11 +553,29 @@
   }
   
   /*
  + * Fault in the buffer prior to writing as a workaround for poor performance
  + * due to interaction with kernel fs deadlock avoidance code. See the comment
  + * prior to vn_io_fault_doio() in vfs_vnops.c for details of the issue.
  + */
  +static void
  +prefault_buffer(const char *buf, size_t s)
  +{
  +	volatile const char *p;
  +	size_t page_size;
  +
  +	page_size = sysconf(_SC_PAGESIZE);
  +	for (p = buf; p < buf + s;
  +	    p += page_size - ((uintptr_t)p & page_size - 1))
  +		*p;
  +}
  +
  +/*
    * Wrapper for archive_write_data().
    */
   static void
   write_data(struct bsdar *bsdar, struct archive *a, const void *buf, size_t s)
   {
  +	prefault_buffer(buf, s);
   	if (archive_write_data(a, buf, s) != (ssize_t)s)
   		bsdar_errc(bsdar, EX_SOFTWARE, 0, "%s",
   		    archive_error_string(a));

EMAIL PREFERENCES
  https://reviews.freebsd.org/settings/panel/emailpreferences/

To: emaste, kib
Cc: kib, freebsd-toolchain-list, dim, davide

--b1_6a703d38f4991d5770a85cd3a93d4c9e
Content-Type: text/x-patch; charset=utf-8; name="D2933.6524.patch"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="D2933.6524.patch"

ZGlmZiAtLWdpdCBhL3Vzci5iaW4vYXIvd3JpdGUuYyBiL3Vzci5iaW4vYXIvd3JpdGUuYwotLS0g
YS91c3IuYmluL2FyL3dyaXRlLmMKKysrIGIvdXNyLmJpbi9hci93cml0ZS5jCkBAIC00MSw2ICs0
MSw3IEBACiAjaW5jbHVkZSA8c3RkbGliLmg+CiAjaW5jbHVkZSA8c3RyaW5nLmg+CiAjaW5jbHVk
ZSA8c3lzZXhpdHMuaD4KKyNpbmNsdWRlIDx1b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gc3lzY29uZihfU0NfUEFHRVNJWkUpOworCWZvciAo
cCA9IGJ1ZjsgcCA8IGJ1ZiArIHM7CisJICAgIHAgKz0gcGFnZV9zaXplIC0gKCh1aW50cHRyX3Qp
cCAmIHBhZ2Vfc2l6ZSAtIDEpKQorCQkqcDsKK30KKworLyoKICAqIFdyYXBwZXIgZm9yIGFyY2hp
dmVfd3JpdGVfZGF0YSgpLgogICovCiBzdGF0aWMgdm9pZAogd3JpdGVfZGF0YShzdHJ1Y3QgYnNk
YXIgKmJzZGFyLCBzdHJ1Y3QgYXJjaGl2ZSAqYSwgY29uc3Qgdm9pZCAqYnVmLCBzaXplX3QgcykK
IHsKKwlwcmVmYXVsdF9idWZmZXIoYnVmLCBzKTsKIAlpZiAoYXJjaGl2ZV93cml0ZV9kYXRhKGEs
IGJ1ZiwgcykgIT0gKHNzaXplX3QpcykKIAkJYnNkYXJfZXJyYyhic2RhciwgRVhfU09GVFdBUkUs
IDAsICIlcyIsCiAJCSAgICBhcmNoaXZlX2Vycm9yX3N0cmluZyhhKSk7Cgo=


--b1_6a703d38f4991d5770a85cd3a93d4c9e--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?differential-rev-PHID-DREV-hkid5hylfsbts6yuvnph-req>