From: Joey Hess <id@joeyh.name>
To: Jeff King <peff@peff.net>
Cc: git <git@vger.kernel.org>
Subject: [PATCH] avoid unncessary malloc of whole file size
Date: Thu, 24 Jan 2019 16:36:39 -0400 [thread overview]
Message-ID: <20190124203639.GA17595@kitenet.net> (raw)
In-Reply-To: <20190124191836.GA31073@sigill.intra.peff.net>
When a worktree file is larger than the available memory, and a clean
filter is in use, this avoids mallocing a buffer the whole size of the
file when reading from the clean filter, which caused commands like git
status and git commit to OOM.
Often in this situation the clean filter will produce a short identifier
for the file, so such a large buffer is not needed.
When the clean filter does output something around the same size as the
worktree file, the buffer will need to be reallocated until it fits,
starting at 8192 and doubling in size. Benchmarking indicates that
reallocation is not a significant overhead for outputs up to a
few MB in size.
Signed-off-by: Joey Hess <id@joeyh.name>
---
convert.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/convert.c b/convert.c
index 0d89ae7c23..85aebe2ed3 100644
--- a/convert.c
+++ b/convert.c
@@ -732,7 +732,7 @@ static int apply_single_file_filter(const char *path, const char *src, size_t le
if (start_async(&async))
return 0; /* error was already reported */
- if (strbuf_read(&nbuf, async.out, len) < 0) {
+ if (strbuf_read(&nbuf, async.out, 0) < 0) {
err = error(_("read from external filter '%s' failed"), cmd);
}
if (close(async.out)) {
--
2.20.1
next prev parent reply other threads:[~2019-01-24 20:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-22 22:07 git status OOM on mmap of large file Joey Hess
2019-01-24 0:39 ` brian m. carlson
2019-01-24 12:14 ` Jeff King
2019-01-24 17:05 ` Joey Hess
2019-01-24 12:10 ` Jeff King
2019-01-24 12:54 ` Duy Nguyen
2019-01-24 18:38 ` Joey Hess
2019-01-24 19:18 ` Jeff King
2019-01-24 19:28 ` Jeff King
2019-01-24 20:36 ` Joey Hess [this message]
2019-01-24 21:12 ` [PATCH] avoid unncessary malloc of whole file size Junio C Hamano
2019-01-24 21:18 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190124203639.GA17595@kitenet.net \
--to=id@joeyh.name \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).