#1053738 mariadb: what's up with the binary sizes?

#1053738#5
Date:
2023-10-09 23:22:43 UTC
From:
To:
Dear Maintainer,

A baseline
  # apt install mariadb-server --no-install-recommends
is
  The following NEW packages will be installed:
    galera-4 libconfig-inifiles-perl mariadb-client mariadb-client-core mariadb-server mariadb-server-core psmisc
  0 upgraded, 7 newly installed, 0 to remove and 2 not upgraded.
  Need to get 15.8 MB of archives.
  After this operation, 184 MB of additional disk space will be used.
  Do you want to continue? [Y/n]

Huh?

  $ apt info galera-4 libconfig-inifiles-perl mariadb-client mariadb-client-core mariadb-server mariadb-server-core psmisc | grep -we Package -e Installed
  Package: galera-4
  Installed-Size: 2,363 kB
  Package: libconfig-inifiles-perl
  Installed-Size: 126 kB
  Package: mariadb-client
  Installed-Size: 64.4 MB
  Package: mariadb-client-core
  Installed-Size: 15.0 MB
  Package: mariadb-server
  Installed-Size: 55.2 MB
  Package: mariadb-server-core
  Installed-Size: 45.7 MB
  Package: psmisc
  Installed-Size: 931 kB
(for reference, a full postgres is like 60M;
 it's fundamentally impossible for any piece of software to be this size).

And indeed, mariadb-server-core has a /usr/bin/resolveip which is 4.5M.
And does... what host(1) does (five libc calls) in 113k.

mariadb-server has
  $ du -hsc usr/bin/*{myisam,aria_}*
  4.9M    usr/bin/myisamchk
  4.8M    usr/bin/myisam_ftdump
  4.7M    usr/bin/myisamlog
  4.8M    usr/bin/myisampack
  5.3M    usr/bin/aria_chk
  5.1M    usr/bin/aria_dump_log
  5.1M    usr/bin/aria_ftdump
  5.2M    usr/bin/aria_pack
  5.3M    usr/bin/aria_read_log
  45.2M   total
and these are all linked to libc and some to libc++.
And they tar | gzip to 11M.

mariadb-client has
  $ du -ahd1 usr/bin/ | grep M
  4.5M    usr/bin/resolve_stack_dump
  4.4M    usr/bin/replace
  4.7M    usr/bin/perror
  4.5M    usr/bin/mariadb-waitpid
  4.5M    usr/bin/mariadb-tzinfo-to-sql
  4.8M    usr/bin/mariadb-slap
  4.8M    usr/bin/mariadb-show
  4.5M    usr/bin/mariadb-plugin
  4.8M    usr/bin/mariadb-import
  4.8M    usr/bin/mariadb-dump
  4.5M    usr/bin/mariadb-conv
  5M      usr/bin/mariadb-binlog
  4.8M    usr/bin/mariadb-admin
  61.2M   usr/bin/

and mariadb-client-core has
  $ du -ahd1 usr/bin/ | grep M
  4.5M    usr/bin/my_print_defaults
  4.8M    usr/bin/mariadb-check
  5M      usr/bin/mariadb
  14.2M   usr/bin/

All of them being 4.5M + a reasonable size for a binary is, shall I say...
sus?

Can these link to a proverbial libmariadb.so instead
(like systemd has with a hard dep like "libsystemd-shared (= 252.17-1~deb12u1)")?
Or if not can they be linked to libmariadb.a with -flto,
in hopes the linker can make less of a hash of this?

Because I don't think I'm being hyperbolic when I say this is egregious.

Best,
наб

#1053738#10
Date:
2023-10-09 23:52:15 UTC
From:
To:
Hi!

Indeed the binary sizes of MariaDB are quite large. The way they are
built is the same as at upstream, there is no artificial bloating
going on in Debian.

Any ideas on how to reduce the binary size are welcome!

The packaging source code is at
https://salsa.debian.org/mariadb-team/mariadb-server and instructions
on how to contribute in
https://salsa.debian.org/mariadb-team/mariadb-server/-/wikis/Contributing-to-MariaDB-packaging-in-Debian
if you want to try playing around with the build yourself.

#1053738#15
Date:
2023-10-11 02:02:39 UTC
From:
To:
I started by looking at the buildd log to confirm my bias and succeeded:
the linker step for resolveip, for example, is passed a couple
libwhatever.a files, no -flto, no -Wl,--as-needed.

Doing, effectively, /^+/s/")/ -flto")/ to
  d/patches/0025-Change-the-default-optimization-from-O3-to-O2-in-mys.patch
(real blessing that's there, I'd've given up otherwise) got me
  -rwxr-xr-x 1 nabijaczleweli users 586K 10-11 03:24 perror
  -rwxr-xr-x 1 nabijaczleweli users 384K 10-11 03:24 replace
  -rwxr-xr-x 1 nabijaczleweli users 384K 10-11 03:24 resolveip
  -rwxr-xr-x 1 nabijaczleweli users 5.1M 10-11 03:25 ./builddir/client/mariadb
  -rwxr-xr-x 1 nabijaczleweli users 5.0M 10-11 03:26 ./builddir/storage/maria/aria_chk
  -rwxr-xr-x 1 nabijaczleweli users 441K 10-11 03:26 ./builddir/storage/maria/aria_dump_log
  -rwxr-xr-x 1 nabijaczleweli users 4.7M 10-11 03:26 ./builddir/storage/maria/aria_ftdump
  -rwxr-xr-x 1 nabijaczleweli users 4.8M 10-11 03:26 ./builddir/storage/maria/aria_pack
  -rwxr-xr-x 1 nabijaczleweli users 4.9M 10-11 03:26 ./builddir/storage/maria/aria_read_log
  -rwxr-xr-x 1 nabijaczleweli users 466K 10-11 03:26 ./builddir/storage/maria/aria_s3_copy
after a no-arg strip on bookworm GCC.

So it's still large, but appears to defeat
"everything is 4.5M + application code" at least.

Alas, the build fails with
  ../storage/csv/./sql/table.h:1651: warning: type of ‘use_all_columns’ does not match original declaration [-Wlto-type-mismatch]
  ../storage/myisam/./sql/table.h:1651:15: note: ‘use_all_columns’ was previously declared here
  ../storage/myisam/./sql/table.h:1651:15: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
  ./builddir/libmysqld/libmysqld_exports_file.cc:148:15: error: function ‘mariadb_field_attr’ redeclared as variable
  ./libmysqld/libmysql.c:743:1: note: previously declared here
  ./builddir/libmysqld/libmysqld_exports_file.cc:147:15: error: function ‘mysql_options4’ redeclared as variable
  ./sql-common/client.c:3918:1: note: previously declared here
  ./builddir/libmysqld/libmysqld_exports_file.cc:146:15: error: function ‘mysql_net_field_length’ redeclared as variable
  ./libmysqld/libmysql.c:4974:15: note: previously declared here
  ./builddir/libmysqld/libmysqld_exports_file.cc:145:15: error: function ‘mysql_net_read_packet’ redeclared as variable
  ./libmysqld/libmysql.c:4969:15: note: previously declared here
  and many others like it
so no stats for mariadbd.

#1053738#20
Date:
2023-10-11 04:13:29 UTC
From:
To:
Hi!

I am open to dropping this patch and using a patch supplied by you
instead if you later figure out how to best optimize the build.

I am also happy to receive a 90% done Merge Request with a failing
build as that will make it easier for other people to chip in and
maybe provide ideas/guidance on how to finalize it.

#1053738#25
Date:
2025-04-12 05:00:00 UTC
From:
To:
Hi!

I never saw a patch or MR about this, but I am happy to have one, even
if it is only 90% done and failing, if you still want to help optimize
the binary sizes.

Currently the examples you referenced are 10M+:

± ll ./builddir/storage/maria/aria_*
-rwxr-xr-x 1 otto otto 14M Apr 11 20:16 ./builddir/storage/maria/aria_chk*
-rwxr-xr-x 1 otto otto 13M Apr 11 20:16 ./builddir/storage/maria/aria_dump_log*
-rwxr-xr-x 1 otto otto 13M Apr 11 20:16 ./builddir/storage/maria/aria_ftdump*
-rwxr-xr-x 1 otto otto 13M Apr 11 20:16 ./builddir/storage/maria/aria_pack*
-rwxr-xr-x 1 otto otto 14M Apr 11 20:16 ./builddir/storage/maria/aria_read_log*
-rwxr-xr-x 1 otto otto 12M Apr 11 20:16 ./builddir/storage/maria/aria_s3_copy*

Related, the O2/O3 was dropped in
https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/af3d7e3fce52387d83f1fca995f12475e0a70399.

#1053738#32
Date:
2025-04-12 17:45:51 UTC
From:
To:
I discarded it when it didn't work I think.
Here's a quick reconstruction, adding -flto/-flto=full to the arguments:
https://salsa.debian.org/mariadb-team/mariadb-server/-/merge_requests/113
This worked more
(2 tests failed with a timezone thing,
 I'm assuming it's because I'm not in UTC0).
$ l ./builddir/storage/maria/aria_*
-rwxr-xr-x 1 nabijaczleweli users   5.2M 04-12 19:43 ./builddir/storage/maria/aria_chk
-rwxr-xr-x 1 nabijaczleweli users 472.4k 04-12 19:43 ./builddir/storage/maria/aria_dump_log
-rwxr-xr-x 1 nabijaczleweli users   4.8M 04-12 19:43 ./builddir/storage/maria/aria_ftdump
-rwxr-xr-x 1 nabijaczleweli users   4.9M 04-12 19:43 ./builddir/storage/maria/aria_pack
-rwxr-xr-x 1 nabijaczleweli users   5.1M 04-12 19:43 ./builddir/storage/maria/aria_read_log
-rwxr-xr-x 1 nabijaczleweli users 498.3k 04-12 19:43 ./builddir/storage/maria/aria_s3_copy

Looks much better for basically free
(certainly freer than carving out libmariadbinternal11).

Also, dpkg -c on a current deb:
and l builddir/client
-rwxr-xr-x  1 nabijaczleweli users   5.2M 04-12 19:43 mariadb
-rwxr-xr-x  1 nabijaczleweli users 739.3k 04-12 19:43 mariadb-admin
-rwxr-xr-x  1 nabijaczleweli users     5M 04-12 19:43 mariadb-binlog
-rwxr-xr-x  1 nabijaczleweli users   4.8M 04-12 19:43 mariadb-check
-rwxr-xr-x  1 nabijaczleweli users   4.5M 04-12 19:43 mariadb-conv
-rwxr-xr-x  1 nabijaczleweli users   4.9M 04-12 19:43 mariadb-dump
-rwxr-xr-x  1 nabijaczleweli users 856.6k 04-12 19:43 mariadb-import
-rwxr-xr-x  1 nabijaczleweli users   417k 04-12 19:43 mariadb-plugin
-rwxr-xr-x  1 nabijaczleweli users 730.3k 04-12 19:43 mariadb-show
-rwxr-xr-x  1 nabijaczleweli users   749k 04-12 19:43 mariadb-slap
-rwxr-xr-x  1 nabijaczleweli users   5.4M 04-12 19:43 mariadb-test
-rwxr-xr-x  1 nabijaczleweli users 897.5k 04-12 19:43 mariadb-upgrade
so a strict improvement there as well.