libc - Improve realloc() performance.
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 17 Feb 2016 04:40:44 +0000 (20:40 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 17 Feb 2016 17:35:48 +0000 (09:35 -0800)
commit07a8ffeaab3fc830679c6836a6ee198ad1a3275f
tree6ae58378499fcfa554851652be1f260ee3f3f05b
parenta2a57c243ff8016578bc559f8603fb25bbcf1768
libc - Improve realloc() performance.

* Oversized free()'s <= 1MB will be cached in a 16-entry array.  Any oversized
  allocation can make use of the cache, even if available cache entries are
  significantly larger than desired, in order to accomodate application
  buffer-growing behavior.  This means that applications which realloc() a
  lot (at least as long as the buffer is <= 1MB) will wind up being handed
  a ~1MB buffer quite frequently, eliminating new mmap() operations.

* Keeps track of the excess in oversized allocations and will garbage-collect
  it if it grows too large (typically > 16MB).  This is primarily what allows
  us to be generous.

* realloc() will attempt to use MAP_TRYFIXED to extend an oversized allocation
  before giving up and remapping it.

* Improves programs which realloc() or malloc()/free() large numbers of
  oversized blocks by reducing or eliminating mmap()/munmap() calls.
lib/libc/stdlib/nmalloc.c