Skip to content

Commit 4b510c3

Browse files
committed
Merge branch 'sp/clip-read-write-to-8mb' into maint
Send a large request to read(2)/write(2) as a smaller but still reasonably large chunks, which would improve the latency when the operation needs to be killed and incidentally works around broken 64-bit systems that cannot take a 2GB write or read in one go. * sp/clip-read-write-to-8mb: Revert "compat/clipped-write.c: large write(2) fails on Mac OS X/XNU" xread, xwrite: limit size of IO to 8MB
2 parents 19230ab + a487916 commit 4b510c3

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ all::
6969
# Define NO_MSGFMT_EXTENDED_OPTIONS if your implementation of msgfmt
7070
# doesn't support GNU extensions like --check and --statistics
7171
#
72-
# Define NEEDS_CLIPPED_WRITE if your write(2) cannot write more than
73-
# INT_MAX bytes at once (e.g. MacOS X).
74-
#
7572
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
7673
# it specifies.
7774
#
@@ -1493,11 +1490,6 @@ ifndef NO_MSGFMT_EXTENDED_OPTIONS
14931490
MSGFMT += --check --statistics
14941491
endif
14951492

1496-
ifdef NEEDS_CLIPPED_WRITE
1497-
BASIC_CFLAGS += -DNEEDS_CLIPPED_WRITE
1498-
COMPAT_OBJS += compat/clipped-write.o
1499-
endif
1500-
15011493
ifneq (,$(XDL_FAST_HASH))
15021494
BASIC_CFLAGS += -DXDL_FAST_HASH
15031495
endif

compat/clipped-write.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

config.mak.uname

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ ifeq ($(uname_S),Darwin)
9595
NO_MEMMEM = YesPlease
9696
USE_ST_TIMESPEC = YesPlease
9797
HAVE_DEV_TTY = YesPlease
98-
NEEDS_CLIPPED_WRITE = YesPlease
9998
COMPAT_OBJS += compat/precompose_utf8.o
10099
BASIC_CFLAGS += -DPRECOMPOSE_UNICODE
101100
endif

git-compat-util.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ typedef unsigned long uintptr_t;
185185
#define probe_utf8_pathname_composition(a,b)
186186
#endif
187187

188-
#ifdef NEEDS_CLIPPED_WRITE
189-
ssize_t clipped_write(int fildes, const void *buf, size_t nbyte);
190-
#define write(x,y,z) clipped_write((x),(y),(z))
191-
#endif
192-
193188
#ifdef MKDIR_WO_TRAILING_SLASH
194189
#define mkdir(a,b) compat_mkdir_wo_trailing_slash((a),(b))
195190
extern int compat_mkdir_wo_trailing_slash(const char*, mode_t);

t/t0021-conversion.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,18 @@ test_expect_success 'required filter clean failure' '
190190
test_must_fail git add test.fc
191191
'
192192

193+
test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
194+
195+
test_expect_success EXPENSIVE 'filter large file' '
196+
git config filter.largefile.smudge cat &&
197+
git config filter.largefile.clean cat &&
198+
for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB &&
199+
echo "2GB filter=largefile" >.gitattributes &&
200+
git add 2GB 2>err &&
201+
! test -s err &&
202+
rm -f 2GB &&
203+
git checkout -- 2GB 2>err &&
204+
! test -s err
205+
'
206+
193207
test_done

wrapper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ void *xcalloc(size_t nmemb, size_t size)
130130
return ret;
131131
}
132132

133+
/*
134+
* Limit size of IO chunks, because huge chunks only cause pain. OS X
135+
* 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in
136+
* the absense of bugs, large chunks can result in bad latencies when
137+
* you decide to kill the process.
138+
*/
139+
#define MAX_IO_SIZE (8*1024*1024)
140+
133141
/*
134142
* xread() is the same a read(), but it automatically restarts read()
135143
* operations with a recoverable error (EAGAIN and EINTR). xread()
@@ -138,6 +146,8 @@ void *xcalloc(size_t nmemb, size_t size)
138146
ssize_t xread(int fd, void *buf, size_t len)
139147
{
140148
ssize_t nr;
149+
if (len > MAX_IO_SIZE)
150+
len = MAX_IO_SIZE;
141151
while (1) {
142152
nr = read(fd, buf, len);
143153
if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
@@ -154,6 +164,8 @@ ssize_t xread(int fd, void *buf, size_t len)
154164
ssize_t xwrite(int fd, const void *buf, size_t len)
155165
{
156166
ssize_t nr;
167+
if (len > MAX_IO_SIZE)
168+
len = MAX_IO_SIZE;
157169
while (1) {
158170
nr = write(fd, buf, len);
159171
if ((nr < 0) && (errno == EAGAIN || errno == EINTR))

0 commit comments

Comments
 (0)