Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Libraries in the RocksDB Makefile Build #6660

Closed
wants to merge 19 commits into from

Conversation

mrambacher
Copy link
Contributor

@mrambacher mrambacher commented Apr 7, 2020

Change the linking of tests/tools to be against a library rather than a list of objects. This change substantially reduces the size of the objects produced.

peterd clean repo size: 264M
Before this change, with make all: 40G
After this change, with make all: 28G
With make LIB_MODE=shared all: 7.0G

The list of TESTS was changed from being hard-coded to generated from the test sources variable. Note that there are some test sources that are not built as tests (though the set of tests is identical to the previous version).

Added OBJ_DIR option to Makefile to allow objects to be placed in an alternative location. By default, OBJ_DIR is the same as before ("./").

This change is a precursor to being able to build/run the tests/tools linked against static libraries. Additionally, it should be possible to clean up and merge some of the rules for building tests and the like if so desired.

@mrambacher mrambacher force-pushed the Makefile branch 2 times, most recently from a9c6e4f to c9aa8fc Compare May 29, 2020 23:24
@mrambacher mrambacher changed the title Better support for shared libraries in RocksDB Use Libraries in the RocksDB Build Process May 29, 2020
@pdillinger
Copy link
Contributor

I'm digging into something else at the moment, but I get this (yes, I did make clean):

util/heap_test.cc:136: error: undefined reference to 'gflags::ParseCommandLineFlags(int*, char***, bool)'
util/heap_test.cc:20: error: undefined reference to 'gflags::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, long*, long*)'

@mrambacher
Copy link
Contributor Author

I'm digging into something else at the moment, but I get this (yes, I did make clean):

util/heap_test.cc:136: error: undefined reference to 'gflags::ParseCommandLineFlags(int*, char***, bool)'
util/heap_test.cc:20: error: undefined reference to 'gflags::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, long*, long*)'

What platform? I have done builds on RedHat and MacOS and do not see this error.

@pdillinger
Copy link
Contributor

I'm digging into something else at the moment, but I get this (yes, I did make clean):
util/heap_test.cc:136: error: undefined reference to 'gflags::ParseCommandLineFlags(int*, char***, bool)'
util/heap_test.cc:20: error: undefined reference to 'gflags::FlagRegisterer::FlagRegisterer(char const*, char const*, char const*, long*, long*)'

What platform? I have done builds on RedHat and MacOS and do not see this error.

Linux/x86_64. Doesn't happen with ROCKSDB_NO_FBCODE=1, so it must be a specific incompatibility with build_tools/fbcode_config_platform007.sh (used by build_detect_platform when building on Facebook machines)

