xmmap: inform Linux users of tuning knobs on ENOMEM

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>
This commit is contained in:
Eric Wong
2021-06-30 00:01:32 +00:00
committed by Junio C Hamano
parent 670b81a890
commit dc05929411
5 changed files with 22 additions and 5 deletions

View 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;
}