When running my program with valgrind / callgrind I get the following message a lot:
==21734== brk segment overflow in thread #1: can't grow to 0x4a39000
(with different addresses)
Note that it is not preceded by a stack overflow message.
I can't find any documentation on this message and I have no idea what is overflowing exactly.
Can anybody help me figure out what the problem is? Is this a problem of valgrind, or of my program?
Line 1327 from the valgrind source code points to the user manual, "see section Limitations in user manual":
Limits section item 1:
On Linux, Valgrind determines at startup the size of the 'brk segment' using the RLIMIT_DATA rlim_cur, with a minimum of 1 MB and a maximum of 8 MB. Valgrind outputs a message each time a program tries to extend the brk segment beyond the size determined at startup. Most programs will work properly with this limit, typically by switching to the use of mmap to get more memory. If your program really needs a big brk segment, you must change the 8 MB hardcoded limit and recompile Valgrind.
Valgrind only allocates 8MB for the brk segment, which runs out. One reports that libc is then switching to a mmap-based memory allocation in the valgrind bugreport discussing this.
While this is not really an answer, it still satisfies OP's "couldn't find any docs" requirement:
1) http://repo.or.cz/valgrind.git/blob/HEAD:/coregrind/m_syswrap/syswrap-generic.c
contains the message discussed at line 1322
2) http://sourceforge.net/p/valgrind/mailman/message/34068401/
is the commit that introduced the feature, and the corresponding commit message reads
Author: florian
Date: Wed Apr 29 13:59:16 2015
New Revision: 15155
Log: Issue an error message if then brk segment overflows.
from where we can further relay this question on to those who can give a qualified answer to "what exactly does "a brk segment overflows" mean in this context"!
Adding to Piwi's answer, sometimes your program will require Callgrind to use a bigger brk segment (up to GBs, depending on your implementation).
To modify the hardcoded limit, go to function VG_(ii_create_image)
in coregrind/m_initimg/initimg-linux.c
(around line 1000), change the following lines according to your needs
SizeT m1 = 1024 * 1024;
SizeT m8 = 8 * m1;
and rebuild valgrind.
m8
is the max brk segment size that callgrind will try to allocate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With