On the 1.8.x-memory-fragmentation branch:
Prevent excessive memory fragmentation in FSFS when activating fulltext
caching in Apache with MaxFreeMem set to 0 (unbounded, the default in 2.2).
Inspired by r1591005 on /trunk.

The default Apache 2.2 configuration does not limit the amount of unused
memory held by the worker thread's allocator.  Requests involving slowly
growing fulltext sizes (such as 'svn annotate') will often not fit into
an existing memory node but cause APR to allocate a new one.  This gives
O(n^2) worst-case memory consumption when fulltext caching is enabled.
Without fulltext caching, we don't allocate large, arbitrarily sized blocks
(arrays etc. already grow similarly to what we do here).

This fix is simple:  Pre-allocate the string buffer for larger fulltexts
as a power of 2 minus some room for overhead.  Because we only request few
different sizes, the respective memory nodes can be reused.  If N is the
size of the longest fulltext, the allocator will at most allocate 4N bytes
for fulltexts over its lifetime (assuming they never get released to the OS).

Since we only select the initial size of our auto-reallocating SVN string
buffer object, this patch will not affect the correctness of the remaining
code.

* subversion/libsvn_fs_fs/fs_fs.c
  (optimimal_allocation_size): New utility function. Taken from /trunk.
  (rep_read_get_baton): Use the new function to allocate large
                        buffers as blocks of 2^N bytes.

git-svn-id: https://svn.apache.org/repos/asf/subversion/branches/1.8.x-memory-fragmentation@1669955 13f79535-47bb-0310-9956-ffa450edef68
1 file changed