diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2019-11-13 17:40:10 +0100 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-11-13 17:44:29 +0100 |
commit | ecdbb0c79d9274a04a1da9efd429c1c88fe9bd9a (patch) | |
tree | a356155806928ffca8d6120a6abad4008083ee6b | |
parent | 817767a385c083b672be3d3f72ad619719254d2d (diff) | |
download | l2md-ecdbb0c79d9274a04a1da9efd429c1c88fe9bd9a.tar.gz |
l2md: bump open file limit for repos with lots of pack files
Bump the limit to avoid bailing out in git_revwalk_next() without
having walked any commits. This happens when the repo has a lot of
pack files where we otherwise surpass the open file limit with the
default.
Ideally doing an equivalent of ...
git repack -a -d -f --depth=250 --window=250
... out of libgit2 would be best and solve this issue, but given
GH issue [0], it's not there yet (if ever).
[0] https://github.com/libgit2/libgit2/issues/3247
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | config.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -8,6 +8,8 @@ #include <wordexp.h> #include <stdbool.h> +#include <sys/resource.h> + #include "l2md.h" enum { @@ -153,6 +155,31 @@ static void config_set_defaults(struct config *cfg, const char *homedir) cfg->ops->set_defaults(cfg); } +static void config_ulimits(void) +{ + struct rlimit limit; + int ret; + + ret = getrlimit(RLIMIT_NOFILE, &limit); + if (ret < 0) + panic("Cannot retrieve rlimit!\n"); + + /* The git repos we're dealing with can have a lot of + * pack files potentially, hence increase open file limit + * to help libgit2's revwalk. + * + * If there is a better API supported by native libgit2 + * for doing repack, we should use that instead: + * + * https://github.com/libgit2/libgit2/issues/3247 + */ + limit.rlim_cur = limit.rlim_max; + + ret = setrlimit(RLIMIT_NOFILE, &limit); + if (ret < 0) + panic("Cannot set rlimit!\n"); +} + void config_uninit(struct config *cfg) { struct config_repo *repo; @@ -190,6 +217,8 @@ struct config *config_init(int argc, char **argv) if (!fp) panic("Cannot open config %s: %s\n", tmp, strerror(errno)); + config_ulimits(); + cfg = xzmalloc(sizeof(*cfg)); config_set_defaults(cfg, homedir); |