]> git.ipfire.org Git - thirdparty/git.git/commitdiff
xmmap: inform Linux users of tuning knobs on ENOMEM
authorEric Wong <e@80x24.org>
Wed, 30 Jun 2021 00:01:32 +0000 (00:01 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Jun 2021 06:14:25 +0000 (23:14 -0700)
Linux users may benefit from additional information on how to
avoid ENOMEM from mmap despite the system having enough RAM to
accomodate them.  We can't reliably unmap pack windows to work
around the issue since malloc and other library routines may
mmap without our knowledge.

Signed-off-by: Eric Wong <e@80x24.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
config.c
git-compat-util.h
object-file.c
packfile.c
read-cache.c

index f9c400ad3062d9953142d6a2f9c4b357962c48c7..79ae9f2dea3e8d77f093b885549151fb8c5a2566 100644 (file)
--- a/config.c
+++ b/config.c
@@ -3051,7 +3051,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;
index fb6e9af76b4fe60572fe8f3a2615329e087e2b88..fa6dd9221902fabf84035c295b7fdfc0bb022a10 100644 (file)
@@ -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);
index f233b440b22c061cbdac1db019b1e8b58c093324..b9c3219793f8666c2578b328cd4a1c806dae3c7a 100644 (file)
@@ -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;
 }
 
index 755aa7aec5efbfe4191a7aba32cfe0a4afab4956..9ef6d98292808718dfadc3b9efec0fb0dc2275f5 100644 (file)
@@ -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);
index 77961a38854069850829a7fecd8be5dc1e2f7b62..a80902155c7e86f93e87c4eec7e7b3e55b5c3567 100644 (file)
@@ -2236,7 +2236,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;