summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2021-07-17 00:42:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-17 00:42:47 (GMT)
commita93c6fd677f16285ce1109f9f200b2b235ab981e (patch)
treef41a55ef2d736a19648bed510aa9ff8cdee40aee
parentfba551379ef89b92b9356caa4096144026250c22 (diff)
parentdc0592941138df684770bfe800ccad6b810214c3 (diff)
downloadgit-a93c6fd677f16285ce1109f9f200b2b235ab981e.zip
git-a93c6fd677f16285ce1109f9f200b2b235ab981e.tar.gz
git-a93c6fd677f16285ce1109f9f200b2b235ab981e.tar.bz2
Merge branch 'ew/mmap-failures'
Error message update. * ew/mmap-failures: xmmap: inform Linux users of tuning knobs on ENOMEM
-rw-r--r--config.c3
-rw-r--r--git-compat-util.h1
-rw-r--r--object-file.c16
-rw-r--r--packfile.c4
-rw-r--r--read-cache.c3
5 files changed, 22 insertions, 5 deletions
diff --git a/config.c b/config.c
index 3cd10ae..55313fc 100644
--- a/config.c
+++ b/config.c
@@ -3052,7 +3052,8 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
if (contents == MAP_FAILED) {
if (errno == ENODEV && S_ISDIR(st.st_mode))
errno = EISDIR;
- error_errno(_("unable to mmap '%s'"), config_filename);
+ error_errno(_("unable to mmap '%s'%s"),
+ config_filename, mmap_os_err());
ret = CONFIG_INVALID_FILE;
contents = NULL;
goto out_free;
diff --git a/git-compat-util.h b/git-compat-util.h
index dca72cb..b466053 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -876,6 +876,7 @@ char *xstrndup(const char *str, size_t len);
void *xrealloc(void *ptr, size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
+const char *mmap_os_err(void);
void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);
int xopen(const char *path, int flags, ...);
ssize_t xread(int fd, void *buf, size_t len);
diff --git a/object-file.c b/object-file.c
index f233b44..b9c3219 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1023,12 +1023,26 @@ void *xmmap_gently(void *start, size_t length,
return ret;
}
+const char *mmap_os_err(void)
+{
+ static const char blank[] = "";
+#if defined(__linux__)
+ if (errno == ENOMEM) {
+ /* this continues an existing error message: */
+ static const char enomem[] =
+", check sys.vm.max_map_count and/or RLIMIT_DATA";
+ return enomem;
+ }
+#endif /* OS-specific bits */
+ return blank;
+}
+
void *xmmap(void *start, size_t length,
int prot, int flags, int fd, off_t offset)
{
void *ret = xmmap_gently(start, length, prot, flags, fd, offset);
if (ret == MAP_FAILED)
- die_errno(_("mmap failed"));
+ die_errno(_("mmap failed%s"), mmap_os_err());
return ret;
}
diff --git a/packfile.c b/packfile.c
index 755aa7a..9ef6d98 100644
--- a/packfile.c
+++ b/packfile.c
@@ -652,8 +652,8 @@ unsigned char *use_pack(struct packed_git *p,
PROT_READ, MAP_PRIVATE,
p->pack_fd, win->offset);
if (win->base == MAP_FAILED)
- die_errno("packfile %s cannot be mapped",
- p->pack_name);
+ die_errno(_("packfile %s cannot be mapped%s"),
+ p->pack_name, mmap_os_err());
if (!win->offset && win->len == p->pack_size
&& !p->do_not_close)
close_pack_fd(p);
diff --git a/read-cache.c b/read-cache.c
index 0c3ac3c..ba2b012 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2233,7 +2233,8 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
mmap = xmmap_gently(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (mmap == MAP_FAILED)
- die_errno(_("%s: unable to map index file"), path);
+ die_errno(_("%s: unable to map index file%s"), path,
+ mmap_os_err());
close(fd);
hdr = (const struct cache_header *)mmap;