diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2016-03-09 11:16:16 +0100 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-03-09 11:16:16 +0100 |
commit | d50fd57174f98b7786a5d2ae13df5d98b07e81ee (patch) | |
tree | 4e19835a3cb757961b43dba9351da390b43e7efc /src | |
parent | c68044a8797d6eac5c8468dd5bec53d07b3ad66c (diff) | |
download | libgit2-d50fd57174f98b7786a5d2ae13df5d98b07e81ee.tar.gz |
mwindow: free unused windows if we fail to mmapcmn/mwindow-try-harder
The first time may be due to memory fragmentation or just bad luck on a
32-bit system. When we hit the mmap error for the first time, free up
the unused windows and try again.
Diffstat (limited to 'src')
-rw-r--r-- | src/mwindow.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/mwindow.c b/src/mwindow.c index 55c8d894b..d3e9be78b 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -296,8 +296,18 @@ static git_mwindow *new_window( */ if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) { - git__free(w); - return NULL; + /* + * The first error might be down to memory fragmentation even if + * we're below our soft limits, so free up what we can and try again. + */ + + while (git_mwindow_close_lru(mwf) == 0) + /* nop */; + + if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < 0) { + git__free(w); + return NULL; + } } ctl->mmap_calls++; |