Skip to content

Commit 412e4ca

Browse files
Eric Wonggitster
authored andcommitted
tests: disable fsync everywhere
The "GIT_TEST_FSYNC" environment variable now exists for disabling fsync() even on packfiles and other "critical" data. Running "make test -j8 NO_SVN_TESTS=1" on a noisy 8-core system on an HDD, test runtime drops from ~4 minutes down to ~3 minutes. Using "GIT_TEST_FSYNC=1" re-enables fsync() for comparison purposes. SVN interopability tests are minimally affected since SVN will still use fsync in various places. This will also be useful for 3rd-party tools which create throwaway git repositories of temporary data, but remains undocumented for end users. Signed-off-by: Eric Wong <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af6d1d6 commit 412e4ca

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,7 @@ extern int read_replace_refs;
985985
extern char *git_replace_ref_base;
986986

987987
extern int fsync_object_files;
988+
extern int use_fsync;
988989
extern int core_preload_index;
989990
extern int precomposed_unicode;
990991
extern int protect_hfs;

environment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const char *git_hooks_path;
4343
int zlib_compression_level = Z_BEST_SPEED;
4444
int pack_compression_level = Z_DEFAULT_COMPRESSION;
4545
int fsync_object_files;
46+
int use_fsync = -1;
4647
size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
4748
size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
4849
size_t delta_base_cache_limit = 96 * 1024 * 1024;

git-cvsserver.perl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,6 +3607,22 @@ package GITCVS::updater;
36073607
use strict;
36083608
use warnings;
36093609
use DBI;
3610+
our $_use_fsync;
3611+
3612+
# n.b. consider using Git.pm
3613+
sub use_fsync {
3614+
if (!defined($_use_fsync)) {
3615+
my $x = $ENV{GIT_TEST_FSYNC};
3616+
if (defined $x) {
3617+
local $ENV{GIT_CONFIG};
3618+
delete $ENV{GIT_CONFIG};
3619+
my $v = ::safe_pipe_capture('git', '-c', "test.fsync=$x",
3620+
qw(config --type=bool test.fsync));
3621+
$_use_fsync = defined($v) ? ($v eq "true\n") : 1;
3622+
}
3623+
}
3624+
$_use_fsync;
3625+
}
36103626

36113627
=head1 METHODS
36123628
@@ -3676,6 +3692,9 @@ sub new
36763692
$self->{dbuser},
36773693
$self->{dbpass});
36783694
die "Error connecting to database\n" unless defined $self->{dbh};
3695+
if ($self->{dbdriver} eq 'SQLite' && !use_fsync()) {
3696+
$self->{dbh}->do('PRAGMA synchronous = OFF');
3697+
}
36793698

36803699
$self->{tables} = {};
36813700
foreach my $table ( keys %{$self->{dbh}->table_info(undef,undef,undef,'TABLE')->fetchall_hashref('TABLE_NAME')} )

perl/Git/SVN.pm

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use constant rev_map_fmt => 'NH*';
66
use vars qw/$_no_metadata
77
$_repack $_repack_flags $_use_svm_props $_head
88
$_use_svnsync_props $no_reuse_existing
9-
$_use_log_author $_add_author_from $_localtime/;
9+
$_use_log_author $_add_author_from $_localtime $_use_fsync/;
1010
use Carp qw/croak/;
1111
use File::Path qw/mkpath/;
1212
use IPC::Open3;
@@ -2269,6 +2269,19 @@ sub mkfile {
22692269
}
22702270
}
22712271

2272+
# TODO: move this to Git.pm?
2273+
sub use_fsync {
2274+
if (!defined($_use_fsync)) {
2275+
my $x = $ENV{GIT_TEST_FSYNC};
2276+
if (defined $x) {
2277+
my $v = command_oneline('-c', "test.fsync=$x",
2278+
qw(config --type=bool test.fsync));
2279+
$_use_fsync = defined($v) ? ($v eq "true\n") : 1;
2280+
}
2281+
}
2282+
$_use_fsync;
2283+
}
2284+
22722285
sub rev_map_set {
22732286
my ($self, $rev, $commit, $update_ref, $uuid) = @_;
22742287
defined $commit or die "missing arg3\n";
@@ -2290,7 +2303,7 @@ sub rev_map_set {
22902303
my $sync;
22912304
# both of these options make our .rev_db file very, very important
22922305
# and we can't afford to lose it because rebuild() won't work
2293-
if ($self->use_svm_props || $self->no_metadata) {
2306+
if (($self->use_svm_props || $self->no_metadata) && use_fsync()) {
22942307
require File::Copy;
22952308
$sync = 1;
22962309
File::Copy::copy($db, $db_lock) or die "rev_map_set(@_): ",

t/test-lib.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ then
489489
export GIT_PERL_FATAL_WARNINGS
490490
fi
491491

492+
case $GIT_TEST_FSYNC in
493+
'')
494+
GIT_TEST_FSYNC=0
495+
export GIT_TEST_FSYNC
496+
;;
497+
esac
498+
492499
# Add libc MALLOC and MALLOC_PERTURB test
493500
# only if we are not executing the test with valgrind
494501
if test -n "$valgrind" ||

write-or-die.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "cache.h"
2+
#include "config.h"
23
#include "run-command.h"
34

45
/*
@@ -57,6 +58,10 @@ void fprintf_or_die(FILE *f, const char *fmt, ...)
5758

5859
void fsync_or_die(int fd, const char *msg)
5960
{
61+
if (use_fsync < 0)
62+
use_fsync = git_env_bool("GIT_TEST_FSYNC", 1);
63+
if (!use_fsync)
64+
return;
6065
while (fsync(fd) < 0) {
6166
if (errno != EINTR)
6267
die_errno("fsync error on '%s'", msg);

0 commit comments

Comments
 (0)