9

Why is mmap buffer allocation activated by default on cygwin, freebsd and irix6-5 but not on linux?

See USE_MMAP_FOR_BUFFERS in emacs/src/config.h. and use_mmap_for_buffers in emacs/configure.in.

Isn't mmap based access superior to normal buffer allocation?

Nordlöw
  • 11,838
  • 10
  • 52
  • 99

2 Answers2

6

The default glibc malloc() uses mmap for large allocations; From the malloc(3) manpage. "When allocating blocks of memory larger than MMAP_THRESHOLD bytes, the glibc malloc() implementation allocates the memory as a private anonymous mapping using mmap(2). MMAP_THRESHOLD is 128 kB by default, but is adjustable using mallopt(3)."

Perhaps switching to mmap on those other platforms is to work around poor malloc() implementations that don't do it themselves?

janneb
  • 36,249
  • 2
  • 81
  • 97
  • 1
    But how can malloc be a replacement for mmap? mmap maps file fd to memory but malloc just allocates memory not related to any file (descriptor). – Nordlöw Jun 13 '11 at 14:23
  • 2
    @Nordlöw: See the "private anonymous mapping" part from what I quoted above. That is, the flags argument to mmap(2) is MAP_PRIVATE|MAP_ANONYMOUS. See the mmap(2) man page for more info. – janneb Jun 13 '11 at 15:04
2

mmap() allocation is easier to realize in a threadsafe fashion, but brk() allocation is about 10% slower on Linux. See this question.

Community
  • 1
  • 1
Yannick Versley
  • 780
  • 3
  • 10