Implement Valgrind support, redzones, and quarantine.

Implement Valgrind support, as well as the redzone and quarantine
features, which help Valgrind detect memory errors.  Redzones are only
implemented for small objects because the changes necessary to support
redzones around large and huge objects are complicated by in-place
reallocation, to the point that it isn't clear that the maintenance
burden is worth the incremental improvement to Valgrind support.

Merge arena_salloc() and arena_salloc_demote().

Refactor i[v]salloc() to expose the 'demote' option.
This commit is contained in:
Jason Evans
2012-04-06 00:35:09 -07:00
parent a1ee7838e1
commit 122449b073
20 changed files with 840 additions and 170 deletions

View File

@@ -720,6 +720,16 @@ for (i = 0; i < nbins; i++) {
build configuration.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<mallctl>config.valgrind</mallctl>
(<type>bool</type>)
<literal>r-</literal>
</term>
<listitem><para><option>--enable-valgrind</option> was specified during
build configuration.</para></listitem>
</varlistentry>
<varlistentry>
<term>
<mallctl>config.xmalloc</mallctl>
@@ -819,6 +829,47 @@ for (i = 0; i < nbins; i++) {
configuration, in which case it is enabled by default.</para></listitem>
</varlistentry>
<varlistentry id="opt.quarantine">
<term>
<mallctl>opt.quarantine</mallctl>
(<type>size_t</type>)
<literal>r-</literal>
[<option>--enable-fill</option>]
</term>
<listitem><para>Per thread quarantine size in bytes. If non-zero, each
thread maintains a FIFO object quarantine that stores up to the
specified number of bytes of memory. The quarantined memory is not
freed until it is released from quarantine, though it is immediately
junk-filled if the <link
linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
enabled. This feature is of particular use in combination with <ulink
url="http://http://valgrind.org/">Valgrind</ulink>, which can detect
attempts to access quarantined objects. This is intended for debugging
and will impact performance negatively. The default quarantine size is
0.</para></listitem>
</varlistentry>
<varlistentry id="opt.redzone">
<term>
<mallctl>opt.redzone</mallctl>
(<type>bool</type>)
<literal>r-</literal>
[<option>--enable-fill</option>]
</term>
<listitem><para>Redzones enabled/disabled. If enabled, small
allocations have redzones before and after them. Furthermore, if the
<link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
enabled, the redzones are checked for corruption during deallocation.
However, the primary intended purpose of this feature is to be used in
combination with <ulink
url="http://http://valgrind.org/">Valgrind</ulink>, which needs
redzones in order to do effective buffer overflow/underflow detection.
This option is intended for debugging and will impact performance
negatively. This option is disabled by default unless
<option>--enable-debug</option> is specified during configuration, in
which case it is enabled by default.</para></listitem>
</varlistentry>
<varlistentry id="opt.zero">
<term>
<mallctl>opt.zero</mallctl>
@@ -849,6 +900,25 @@ for (i = 0; i < nbins; i++) {
is disabled by default.</para></listitem>
</varlistentry>
<varlistentry id="opt.valgrind">
<term>
<mallctl>opt.valgrind</mallctl>
(<type>bool</type>)
<literal>r-</literal>
[<option>--enable-valgrind</option>]
</term>
<listitem><para><ulink
url="http://http://valgrind.org/">Valgrind</ulink> support
enabled/disabled. If enabled, several other options are automatically
modified during options processing to work well with Valgrind: <link
linkend="opt.junk"><mallctl>opt.junk</mallctl></link> and <link
linkend="opt.zero"><mallctl>opt.zero</mallctl></link> are set to false,
<link linkend="opt.quarantine"><mallctl>opt.quarantine</mallctl></link>
is set to 16 MiB, and <link
linkend="opt.redzone"><mallctl>opt.redzone</mallctl></link> is set to
true. This option is disabled by default.</para></listitem>
</varlistentry>
<varlistentry id="opt.xmalloc">
<term>
<mallctl>opt.xmalloc</mallctl>
@@ -1764,10 +1834,11 @@ malloc_conf = "xmalloc:true";]]></programlisting>
<para>This implementation does not provide much detail about the problems
it detects, because the performance impact for storing such information
would be prohibitive. There are a number of allocator implementations
available on the Internet which focus on detecting and pinpointing problems
by trading performance for extra sanity checks and detailed
diagnostics.</para>
would be prohibitive. However, jemalloc does integrate with the most
excellent <ulink url="http://http://valgrind.org/">Valgrind</ulink> tool if
the <option>--enable-valgrind</option> configuration option is enabled and
the <link linkend="opt.valgrind"><mallctl>opt.valgrind</mallctl></link>
option is enabled.</para>
</refsect1>
<refsect1 id="diagnostic_messages">
<title>DIAGNOSTIC MESSAGES</title>