mkdir -p third-party/gtest-1.8.1/fused-src/gtest && /mnt/gvfs/third-party2/gcc/7331085db891a2ef4a88a48a751d834e8d68f4cb/7.x/centos7-native/b2ef2b6/bin/g++  -DROCKSDB_USE_RTTI -g -W -Wextra -Wall -Wsign-compare -Wshadow -Wunused-parameter -Werror -I. -I./include -std=c++11   -DSNAPPY -DZLIB -DBZIP2 -DLZ4 -DZSTD -DGFLAGS=gflags -DNUMA -DTBB -DLIBURING -B/mnt/gvfs/third-party2/binutils/ab9f09bba370e7066cafd4eb59752db93f2e8312/2.29.1/platform007/15a3614/bin/gold -isystem /mnt/gvfs/third-party2/libgcc/6ace84e956873d53638c738b6f65f3f469cca74c/7.x/platform007/5620abc/include/c++/7.3.0 -isystem /mnt/gvfs/third-party2/glibc/192b0f42d63dcf6210d6ceae387b49af049e6e0c/2.26/platform007/f259413/include  -I /mnt/gvfs/third-party2/snappy/7f9bdaada18f59bc27ec2b0871eb8a6144343aef/1.1.3/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/zlib/2d9f0b9a4274cc21f61272a9e89bdb859bce8f1f/1.2.8/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/bzip2/dc49a21c5fceec6456a7a28a94dcd16690af1337/1.0.6/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/lz4/0f607f8fc442ea7d6b876931b1898bb573d5e5da/1.9.1/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/zstd/ca22bc441a4eb709e9e0b1f9fec9750fed7b31c5/1.4.x/platform007/15a3614/include/  -I /mnt/gvfs/third-party2/gflags/0b9929d2588991c65a57168bf88aff2db87c5d48/2.2.0/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/numa/3f3fb57a5ccc5fd21c66416c0b83e0aa76a05376/2.0.11/platform007/ca4da3d/include/  -isystem /mnt/gvfs/third-party2/tbb/4ce8e8dba77cdbd81b75d6f0c32fd7a1b76a11ec/2018_U5/platform007/ca4da3d/include/  -isystem /mnt/gvfs/third-party2/liburing/79427253fd0d42677255aacfe6d13bfe63f752eb/20190828/platform007/ca4da3d/include/ -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX  -DSNAPPY -DZLIB -DBZIP2 -DLZ4 -DZSTD -DGFLAGS=gflags -DNUMA -DTBB -DLIBURING -B/mnt/gvfs/third-party2/binutils/ab9f09bba370e7066cafd4eb59752db93f2e8312/2.29.1/platform007/15a3614/bin/gold -isystem /mnt/gvfs/third-party2/libgcc/6ace84e956873d53638c738b6f65f3f469cca74c/7.x/platform007/5620abc/include/c++/7.3.0 -isystem /mnt/gvfs/third-party2/glibc/192b0f42d63dcf6210d6ceae387b49af049e6e0c/2.26/platform007/f259413/include  -I /mnt/gvfs/third-party2/snappy/7f9bdaada18f59bc27ec2b0871eb8a6144343aef/1.1.3/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/zlib/2d9f0b9a4274cc21f61272a9e89bdb859bce8f1f/1.2.8/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/bzip2/dc49a21c5fceec6456a7a28a94dcd16690af1337/1.0.6/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/lz4/0f607f8fc442ea7d6b876931b1898bb573d5e5da/1.9.1/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/zstd/ca22bc441a4eb709e9e0b1f9fec9750fed7b31c5/1.4.x/platform007/15a3614/include/  -I /mnt/gvfs/third-party2/gflags/0b9929d2588991c65a57168bf88aff2db87c5d48/2.2.0/platform007/ca4da3d/include/  -I /mnt/gvfs/third-party2/numa/3f3fb57a5ccc5fd21c66416c0b83e0aa76a05376/2.0.11/platform007/ca4da3d/include/  -isystem /mnt/gvfs/third-party2/tbb/4ce8e8dba77cdbd81b75d6f0c32fd7a1b76a11ec/2018_U5/platform007/ca4da3d/include/  -isystem /mnt/gvfs/third-party2/liburing/79427253fd0d42677255aacfe6d13bfe63f752eb/20190828/platform007/ca4da3d/include/ -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT -DOS_LINUX -fno-builtin-memcmp -DROCKSDB_BACKTRACE -msse4.2 -DHAVE_SSE42 -mpclmul -DHAVE_PCLMUL -mavx2 -DHAVE_AVX2 -DHAVE_UINT128_EXTENSION -DROCKSDB_SUPPORT_THREAD_LOCAL -DROCKSDB_JEMALLOC -DJEMALLOC_NO_DEMANGLE -I /mnt/gvfs/third-party2/jemalloc/c26f08f47ac35fc31da2633b7da92d6b863246eb/master/platform007/c26c002/include/ -isystem third-party/gtest-1.8.1/fused-src -isystem ./third-party/folly -O2 -fno-omit-frame-pointer -momit-leaf-frame-pointer -Woverloaded-virtual -Wnon-virtual-dtor -Wno-missing-field-initializers -c third-party/gtest-1.8.1/fused-src/gtest/gtest-all.cc -o third-party/gtest-1.8.1/fused-src/gtest/gtest-all.o 
/mnt/gvfs/third-party2/gcc/7331085db891a2ef4a88a48a751d834e8d68f4cb/7.x/centos7-native/b2ef2b6/bin/g++ -o heap_test /mnt/gvfs/third-party2/jemalloc/c26f08f47ac35fc31da2633b7da92d6b863246eb/master/platform007/c26c002/lib/libjemalloc.a /mnt/gvfs/third-party2/snappy/7f9bdaada18f59bc27ec2b0871eb8a6144343aef/1.1.3/platform007/ca4da3d/lib/libsnappy.a  /mnt/gvfs/third-party2/zlib/2d9f0b9a4274cc21f61272a9e89bdb859bce8f1f/1.2.8/platform007/ca4da3d/lib/libz.a  /mnt/gvfs/third-party2/bzip2/dc49a21c5fceec6456a7a28a94dcd16690af1337/1.0.6/platform007/ca4da3d/lib/libbz2.a  /mnt/gvfs/third-party2/lz4/0f607f8fc442ea7d6b876931b1898bb573d5e5da/1.9.1/platform007/ca4da3d/lib/liblz4.a  /mnt/gvfs/third-party2/zstd/ca22bc441a4eb709e9e0b1f9fec9750fed7b31c5/1.4.x/platform007/15a3614/lib/libzstd.a  /mnt/gvfs/third-party2/gflags/0b9929d2588991c65a57168bf88aff2db87c5d48/2.2.0/platform007/ca4da3d/lib/libgflags.a  /mnt/gvfs/third-party2/numa/3f3fb57a5ccc5fd21c66416c0b83e0aa76a05376/2.0.11/platform007/ca4da3d/lib/libnuma.a /mnt/gvfs/third-party2/tbb/4ce8e8dba77cdbd81b75d6f0c32fd7a1b76a11ec/2018_U5/platform007/ca4da3d/lib/libtbb.a /mnt/gvfs/third-party2/liburing/79427253fd0d42677255aacfe6d13bfe63f752eb/20190828/platform007/ca4da3d/lib/liburing.a -B/mnt/gvfs/third-party2/binutils/ab9f09bba370e7066cafd4eb59752db93f2e8312/2.29.1/platform007/15a3614/bin/gold -Wl,--dynamic-linker,/usr/local/fbcode/platform007/lib/ld.so /mnt/gvfs/third-party2/libunwind/40c73d874898b386a71847f1b99115d93822d11f/1.4/platform007/6f3e0a9/lib/libunwind.a -Wl,-rpath=/usr/local/fbcode/platform007/lib -ldl -L. util/heap_test.o third-party/gtest-1.8.1/fused-src/gtest/gtest-all.o   -L /mnt/gvfs/third-party2/libgcc/6ace84e956873d53638c738b6f65f3f469cca74c/7.x/platform007/5620abc/lib  -L /mnt/gvfs/third-party2/glibc/192b0f42d63dcf6210d6ceae387b49af049e6e0c/2.26/platform007/f259413/lib -L /mnt/gvfs/third-party2/gcc/7331085db891a2ef4a88a48a751d834e8d68f4cb/7.x/centos7-native/b2ef2b6/lib64 -lgcc -lstdc++ -lpthread -lrt -ldl 
util/heap_test.cc:136: error: undefined reference to 'gflags::ParseCommandLineFlags(int*, char***, bool)'
util/heap_test.cc:20: error: undefined reference to 'gflags::FlagRegisterer::FlagRegisterer<long>(char const*, char const*, char const*, long*, long*)'
collect2: error: ld returned 1 exit status

@mrambacher
Copy link
Contributor Author

Do the tests other than heap_test build successfully? How can I see the command for a successful versus failed build? At first glance, I am not sure how/where the command to build heap_test has changed.

@pdillinger
Copy link
Contributor

Some pass, some fail. Although I told you that TARGETS isn't really affected by Makefile changes, these changes are deep enough that the buckifying has been gutted. Sorry about that.

To accept this, I think we need to break this up in into pieces. But also, the size savings is not as much as I had hoped for.

About 80% of the space is unit test executables. Since the .o files for the tests (test-specific parts) are only about 5%, we should be able to build a unified test executable that saves almost all of that 80%. We would just need to make the defined "main" functions either a true main or sub-main depending on compile time parameter, implement some resigtry+dispatch based on argv[0], and generate symlinks from old test executable names to unified test executable. And probably resolve a few new linking conflicts between tests. Note that we would want the test subset CI builds only to build and unify the necessary subset. (Not hygienic for incremental re-builds, but OK as it's intended for CI.)

@pdillinger
Copy link
Contributor

To accept this, I think we need to break this up in into pieces.

So that we can update buckifier incrementally, rather than in a giant leap.

@pdillinger
Copy link
Contributor

We would just need to make the defined "main" functions either a true main or sub-main depending on compile time parameter, ...

Probably makes sense to simply use gtest as the registry and don't try to preserve usability as segregated executables for unified unit test executable. (But maybe keep ability to build those.)

@mrambacher
Copy link
Contributor Author

As another point of reference, if I build RocksDB as a shared library and build the tests and tools against the shared libraries, the size drops substantially.
Debug with shared libraries: 987,696
Debug with static libraries: 14,760,176
Debug against object files: 22,231,072

The shared libraries are missing a few tests (about 6 from an older Makefile) but gives you an idea of the scope. Release builds are also around 1/6 the size.

@pdillinger
Copy link
Contributor

if I build RocksDB as a shared library and build the tests and tools against the shared libraries

That's not available in these changes though? (I haven't figured out how SHARED_TEST_LIBRARY is referenced by any targets.)

