[PATCH v2] Allow shrinking of arena heaps using mmap based on overcommit settings when available

Siddhesh Poyarekar siddhesh@redhat.com
Tue Sep 11 10:11:00 GMT 2012


Hi Roland,

Here is an updated patch with further fixes as per your review. No
regressions in the testsuite. Also, I have tested this on F16 x86_64 as
follows:

* echo 0 > /proc/sys/vm/overcommit_memory
* Run the benchmark program that I posted earlier:

http://sourceware.org/ml/libc-alpha/2012-08/msg00462.html

and attach an strace as follows:

strace -f -e madvise -p $(pgrep a.out)

to confirm that madvise is being called. Detach and attach strace again
as follows:

strace -f -e mmap -p $(pgrep a.out)

to ensure that there are no mmap calls with MAP_FIXED.

Now disable overcommit:

* echo 2 > /proc/sys/vm/overcommit_memory
* Run the benchmark program and verify that the behaviour is the
  opposite, i.e. there should be no calls to madvise and you should see
  calls to mmap with MAP_FIXED.

Further, I also verified that I see the performance difference between
madvise and MAP_FIXED:

with overcommit_memory == 0:

RUNS=4096, TOTAL=8859615.000000, AVG=2162.991943
RUNS=4096, TOTAL=8948967.000000, AVG=2184.806396
RUNS=4096, TOTAL=9002337.000000, AVG=2197.836182
RUNS=4096, TOTAL=9147284.000000, AVG=2233.223633
RUNS=4096, TOTAL=8852469.000000, AVG=2161.247314
RUNS=4096, TOTAL=8920974.000000, AVG=2177.972168
RUNS=4096, TOTAL=9051495.000000, AVG=2209.837646
RUNS=4096, TOTAL=8896417.000000, AVG=2171.976807

with overcommit_memory == 2:

RUNS=4096, TOTAL=9916217.000000, AVG=2420.951416
RUNS=4096, TOTAL=10098292.000000, AVG=2465.403320
RUNS=4096, TOTAL=9951147.000000, AVG=2429.479248
RUNS=4096, TOTAL=9776165.000000, AVG=2386.759033
RUNS=4096, TOTAL=9735272.000000, AVG=2376.775391
RUNS=4096, TOTAL=10049977.000000, AVG=2453.607666
RUNS=4096, TOTAL=9967350.000000, AVG=2433.435059
RUNS=4096, TOTAL=9817866.000000, AVG=2396.939941

Regards,
Siddhesh

ChangeLog:

	* malloc/arena.c: Include malloc-sysdep.h.
	(shrink_heap): Use check_may_shrink_heap to decide if madvise
	is sufficient to shrink the heap or an unmap is needed.
	* sysdeps/generic/malloc-sysdep.h: New file.  Define
	new function check_may_shrink_heap.
	* sysdeps/unix/sysv/linux/malloc-sysdep.h: New file.  Define
	new function check_may_shrink_heap.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: heap-shrink.patch
Type: text/x-patch
Size: 4669 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120911/7c89e3bf/attachment.bin>


More information about the Libc-alpha mailing list