Here comes another case study fof fixing parallel make issues, in this case, I’m going to talk about a parallel make issue that does not cause the build to abort, but that forces serial make even when parallel make is requested.
If you look closely at the build messages coming out of various packages you might notice from time to time the error “jobserver unavailable” coming from make. When that warning is outputted, it means that GNU make is unable to properly handle parallel builds since it does not know how to discipline the build, for instance, this comes from the build of xfsprogs:
flame@yamato xfsprogs-2.10.1 % make -j16
=== include ===
gmake[1]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
Code language: PHP (php)
I have to say that GNU make here is very nice with its messages: it does not simply say that the jobserver is unavailable, it also tells you that it is going to use -j1
and that you should add a plus sign to the “parent make rule”. But I guess most people wouldn’t know how to deal with this. Let’s look deeper.
The build system of xfsprogs is based on autoconf and libtool, but it’s custom made (which by itself caused me quite a few headaches in the past and I still loathe). It is also recursive just like automake based buildsystem, but how does it recurse? The main Makefile contains this:
default: $(CONFIGURE)
ifeq ($(HAVE_BUILDDEFS), no)
$(MAKE) -C . $@
else
$(SUBDIRS_MAKERULE)
endif
Code language: JavaScript (javascript)
To find SUBDIRS_MAKERULE we have to dig a lot deeper, finally we can find it in include/buildmacros
:
SUBDIRS_MAKERULE =
@for d in $(SUBDIRS) ""; do
if test -d "$d" -a ! -z "$d"; then
$(ECHO) === $d ===;
$(MAKEF) -C $d $@ || exit $?;
fi;
done
Code language: PHP (php)
So it’s serialising the subdirectories build, what is the problem here? The problem is that GNU make, to implement parallel build, requires special options and descriptors to be passed over the sub-make calls, this happens automatically when make
is invoked directly or through $(MAKE)
but if it’s indirected through variables, then it’s not happening automatically and the developer has to tell GNU make to actually pass the options along.
Now the only problem here is to identify which is the rule that you should add +
to, but this is very simple since the rule here already has a @ symbol at its start, so just make it @+ and it’ll be done. A very big problem can arise if the rule executes something that is not make together with make (and something more than just test) since then stuff might break hugely.
At any rate, after you actually change this rule (as well as the SOURCE_MAKERULE
one), xfsprogs can finally build in parallel, taking much less time than it otherwise would. Cool, isn’t it?