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

Memory use during build #45949

Closed
htot opened this issue Dec 22, 2022 · 5 comments
Closed

Memory use during build #45949

htot opened this issue Dec 22, 2022 · 5 comments
Labels
feature request Issues that request new features to be added to Node.js.

Comments

@htot
Copy link

htot commented Dec 22, 2022

What is the problem this feature will solve?

My build machine is 8 cores / 16 threads. It has 16GB RAM. If I build with make -j 16 the compile stage takes about 30 min. But during link 5 executables are being linked simultaneously, each taking 4GB RAM. Disk thrashing starts and the link phase takes an extreme long time to complete. In the mean while keyboard/mouse stop responding.

Alternative I can set make -j 2 in which case the compile phase takes multiple hours.

I would like only one executable linked at a time, but compiling to respect 16 threads.

What is the feature you are proposing to solve the problem?

Possibly a hard coded limit in the makefile. Or a command line switch.

What alternatives have you considered?

Other then buying more RAM, I can send SIGSTOP from over ssh (seems to respond better then local terminal). The stopped linkers are swapped out and not swapped back in. Then I can SIGCONT one by one. This works but requires manual intervention.

@htot htot added the feature request Issues that request new features to be added to Node.js. label Dec 22, 2022
@aduh95
Copy link
Contributor

aduh95 commented Dec 22, 2022

I'm personally always doing make -j12 on my 16 core machine, so I can keep using it while it compiles.

@htot
Copy link
Author

htot commented Dec 23, 2022

I bet you have a bit more RAM?

@bnoordhuis
Copy link
Member

bnoordhuis commented Dec 23, 2022

But during link 5 executables are being linked simultaneously, each taking 4GB RAM.

You can serialize them with flock(1):

$ make -j16 LINK='flock /tmp g++' LINK.host='flock /tmp g++'

LINK.host is only necessary when cross-compiling - edit: probably a good idea to include anyway

@htot
Copy link
Author

htot commented Dec 23, 2022

I'm using Yocto recipe, let's see if I can force that to use flock, thanks for the tip!

@htot
Copy link
Author

htot commented Dec 24, 2022

@bnoordhuis that is brilliant. Thank you!. The yocto recipe already has:

EXTRA_OEMAKE = "\
    CC.host='${CC}' \
    CFLAGS.host='${CPPFLAGS} ${CFLAGS}' \
    CXX.host='${CXX}' \
    CXXFLAGS.host='${CPPFLAGS} ${CXXFLAGS}' \
    LDFLAGS.host='${LDFLAGS}' \
    AR.host='${AR}' \
    \
    builddir_name=./ \
"

I inserted LINK.host='flock /tmp ${CXX}' \ as that seemed most logical, but that didn't help a bit (the 4 calls in my log to flock were never simultaneous). However after changing it to LINK='flock /tmp ${CXX}' \ it works.

This makes an enormous difference in my Yocto image build time (nodejs was the dominant factor).

@htot htot closed this as completed Dec 25, 2022
htot added a commit to htot/meta-intel-edison that referenced this issue Dec 25, 2022
On build hosts with more cores then RAM it is benificial to compile on as many
threads as possible (though on average you need about 1GB RAM per thread). During
the link stage make will try to link up to 5 executables, each requiring up to
5GB. On machines with less the 20GB RAM this will thrash the disk or OOM. To prevent
that from happening force serializing the link, so only 5GB RAM is required.
link: nodejs/node#45949
Suggested-by: @bnoordhuis

Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
htot added a commit to htot/meta-intel-edison that referenced this issue Nov 7, 2023
On build hosts with more cores then RAM it is benificial to compile on as many
threads as possible (though on average you need about 1GB RAM per thread). During
the link stage make will try to link up to 5 executables, each requiring up to
5GB. On machines with less the 20GB RAM this will thrash the disk or OOM. To prevent
that from happening force serializing the link, so only 5GB RAM is required.
link: nodejs/node#45949
Suggested-by: @bnoordhuis

Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

3 participants