New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GC mwindows on too many open files #2758
Comments
I believe we're hitting this in Cargo as well. We're using an index on GitHub which has lots of little files and lots of updates over time. Sometimes when we do a git update of the repository it causes a huge number of file descriptors to get opened, often reaching close to the system limit or blowing the system limit. In tracking this down I found that this program is all that's needed to trigger the behavior, namely starting a revwalk that looks at the repository. I believe this is internally done during the fetch operation for smart transports. Notably, though, I ran Out of curiosity, is there something we should be doing in Cargo to mitigate this issue? I'm gonna go run |
We have the same issue here and it's causing a lot of problems. However we are unable to depend on git being available locally (hence using libgit2) to perform gc. Are there other suggested workarounds? |
I just this this as well (I believe), and I have the same issue as @tommoor; I can't necessarily rely on git being available locally to run |
We had to abandon libgit2 unfortunately. We've rewritten in go-git – I'm sure that's not the answer you were hoping for 😞 |
If you can do it from a licensing POV I'd recommend bundling the vanilla git binary with your application, it's much faster than both libgit2 and go-git and worth the extra weight if you ask me. Even github desktop bundles it. |
It's worse than I thought. Even bundling vanilla git won't suffice, for a long-running process. Watching |
It looks like the fix is may be as simple as: diff --git a/src/mwindow.c b/src/mwindow.c
index 262786a5f..ccb24bdd8 100644
--- a/src/mwindow.c
+++ b/src/mwindow.c
@@ -271,6 +271,9 @@ static git_mwindow *new_window(
while (git_mwindow__mapped_limit < ctl->mapped &&
git_mwindow_close_lru(mwf) == 0) /* nop */;
+ while (ctl->open_windows > 20 &&
+ git_mwindow_close_lru(mwf) == 0) /* nop */;
+
/*
* We treat `mapped_limit` as a soft limit. If we can't find a
* window to close and are above the limit, we still mmap the new Obviously the limit needs to be made configurable. I'll see about putting together a PR. Feedback welcomed in the interim. |
Doing many network operations can lead to lots of small packfiles. The existing mwindow limit was only the total size of mmap'd files, not on their number, so having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low. Add a limit to the number of files as well as their total size, and set the default limit low enough that even macOS users should not hit it during normal use. Fixes libgit2#2758
Doing many network operations can lead to lots of small packfiles. The existing mwindow limit was only the total size of mmap'd files, not on their number, so having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low. Add a limit to the number of files as well as their total size, and set the default limit low enough that even macOS users should not hit it during normal use. Fixes libgit2#2758
PR is #5386. |
Doing many network operations can lead to lots of small packfiles. The existing mwindow limit was only the total size of mmap'd files, not on their number, so having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low. Add a limit to the number of files as well as their total size, and set the default limit low enough that even macOS users should not hit it during normal use. Fixes libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
There are some cases in which repositories accrue a large number of packfiles. The existing mwindow limit applies only to the total size of mmap'd files, not on their number. This leads to a situation in which having lots of small packfiles could exhaust the allowed number of open files, particularly on macOS, where the default ulimit is very low (256). This change adds a new configuration parameter (GIT_OPT_SET_MWINDOW_FILE_LIMIT) that sets the maximum number of open packfiles, with a default of 128. This is low enough so that even macOS users should not hit it during normal use. Based on PR libgit2#5386, originally written by @josharian. Fixes: libgit2#2758
We currently attempt to free unused map windows for packfiles when we go over a threshold. We however do not account for the number of open packfiles.
There's been at least two distinct reports of people running into issues when they have repositories which do network operations in small batches. These accumulate a lot of tiny packfiles and we end up having them all open at once, which can reach the system's limit for open file descriptors.
We should have a configurable limit on how many open file descriptors we want to have for packfiles and do a soft-GC similar to what we do for memory (address space).
The text was updated successfully, but these errors were encountered: