Valgrind reporting a segment overflow

C++OverflowValgrindCallgrind

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

Line 1327 from the [valgrind source code][1] points to the user manual, "see section Limitations in user manual":

>[Limits section item 1:][2] > >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.

[1]: http://repo.or.cz/valgrind.git/blob/HEAD:/coregrind/m_syswrap/syswrap-generic.c "Valgrind Source Code" [2]: http://valgrind.org/docs/manual/manual-core.html#manual-core.limits "Manual, limits"

Solution 2 - C++

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.

Solution 3 - C++

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

  1. 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"!

Solution 4 - C++

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

Solution 5 - C++

>Is this a problem of valgrind, or of my program?

I am unsure of the reason, but I think you can ignore it. At least it seems to be possible to trigger it with legal programs. I answered a similar/dublicate with an example here:

https://stackoverflow.com/questions/36028302/valgrind-reporting-brk-segment-overflow-in-thread-1/36248778#36248778

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTim KuipersView Question on Stackoverflow
Solution 1 - C++PiwiView Answer on Stackoverflow
Solution 2 - C++sylvain.joyeuxView Answer on Stackoverflow
Solution 3 - C++iksemyonovView Answer on Stackoverflow
Solution 4 - C++FimbresView Answer on Stackoverflow
Solution 5 - C++Thorbjørn MartsumView Answer on Stackoverflow