From owner-svn-src-all@freebsd.org Mon Jun 29 17:21:35 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 395499907E1; Mon, 29 Jun 2015 17:21:35 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: from mail-ie0-x233.google.com (mail-ie0-x233.google.com [IPv6:2607:f8b0:4001:c03::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0F31912E8; Mon, 29 Jun 2015 17:21:35 +0000 (UTC) (envelope-from adrian.chadd@gmail.com) Received: by iebmu5 with SMTP id mu5so119498506ieb.1; Mon, 29 Jun 2015 10:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=a9+v/4t7TxYEZul2NVu9Lldfk0wUuaXfDfQh6tRz9wM=; b=vUWjVT/Z+L/MefQQDj4Bn+mRztD2b1qbpzctaduM3eHCdixKF1WJAAA7E7SzCLuHRf glk7gxY/BFOicTFCLYFSI3z6w2CSk3ergLQwT3eKTF6+WGlWnJRGz46levxepNdRGV8t Nh80iKU8mRiIz3CO8zRghA0EMYQfMoIBFIHK/E0PonszC/dr7+fHQ39rwMPK0P4G4YIn KXrRrODG7RfN+Vi8fkdAXvuGtvJuOwpPbzlp7TdbAHfekKvfkGz77cFFlULB97wgbLGL j1TSUoo6h6kj+kjSZ46EK8Iph1HvoRmXMhi/yt80X+iePvEz+8Ikn60ZStZ4ayK7m+tz 5y2w== MIME-Version: 1.0 X-Received: by 10.107.155.74 with SMTP id d71mr21968361ioe.29.1435598494468; Mon, 29 Jun 2015 10:21:34 -0700 (PDT) Received: by 10.36.38.133 with HTTP; Mon, 29 Jun 2015 10:21:34 -0700 (PDT) In-Reply-To: <201506291348.t5TDmiZG039322@svn.freebsd.org> References: <201506291348.t5TDmiZG039322@svn.freebsd.org> Date: Mon, 29 Jun 2015 10:21:34 -0700 Message-ID: Subject: Re: svn commit: r284928 - head/usr.bin/ar From: Adrian Chadd To: Ed Maste Cc: "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2015 17:21:35 -0000 Is this potentially an issue for other applications? Why is it such a big issue for ar? -a On 29 June 2015 at 06:48, Ed Maste wrote: > Author: emaste > Date: Mon Jun 29 13:48:44 2015 > New Revision: 284928 > URL: https://svnweb.freebsd.org/changeset/base/284928 > > Log: > speed up ar(1) on UFS file systems > > Fault in the buffer prior to writing to workaround poor performance due > to interaction with kernel fs deadlock avoidance code. See the comment > prior to vn_io_fault_doio() in sys/kern/vfs_vnops.c for details of the > issue. > > On my stable/10 desktop with a 16MB obj.o and "ar r out.a obj.o" I see > the following run times (seconds): > > 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.020 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) > > Thanks to kib for diagnosing and explaining the issue and suggesting > the workaround. > > Reviewed by: eadler, kib > MFC after: 1 week > Sponsored by: The FreeBSD Foundation > Differential Revision: https://reviews.freebsd.org/D2933 > > Modified: > head/usr.bin/ar/write.c > > Modified: head/usr.bin/ar/write.c > ============================================================================== > --- head/usr.bin/ar/write.c Mon Jun 29 13:06:24 2015 (r284927) > +++ head/usr.bin/ar/write.c Mon Jun 29 13:48:44 2015 (r284928) > @@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$"); > #include > #include > #include > +#include > > #include "ar.h" > > @@ -61,6 +62,7 @@ static void create_symtab_entry(struct b > 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,35 @@ write_cleanup(struct bsdar *bsdar) > } > > /* > + * 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 > + * above vn_io_fault_doio() in sys/kern/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; > + > + if (s == 0) > + return; > + page_size = sysconf(_SC_PAGESIZE); > + for (p = buf; p < buf + s; p += page_size) > + *p; > + /* > + * Ensure we touch the last page as well, in case the buffer is not > + * page-aligned. > + */ > + *(volatile const char *)(buf + s - 1); > +} > + > +/* > * 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)); >