Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Buffer Allocation using mmap

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?

like image 779
Nordlöw Avatar asked Jun 13 '11 08:06

Nordlöw


2 Answers

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?

like image 102
janneb Avatar answered Oct 03 '22 06:10

janneb


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

like image 29
Yannick Versley Avatar answered Oct 03 '22 08:10

Yannick Versley