For the out-of-tree build, scripts/Makefile.build creates output directories, but this operation is not efficient. scripts/Makefile.lib calculates obj-dirs as follows: obj-dirs := $(dir $(multi-objs) $(obj-y)) Please notice $(sort ...) is not used here. Usually the result is as many "./" as objects here. For a lot of duplicated paths, the following command is invoked. _dummy := $(foreach d,$(obj-dirs), $(shell [ -d $(d) ] || mkdir -p $(d))) Then, the costly shell command is run over and over again. I see many points for optimization: [1] Use $(sort ...) to cut down duplicated paths before passing them to system call [2] Use single $(shell ...) instead of repeating it with $(foreach ...) This will reduce forking. [3] We can calculate obj-dirs more simply. Most of objects are already accumulated in $(targets). So, $(dir $(targets)) is fine and more comprehensive. I also removed ugly code in arch/x86/entry/vdso/Makefile. This is now really unnecessary.
Showing the changes to scripts/Makefile.lib (1 of 4 files). Show all
Unified · Split
| @@ -50,15 +50,11 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m))) · 49 unmodified lines | ||
| 50 | 50 | # objects depend on those (obviously) |
| 51 | 51 | multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)) $($(m:.o=-y))) |
| 52 | 52 | multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)) $($(m:.o=-y))) |
| 53 | −multi-objs := $(multi-objs-y) $(multi-objs-m) | |
| 54 | 53 | |
| 55 | 54 | # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to |
| 56 | 55 | # tell kbuild to descend |
| 57 | 56 | subdir-obj-y := $(filter %/built-in.o, $(obj-y)) |
| 58 | 57 | |
| 59 | −# $(obj-dirs) is a list of directories that contain object files | |
| 60 | −obj-dirs := $(dir $(multi-objs) $(obj-y)) | |
| 61 | − | |
| 62 | 58 | # Replace multi-part objects by their individual parts, look at local dir only |
| 63 | 59 | real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m))) $(extra-y) |
| 64 | 60 | real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m))) |
| @@ -81,7 +77,6 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) · 16 unmodified lines | ||
| 81 | 77 | multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) |
| 82 | 78 | multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) |
| 83 | 79 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) |
| 84 | −obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) | |
| 85 | 80 | |
| 86 | 81 | # These flags are needed for modversions and compiling, so we define them here |
| 87 | 82 | # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will |