@mrambacher
Copy link
Contributor Author

I pushed a new commit with the a shared mode for the tests. I figured that would be too much for a single PR.

@pdillinger
Copy link
Contributor

Now I can run 'make check' with ~90% space savings vs. static linking. That's more motivation for me to dig into some of the compatibility issues. (I haven't tested my change on clang, just sharing it so that test binaries run as usual but with dynamic linking.)

@pdillinger
Copy link
Contributor

Is there a reason to not do this for debug_level=0 and make it rpath="." ?

My inclination was to do the minimum for unit tests to work as they have historically, and they should always be run with DEBUG_LEVEL>0 anyway. I don't think we want to manipulate rpath for binaries that even might be installed (release build), because of security risk.

I don't know enough about rpath to know if "." works. And that might ask the question of which is more likely: changing the absolute path of your repo clone without rebuild or running executables from path other than ./ (I consider it more kosher to break the former case than the latter.)

@mrambacher
Copy link
Contributor Author

Has any more thought been put into this PR? If we can head down this path and do the customizable work, we may be able to solve quite a few problems. With some effort, the Java system could be more pluggable for one. And components that may be add-ons (like HDFS, ClockCache, CuckooTable, Cassandra, etc) could be removed from the core and put into separate libraries.

@pdillinger
Copy link
Contributor

pdillinger commented Jun 19, 2020

I still need to fix buckifier. Shouldn't be hard

@pdillinger
Copy link
Contributor

Anyone know how to fix the java_test build on Travis? (UnsatisfiedLinkError on _ZTIN7rocksdb6LoggerE)

@mrambacher
Copy link
Contributor Author

I fixed this problem on my local machine so that rocksdbjava and rocksdbjavastatic both build now.

It would be really nice to further clean up the Java build (in a later PR) so that it just used the shared library build (rather than rebuilding everything itself).

@pdillinger
Copy link
Contributor

I saw another PR with a similar error (6997), so a merge or rebase might help.

mrambacher and others added 8 commits June 23, 2020 15:44
… a list of objects. This change substantially reduces the size of the objects produced.

Added OBJ_DIR option to Makefile to allow objects to be placed in an alternative location.  This value is currently unused (set to the current directory) but will allow objects to be placed in different directories to simplify the build process when building multiple targets (like LITE, release/debug, shared/static, java, etc).
This change adds a LIB_MODE flag to control how RocksDB binaries, libraries, and tests are built.

