Bug #56267 tcmalloc lib (libtcmalloc_minimal.so) is missing from mysql 5.5 binary
Submitted: 25 Aug 2010 18:55 Modified: 30 Sep 2013 16:17
Reporter: Alexander Rubin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.5 OS:Linux
Assigned to: Assigned Account CPU Architecture:Any
Tags: tcmalloc
Triage: Triaged: D3 (Medium)

[25 Aug 2010 18:55] Alexander Rubin
Description:
As per http://dev.mysql.com/doc/refman/5.5/en/mysqld-safe.html#option_mysqld_safe_malloc-lib: "Linux users can use the libtcmalloc_minimal.so included in binary packages by adding these lines to the my.cnf file"

However, libtcmalloc is absent from MySQL 5.5 binaries.

libtcmalloc can give 2x performance on some workloads (readonly). For example:
sysbench readonly test, 64 threads: 1760.08 per sec. with tcmalloc vs 725.44 per sec. without tcmalloc

How to repeat:
Download the latest MySQL 5.5 and check MYSQL_DIR/lib 

Suggested fix:
Include the tcmalloc in the next MySQL 5.5 release
[23 Sep 2010 14:42] Joerg Bruehe
May take some time to get it working, and to verify this.
[30 Sep 2010 15:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/119573

3081 Joerg Bruehe	2010-09-30
      Part of the fix for bug#56267: Set a proper installation directory.
[1 Oct 2010 13:39] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/119684

3083 Joerg Bruehe	2010-10-01
      Next attempt at bug#56267: Use a "-D" parameter to cmake.
[3 Oct 2010 16:31] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/119783

3208 Joerg Bruehe	2010-10-03
      Fix bug#56267:
      tcmalloc lib (libtcmalloc_minimal.so) is missing from mysql 5.5 binary
      
      Ensure that a "-DMALLOC_LIB=/foo/bar/libtcmalloc_minimal.so"
      will ensure that this library gets included in the tar.gz
      binary package.
      
      It depends on the build environment to set this variable
      to the correct path name, if it is available.
[4 Oct 2010 10:02] Jonathan Perkin
Looks fine.
[4 Oct 2010 15:37] Joerg Bruehe
With the approvals, the fix is now pushed to the respective trees,
from 5.5 via trunk up to next-mr.

I hope it will get merged into main 5.5 in time for the 5.5.7 build,
the tools are ready to do it.
[20 Oct 2010 2:11] Paul Dubois
Noted in 5.5.7 changelog.

The tcmalloc library was missing from binary Linux packages.
[31 Oct 2010 16:45] Elena Stepanova
The library is included now, but as 'libtcmalloc_minimal.so.0.0.0', and there is no soft link to 'libtcmalloc_minimal.so'. With malloc-lib=tcmalloc option mysqld_safe attempts to find the file libtcmalloc_minimal.so and fails, so the shortcut still does not work (full path to the library works, though).

Also, to find the library upon the shortcut option, mysqld_safe attempts to run mysql_config and fails if it cannot be found. The script is delivered with the devel package, not server, and might need to be installed separately -- possibly it deserves mentioning in the documentation, as it seems to be the only remaining usage of mysql_config in mysqld_safe.
[31 Oct 2010 19:28] Jonathan Perkin
Joerg, can you take a look?
[1 Nov 2010 17:56] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/122467

3112 Joerg Bruehe	2010-11-01
      Resolve remaining issues of bug#56267
          tcmalloc lib (libtcmalloc_minimal.so) is missing from mysql 5.5 binary
      
      The library is already contained in all packages, and
      its name is now corrected (handled by the build tools).
      
      This fix will remove the dependency of "mysqld_safe"
      (in 'server' RPM) on "mysql_config" (in 'devel' RPM!)
      by always using the "pkglibdir" value of configure/build time.
      
      If that is wrong, the user can still provide a full path name
      as an explicit argument.
[1 Nov 2010 17:58] Joerg Bruehe
The complaint is correct:
In 5.4.3-beta, packages contained "libtcmalloc_minimal.so" (no numbering).
In 5.5.7-rc, they contain "libtcmalloc_minimal.so.0.0.0".
This holds for tar.gz packages as well as for generic and specific server RPMs.
(With RPMs, the path is absolute, in "/usr/lib/mysql", while with tar.gz it is relative.)

The build scripts are now corrected so that the numeric version info is dropped from the file name, a test build of this is running.

For the "mysql_config" dependency I wrote a patch to avoid it, at the cost of always searching the tcmalloc shared object in the configure/build location of "pkglibdir". Support will check whether that is acceptable.
[9 Nov 2010 19:49] Bugs System
Pushed into mysql-5.5 5.5.7-rc (revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (version source revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (merge vers: 5.5.7-rc) (pib:21)
[13 Nov 2010 16:16] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:40] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:jimmy.yang@oracle.com-20100804103744-vbpeghipkz6pyc9z) (pib:21)
[19 Nov 2010 17:39] Elena Stepanova
> For the "mysql_config" dependency I wrote a patch to avoid it, at the cost of 
> always searching the tcmalloc shared object in the configure/build location of > "pkglibdir". 

I ran some tests in regard to this part of the fix, which was not included into 5.5.7 release.

I a used Linux SUSE 10.2 x86_64 machine and the following packages:

- MySQL-server-5.5.8-1.linux2.6.i386.rpm
- MySQL-server-5.5.8-1.linux2.6.x86_64.rpm
- MySQL-server-5.5.8-1.sles10.x86_64.rpm
- mysql-5.5.8-linux2.6-x86_64.tar.gz

There was no problem with RPM installations -- in each case mysqld_safe successfully found the library in case of malloc-lib=tcmalloc; an absolute path also worked.

For the tar.gz package, there is a regression comparing to the old behavior. Now in case of the short option value (malloc-lib=tcmalloc) mysqld_safe cannot find the library located in <basedir>/lib, while with the previous version it worked all right. 

The difference is caused by the logic that exists in mysql_config, but not in mysqld_safe. 
mysql_config uses its own basedir as a prefix and tries to find the library folder under it, so it's dynamic and works for both RPM and tar.gz packages. mysqld_safe only checks a couple of locations pre-defined on the build stage, which works all right for RPMs but not for tar.gz as it can be placed anywhere.
[14 Jul 2011 16:39] Joerg Bruehe
Finally, I'm resuming work on this.

Situation in current 5.5 versions is (AFAIK):
- The library is contained in all binary packages (on Unix).
- With any binary package of ours, a 
      mysqld_safe --malloc-lib=/abolute/path/libtemalloc.so
  is working (at least I don't know of any complaints).
- With RPMs, a
      mysqld_safe --malloc-lib=tcmalloc
  should be working, too (I still need to double-check).
- With tar.gz, this command will work only if 
  a) the installation is done to standard paths
     so that "pkglibdir" is as expected, or
  b) "libtcmalloc" is separately installed on the system
     (this one has priority anyway, to allow updates).
  With tar.gz installed in a non-standard path,
  a "libtcmalloc.so" that came with the package will only
   be found if its absolute name is given.

Currently, I see these three choices:
a) Do nothing, require the user to use an absolute path
   under these conditions.
b) Duplicate the code of "mysql_config" that determines the
   installation path at runtime, copy it into "mysqld_safe".
c) Move "mysql_config" from the "devel" RPM into the "server" one.

Other proposals, comments, etc are welcome.
[11 Sep 2013 19:05] James Day
Option a was used in 5.5.8, current status is waiting for documentation to update as required.
[30 Sep 2013 16:17] Paul Dubois
Added to
http://dev.mysql.com/doc/refman/5.5/en/mysqld-safe.html#option_mysqld_safe_malloc-lib:

It is possible that the shortcut form will not work under certain configurations, in which case you should specify a path name instead.