Date: Mon, 29 Jun 2015 13:14:12 +0000 From: "emaste (Ed Maste)" <phabric-noreply@FreeBSD.org> To: freebsd-toolchain@freebsd.org Subject: [Differential] [Updated, 26 lines] D2933: Significantly speed up ar(1) on UFS file systems Message-ID: <a222931c107847e855b5d47d28ef7204@localhost.localdomain> In-Reply-To: <differential-rev-PHID-DREV-hkid5hylfsbts6yuvnph-req@FreeBSD.org> References: <differential-rev-PHID-DREV-hkid5hylfsbts6yuvnph-req@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--b1_a222931c107847e855b5d47d28ef7204 Content-Type: text/plain; charset = "utf-8" Content-Transfer-Encoding: 8bit emaste updated this revision to Diff 6543. emaste added a comment. This revision now requires review to proceed. - give full path to file with comment explaining the deadlock avoidance - avoid confusing page mask manipulation and just touch the last byte explicitly CHANGES SINCE LAST UPDATE https://reviews.freebsd.org/D2933?vs=6524&id=6543 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,35 @@ } /* + * 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)); EMAIL PREFERENCES https://reviews.freebsd.org/settings/panel/emailpreferences/ To: emaste, kib, eadler Cc: kib, freebsd-toolchain-list, dim, davide --b1_a222931c107847e855b5d47d28ef7204 Content-Type: text/x-patch; charset=utf-8; name="D2933.6543.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="D2933.6543.patch" ZGlmZiAtLWdpdCBhL3Vzci5iaW4vYXIvd3JpdGUuYyBiL3Vzci5iaW4vYXIvd3JpdGUuYwotLS0g YS91c3IuYmluL2FyL3dyaXRlLmMKKysrIGIvdXNyLmJpbi9hci93cml0ZS5jCkBAIC00MSw2ICs0 MSw3IEBACiAjaW5jbHVkZSA8c3RkbGliLmg+CiAjaW5jbHVkZSA8c3RyaW5nLmg+CiAjaW5jbHVk ZSA8c3lzZXhpdHMuaD4KKyNpbmNsdWRlIDx1bmlzdGQuaD4KIAogI2luY2x1ZGUgImFyLmgiCiAK QEAgLTYxLDYgKzYyLDcgQEAKIHN0YXRpYyB2b2lkCWZyZWVfb2JqKHN0cnVjdCBic2RhciAqYnNk YXIsIHN0cnVjdCBhcl9vYmogKm9iaik7CiBzdGF0aWMgdm9pZAlpbnNlcnRfb2JqKHN0cnVjdCBi c2RhciAqYnNkYXIsIHN0cnVjdCBhcl9vYmogKm9iaiwKIAkJICAgIHN0cnVjdCBhcl9vYmogKnBv cyk7CitzdGF0aWMgdm9pZAlwcmVmYXVsdF9idWZmZXIoY29uc3QgY2hhciAqYnVmLCBzaXplX3Qg cyk7CiBzdGF0aWMgdm9pZAlyZWFkX29ianMoc3RydWN0IGJzZGFyICpic2RhciwgY29uc3Qg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IHdy aXRlX2RhdGEoc3RydWN0IGJzZGFyICpic2Rhciwgc3RydWN0IGFyY2hpdmUgKmEsIGNvbnN0IHZv aWQgKmJ1Ziwgc2l6ZV90IHMpCiB7CisJcHJlZmF1bHRfYnVmZmVyKGJ1Ziwgcyk7CiAJaWYgKGFy Y2hpdmVfd3JpdGVfZGF0YShhLCBidWYsIHMpICE9IChzc2l6ZV90KXMpCiAJCWJzZGFyX2VycmMo YnNkYXIsIEVYX1NPRlRXQVJFLCAwLCAiJXMiLAogCQkgICAgYXJjaGl2ZV9lcnJvcl9zdHJpbmco YSkpOwoK --b1_a222931c107847e855b5d47d28ef7204--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a222931c107847e855b5d47d28ef7204>