Using shared libraries reduces the size of the executables substantially.  Additionally, shared libraries will make it easier/cleaner to develop and deploy extension libraries to RocksDB.
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdillinger has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdillinger has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdillinger has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mrambacher has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pdillinger has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@pdillinger pdillinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are all good now

@pdillinger pdillinger changed the title Use Libraries in the RocksDB Build Process Use Libraries in the RocksDB Makefile Build Jun 30, 2020
EXEC_LDFLAGS += -Wl,-rpath="$(PWD)"
endif
# So that binaries are executable from build location, in addition to install location
EXEC_LDFLAGS += -Wl,-rpath='$$ORIGIN'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing to compile on MacOS:

CCLD cache_bench
ld: unknown option: -rpath=$ORIGIN
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If I specify -rpath . on the Mac (no =), it works. I have not gotten it to work with ORIGIN however

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this option should go into build_detect_platform as part of PLATFORM_LDFLAGS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except it's EXEC_LDFLAGS (only for linking executables), so PLATFORM_EXEC_LDFLAGS?

@@ -215,7 +231,8 @@ LIB_SOURCES += utilities/env_librados.cc
LDFLAGS += -lrados
endif

AM_LINK = $(AM_V_CCLD)$(CXX) $^ $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS)
AM_LINK = $(AM_V_CCLD)$(CXX) $(patsubst lib%.a, -l%, $(patsubst lib%.$(PLATFORM_SHARED_EXT), -l%, $^)) $(EXEC_LDFLAGS) -o $@ -L. $(LDFLAGS) $(COVERAGEFLAGS)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the -L. should be before the libraries (patsubst).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed for me the way you had it so I semi-reverted. b94b715

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But moving just the -L. does seem ok testing it just now. (Now for follow-up PR)

@facebook-github-bot
Copy link
Contributor

@pdillinger merged this pull request in 80f71b5.

facebook-github-bot pushed a commit that referenced this pull request Jul 1, 2020
Summary:
Follow-up to #6660. Release build had linker error. fbcode+clang+shared build was erroring on unused parameter '-nostdinc'.

Fixes #7061

Pull Request resolved: #7062

Test Plan: make release, USE_CLANG=1 LIB_MODE=shared make check, etc.

Reviewed By: siying

Differential Revision: D22335663

Pulled By: pdillinger

fbshipit-source-id: 261cd959ca1f6c273dc763a70020a535ba8e81de
pdillinger added a commit to pdillinger/rocksdb that referenced this pull request Sep 8, 2020
Summary: Was broken by facebook#6660

Test Plan: CI inspection
facebook-github-bot pushed a commit that referenced this pull request Sep 9, 2020
Summary:
Was broken by #6660

Travis times before this change, after 6660:
platform_dependent: 17 min
group 1: 15 min
group 2: 44 min (often timeout on non-x86 or non-Linux)
group 3: 31 min
group 4: 21 min

After this change:
TODO

Pull Request resolved: #7360

Test Plan: CI inspection

Reviewed By: ajkr

Differential Revision: D23586917

Pulled By: pdillinger

fbshipit-source-id: 4c67cf33180b0b833c39a817e6c1f128727941d2
adamretter pushed a commit to adamretter/rocksdb that referenced this pull request Oct 14, 2020
…cebook#6660

This was fixed in facebook#7359 and this commit is just a partial back-port of the necessary parts of that PR.
ajkr pushed a commit that referenced this pull request Oct 14, 2020


This was fixed in #7359 and this commit is just a partial back-port of the necessary parts of that PR.
codingrhythm pushed a commit to SafetyCulture/rocksdb that referenced this pull request Mar 5, 2021
Summary:
Was broken by facebook#6660

Travis times before this change, after 6660:
platform_dependent: 17 min
group 1: 15 min
group 2: 44 min (often timeout on non-x86 or non-Linux)
group 3: 31 min
group 4: 21 min

After this change:
TODO

Pull Request resolved: facebook#7360

Test Plan: CI inspection

Reviewed By: ajkr

Differential Revision: D23586917

Pulled By: pdillinger

fbshipit-source-id: 4c67cf33180b0b833c39a817e6c1f128727941d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants