-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
zig0 takes too much RAM to build zig1.o #6485
Comments
Seems to use up to 5.4GiB on the current commit |
I've tested around a bit, and using jemalloc or mimalloc seems to improve memory usage quite a bit. You can use those simply by using LD_PRELOAD to override the usual (glibc or musl) allocator while building Zig: ... usual cmake setup
$ LD_PRELOAD=/usr/lib/libjemalloc.so.2 ninja (substitute These are the results i've obtained on my machine for building zig:
And running stdlib tests:
update: I've also tested boehm gc. This was not tested using LD_PRELOAD, but by linking with the library and replacing all Also related: #6467 |
|
@ask6155 did you try downloading more ram? Maybe we should add some logic in the build that checks how much ram the system has and automatically downloads more if there isn't enough? |
Related: #6467 Things are going to get worse before they get better. The current plan is to (1) release 0.7.0 on October 26th and then (2) focus the main efforts of the next release cycle on finishing the self-hosted compiler, which has much better memory utilization. At this point the plan is #6378. Hang on tight, it's gonna be a bumpy ride. But we'll get through to the other side. |
Andrew and all, free -m I fail with the identical error output as the OP. I have not tried building/loading alternative *malloc libs; my interpretation of Snektron's update is this is (probably?) not an option. Are there no work arounds to 'Hang on tight' at this point? Thank you to all who are contributing to ziglang. FWIW I followed this for the build; llvm v11 built without issue: |
I'd still recommend trying with On my router that has a similar amount of memory, I can't build Zig with the default malloc either, but with |
Thank your for that clarification. I'll try getting 'jemalloc' on my system. |
Zig will not build on any 32-bit system if the process needs >4Gbyte of RAM. |
I just managed to build zig release 0.71 stage 1 on an 32-bit i386 Debian Bullseye/Sid system.
This completed in about 3 minutes with a peak resident size of 3.6GB
completed in about the same time with a peak resident size of only 3.2GB |
I hit OOM when building from master with jemalloc on a machine with ~5GB free. If anyone is still struggling like I was, I finally managed by setting up zram swap on 50% of RAM (~4GB). |
I have run into this on rpi4 (8GB ram). Adding swap did help. If You do not know how to add swap this should work (you have to be root for these):
After successful build you can remove the swap:
|
Install |
Out of curiosity, I ran heaptrack for the self-hosted compilation step with the following changes to --- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.8.12)
+FIND_PROGRAM(HEAPTRACK_PROGRAM heaptrack)
# Use ccache if possible
FIND_PROGRAM(CCACHE_PROGRAM ccache)
IF(CCACHE_PROGRAM)
@@ -868,7 +869,7 @@ set(BUILD_ZIG1_ARGS
if("${ZIG_EXECUTABLE}" STREQUAL "")
add_custom_command(
OUTPUT "${ZIG1_OBJECT}"
- COMMAND zig0 ${BUILD_ZIG1_ARGS}
+ COMMAND ${HEAPTRACK_PROGRAM} ${CMAKE_BINARY_DIR}/zig0 ${BUILD_ZIG1_ARGS}
DEPENDS zig0 "${ZIG_STAGE2_SOURCES}"
COMMENT STATUS "Building self-hosted component ${ZIG1_OBJECT}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" The |
I'm working on this issue (I already discussed this with Andrew on Discord). Here's a description of the problem with the proposed solution (in progress): Recap of compiler stages: zig0: Stage 0 compiler, consisting of all C++ code. We are concerned with building zig1 via zig0, which currently takes over 8 gigs. Why does it take so much memory? It is NOT because of memory leaks, nor because of the memory allocator. It's because zig0 compiles the ENTIRE std .zig library into one giant, in-memory object and then creates an executable file from that. That's about 35,000 function definitions. So the solution: Introduce separate compilation with separate modules, which will then be linked together at the end. |
see ziglang/zig#6485 Package-Manager: Portage-3.0.30, Repoman-3.0.3 Signed-off-by: BratishkaErik <[email protected]>
see ziglang/zig#6485 Package-Manager: Portage-3.0.30, Repoman-3.0.3 Signed-off-by: BratishkaErik <[email protected]>
see ziglang/zig#6485 Package-Manager: Portage-3.0.30, Repoman-3.0.3 Signed-off-by: BratishkaErik <[email protected]> Closes: #24734 Signed-off-by: Florian Schmaus <[email protected]>
We are one major step closer to solving this now that the self-hosted compiler can build itself. The next major step to solving this will be getting the C backend to passing all behavior tests.
|
I'll be dropping my efforts on reducing zig0 memory usage then, since it will soon be obsolete if it isn't already. |
By the way, you mentioned in your recent 2023 Roadmap video that building the self-hosted compiler will take about 0.5 GB, but when I built stage 3 from stage 2 it was taking about 2.5GB. Obviously, though, that''s a big improvement from the >8GB. |
During that talk we didn't have it fully building yet so I gave a (clearly too optimistic) guess based on how much of the compiler that was being built at the time. I did make sure to qualify my prediction carefully, mentioning that the number could be off from the final value once it is building. Anyway it can still be improved from this point- this is only the beginning. |
Hello, I've noticed that Zig is, right now, in a "package management limbo", where packages are being pulled out of the repositories, apparently because of this issue (out-of-memory when building). I've confirmed that Zig has been removed from OpenBSD 7.1 and Windows MSYS2. Maybe fixes should be backported to the 0.9 release ? For example, version 0.9.2 could be released and maintained for 1 year, while next version is developed with more tranquility. |
Hello, are there any updates about this issue ? |
The self-hosted compiler has now been set as the default one, which comes with a set of improvement that are listed in the upgrade guide: https://github.com/ziglang/zig/wiki/Self-Hosted-Compiler-Upgrade-Guide#improvements-over-stage1 One of them is:
..so building Zig yourself should now be generally more approachable even on modest hardware, given you are of course building from |
What I am doing wrong? |
Zig 0.10.1 still includes the old stage1 codebase, and uses it for bootstrapping. This issue is solved in master, and the fix will be in 0.11.0 since master no longer contains the old codebase (the bootstrap process has been replaced), but until then if you want to bootstrap without OOMing you need to use |
@mlugg Thanks for explanations! |
Hello,
Due to the recent changes in the internals of the zig compiler, I'm no longer able to build the compiler anymore.
The build fails at 99% where the self hosted component zig1.o is being built
Here's a small snippet
I have 4GB of ram on my system and I'd assume it's enough ram to build the zig compiler as I was able to do that before the restructuring. After the commit
0.6.0+f8b3543ca
I am unable to build the compiler due to enormous amount of ram that is required.I'd like to be able to compile the build on my system because it's one the features of the compiler that I liked. Unlike other languages.
The text was updated successfully, but these errors were encountered: