Cleanup io.h
Subsystems (4)
v2 cover Cleanup io.h
In a wider effort to improve build speeds, we're attempting to split/cleanup core headers.
This series attempts to cleanup io.h with "include what you need" approach.
This depends on earlier modifications available in immutable tag[1]. Feel free to carry your subsystem patches with it, or let Andy know if you'd rather let him carry them.
[1] https://lore.kernel.org/r/[email protected]/
v2: Fix drm_draw.c build errors
Raag Jadav (2):
io.h: drop unused headers
drm/draw: include bug.h
drivers/gpu/drm/drm_draw.c | 1 + include/linux/io.h | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-)
base-commit: b16e9f8547a328b19af59afc213ce323124d11e9
Signature · 1 line
2.34.1
PATCH v2 1/2 io.h: drop unused headers
Drop unused headers and type declaration from io.h.
--- include/linux/io.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/io.h +0 -3
@@ -9,13 +9,10 @@#include <linux/sizes.h> #include <linux/types.h> #include <linux/init.h> -#include <linux/bug.h> -#include <linux/err.h> #include <asm/io.h> #include <asm/page.h> struct device ; -struct resource ;#ifndef __iowrite32_copyvoid __iowrite32_copy (void __iomem *to,const void *from,size_t count);
Signature · 1 line
2.34.1
PATCH v2 2/2 drm/draw: include bug.h
In reply to Raag JadavDirectly include bug.h for WARN() helpers instead of relying on intermediate headers.
--- drivers/gpu/drm/drm_draw.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_draw.c +1 -0
@@ -5,6 +5,7 @@*/ #include <linux/bits.h> +#include <linux/bug.h> #include <linux/iosys-map.h> #include <linux/types.h>
Signature · 1 line
2.34.1
Re: [PATCH v2 2/2] drm/draw: include bug.h
Quoted 23 lines · Raag Jadav
Directly include
bug.hforWARN()helpers instead of relying on intermediate headers.Signed-off-by Raag Jadav <[email protected]>--- drivers/gpu/drm/drm_draw.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_draw.c +1
-0@@ -5,6 +5,7 @@*/ #include <linux/bits.h> +#include <linux/bug.h> #include <linux/iosys-map.h> #include <linux/types.h> Signature · 1 line
2.34.1
Does patch 1 break this file without this patch so this series is not in order?
I'll be glad to take patch 1 in my tree, but I don't want to break anything else.
thanks,
greg k-h
Simona Vetter
Acked-byRe: [PATCH v2 2/2] drm/draw: include bug.h
Quoted 28 lines · Greg KH
Quoted 23 lines · Raag Jadav
Directly include
bug.hforWARN()helpers instead of relying on intermediate headers.Signed-off-by Raag Jadav <[email protected]>--- drivers/gpu/drm/drm_draw.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_draw.c +1
-0@@ -5,6 +5,7 @@*/ #include <linux/bits.h> +#include <linux/bug.h> #include <linux/iosys-map.h> #include <linux/types.h> Signature · 1 line
2.34.1Does patch 1 break this file without this patch so this series is not in order?
Quoted 2 lines
I'll be glad to take patch 1 in my tree, but I don't want to break anything else.
Yeah looks inverted. In case this is all there is I'm happy to land this patch through your tree, that seems like the simplest approach.
Cheers, Sima
Signature · 3 lines
Simona Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v2 2/2] drm/draw: include bug.h
Quoted 29 lines · Simona Vetter
Quoted 28 lines · Greg KH
Quoted 23 lines · Raag Jadav
Directly include
bug.hforWARN()helpers instead of relying on intermediate headers.Signed-off-by Raag Jadav <[email protected]>--- drivers/gpu/drm/drm_draw.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_draw.c +1
-0@@ -5,6 +5,7 @@*/ #include <linux/bits.h> +#include <linux/bug.h> #include <linux/iosys-map.h> #include <linux/types.h> Signature · 1 line
2.34.1Does patch 1 break this file without this patch so this series is not in order?
Quoted 5 lines
Quoted 2 lines
I'll be glad to take patch 1 in my tree, but I don't want to break anything else.
Yeah looks inverted. In case this is all there is I'm happy to land this patch through your tree, that seems like the simplest approach.
Yep, I messed up the ordering. Let me send out a v3 since I need to fix nios2 builds anyway.
Quoted 1 line
Acked-by Simona Vetter <[email protected]>
Thank you!
Raag
Quoted 5 lines · Raag Jadav
In a wider effort to improve build speeds, we're attempting to split/cleanup core headers.
This series attempts to cleanup
io.hwith "include what you need" approach.
Quoted 7 lines
This depends on earlier modifications available in immutable tag[1]. Feel free to carry your subsystem patches with it, or let Andy know if you'd rather let him carry them.
[1] https://lore.kernel.org/r/[email protected]/
v2: Fix
drm_draw.cbuild errors
Hi Raag,
I think your patch is to linux/io.h is correct and we should eventually apply it, but I think the header file cleanup needs to be done in a little more structured way or it ends up causing a lot of extra work for very little gain.
As you already found, removing an old indirect #include that is no longer needed usually leads to some files breaking. The more impactful your change is in terms of build speed, the more things break! I think in this case, removing linux/err.h and linux/bug.h made very little difference because they are very small files in terms of what else they include.
The approach that I would suggest you take is:
1. identify a header file that is included indirectly in a lot of places and also has a ton of indirect inclusions inside it
2. split it up in a way that most indirect inclusions can be replaced with a much smaller varient
3. repeat step 1 and 2 for additional headers, splitting them up but leaving the inclusions in place for the moment
4. test thousands of randconfig builds across architectures with the unnecessary indirect inclusions removed, send fixup patches for the drivers to add the missing direct #include statements, one patch per subsystem
5. once the known regressions are fixed, actually propose removing the extra #include statements and fix the remaining regressions
If you are looking for a good place to start with step 1, the way I've done this in the past is to calculate for each header file how often it gets included in a particular build and how large the preprocessed files are, then sort them by the product of the two. These are the top entries I see for an arm64 defconfig
#incl #lines file
7054 41901 include/linux/module.i
7146 39685 include/linux/fs.i
7057 39996 include/linux/elf.i
5667 44323 include/linux/energy_model.i
5667 44322 include/linux/device.i
5668 42467 include/linux/device/driver.i
4707 47776 include/linux/mm.i
7151 29653 include/linux/kobject.i
7151 29494 include/linux/sysfs.i
7146 29090 include/linux/percpu-rwsem.i
7152 28963 include/linux/rcuwait.i
7154 28929 include/linux/sched/signal.i
7151 28608 include/linux/kernfs.i
3713 55040 include/linux/kprobes.i
3707 55113 include/linux/kgdb.i
3718 54591 include/linux/ftrace.i
7366 27519 include/linux/slab.i
7146 28276 include/linux/ioprio.i
7190 28029 include/linux/radix-tree.i
7159 28137 include/linux/idr.i
7146 28098 include/linux/iocontext.i
3390 59188 include/linux/bio.i
7146 28073 include/linux/list_lru.i
7192 27842 include/linux/xarray.i
3390 58566 include/linux/blk_types.i
3176 62442 include/linux/writeback.i
7366 26873 include/linux/percpu-refcount.i
3538 55872 include/linux/highmem.i
7054 27934 include/linux/kmod.i
7382 26691 include/linux/gfp.i
7054 27925 include/linux/umh.i
3538 55255 include/linux/cacheflush.i
7382 26416 include/linux/topology.i
3053 63637 include/linux/memcontrol.i
7193 27010 include/linux/sched/mm.i
7382 26210 include/linux/mmzone.i
7382 26210 include/linux/memory_hotplug.i
4707 40968 include/linux/huge_mm.i
3428 56061 include/linux/bvec.i
3713 49335 include/linux/rethook.i
...
5159 28781 include/linux/io.i
You can pick any one of these and try to analyze why the header gets included absolutely everywhere, and why it is so huge, then try to come up with an idea for how to improve that based on what you found.
When you do the analysis for linux/io.h, you find that it's only on #72 on that list (for arm64 defconfig), and that almost all of its 28781 lines come from one of these indirectly included files (sorted by number of lines after preprocessing), not from bug.h or err.h:
27569 include/linux/pgtable.h
24636 include/linux/mmu_notifier.h
24217 include/linux/page-flags.h
23860 include/linux/mmap_lock.h
23670 include/linux/mm_types.h
21468 include/linux/srcu.h
21355 include/linux/uprobes.h
20746 include/linux/workqueue.h
20091 include/linux/timer.h
19950 include/linux/ktime.h
19949 include/linux/timekeeping.h
19536 include/linux/jiffies.h
19428 include/linux/timex.h
19428 include/linux/time.h
19427 include/linux/time32.h
18716 include/linux/percpu_counter.h
18595 include/linux/percpu.h
18390 include/linux/sched.h
16879 include/linux/maple_tree.h
16699 include/linux/seqlock.h
16527 include/linux/kref.h
16472 include/linux/completion.h
16429 include/linux/swait.h
16388 include/linux/wait.h
16364 include/linux/rwsem.h
Note that a lot of these are indirectly included multiple times below linux/io.h. Almost none of the above have any business being included in linux/io.h.
Arnd
Quoted 132 lines · Arnd Bergmann
Quoted 5 lines · Raag Jadav
In a wider effort to improve build speeds, we're attempting to split/cleanup core headers.
This series attempts to cleanup
io.hwith "include what you need" approach.Quoted 7 lines
This depends on earlier modifications available in immutable tag[1]. Feel free to carry your subsystem patches with it, or let Andy know if you'd rather let him carry them.
[1] https://lore.kernel.org/r/[email protected]/
v2: Fix
drm_draw.cbuild errorsHi Raag,
I think your patch is to
linux/io.his correct and we should eventually apply it, but I think the header file cleanup needs to be done in a little more structured way or it ends up causing a lot of extra work for very little gain.As you already found, removing an old indirect #include that is no longer needed usually leads to some files breaking. The more impactful your change is in terms of build speed, the more things break! I think in this case, removing
linux/err.handlinux/bug.hmade very little difference because they are very small files in terms of what else they include.The approach that I would suggest you take is:
1. identify a header file that is included indirectly in a lot of places and also has a ton of indirect inclusions inside it
2. split it up in a way that most indirect inclusions can be replaced with a much smaller varient
3. repeat step 1 and 2 for additional headers, splitting them up but leaving the inclusions in place for the moment
4. test thousands of randconfig builds across architectures with the unnecessary indirect inclusions removed, send fixup patches for the drivers to add the missing direct #include statements, one patch per subsystem
5. once the known regressions are fixed, actually propose removing the extra #include statements and fix the remaining regressionsIf you are looking for a good place to start with step 1, the way I've done this in the past is to calculate for each header file how often it gets included in a particular build and how large the preprocessed files are, then sort them by the product of the two. These are the top entries I see for an arm64 defconfig
#incl #lines file
7054 41901include/linux/module.i
7146 39685include/linux/fs.i
7057 39996include/linux/elf.i
5667 44323include/linux/energy_model.i
5667 44322include/linux/device.i
5668 42467include/linux/device/driver.i
4707 47776include/linux/mm.i
7151 29653include/linux/kobject.i
7151 29494include/linux/sysfs.i
7146 29090include/linux/percpu-rwsem.i
7152 28963include/linux/rcuwait.i
7154 28929include/linux/sched/signal.i
7151 28608include/linux/kernfs.i
3713 55040include/linux/kprobes.i
3707 55113include/linux/kgdb.i
3718 54591include/linux/ftrace.i
7366 27519include/linux/slab.i
7146 28276include/linux/ioprio.i
7190 28029include/linux/radix-tree.i
7159 28137include/linux/idr.i
7146 28098include/linux/iocontext.i
3390 59188include/linux/bio.i
7146 28073include/linux/list_lru.i
7192 27842include/linux/xarray.i
3390 58566include/linux/blk_types.i
3176 62442include/linux/writeback.i
7366 26873include/linux/percpu-refcount.i
3538 55872include/linux/highmem.i
7054 27934include/linux/kmod.i
7382 26691include/linux/gfp.i
7054 27925include/linux/umh.i
3538 55255include/linux/cacheflush.i
7382 26416include/linux/topology.i
3053 63637include/linux/memcontrol.i
7193 27010include/linux/sched/mm.i
7382 26210include/linux/mmzone.i
7382 26210include/linux/memory_hotplug.i
4707 40968include/linux/huge_mm.i
3428 56061include/linux/bvec.i
3713 49335include/linux/rethook.i
...
5159 28781include/linux/io.iYou can pick any one of these and try to analyze why the header gets included absolutely everywhere, and why it is so huge, then try to come up with an idea for how to improve that based on what you found.
When you do the analysis for
linux/io.h, you find that it's only on #72 on that list (for arm64 defconfig), and that almost all of its 28781 lines come from one of these indirectly included files (sorted by number of lines after preprocessing), not frombug.horerr.h:27569
include/linux/pgtable.h
24636include/linux/mmu_notifier.h
24217include/linux/page-flags.h
23860include/linux/mmap_lock.h
23670include/linux/mm_types.h
21468include/linux/srcu.h
21355include/linux/uprobes.h
20746include/linux/workqueue.h
20091include/linux/timer.h
19950include/linux/ktime.h
19949include/linux/timekeeping.h
19536include/linux/jiffies.h
19428include/linux/timex.h
19428include/linux/time.h
19427include/linux/time32.h
18716include/linux/percpu_counter.h
18595include/linux/percpu.h
18390include/linux/sched.h
16879include/linux/maple_tree.h
16699include/linux/seqlock.h
16527include/linux/kref.h
16472include/linux/completion.h
16429include/linux/swait.h
16388include/linux/wait.h
16364include/linux/rwsem.h
Quoted 3 lines
Note that a lot of these are indirectly included multiple times below
linux/io.h. Almost none of the above have any business being included inlinux/io.h.
Excellent! Thanks for laying out a great analysis and points worth considering. It seems this will require extensive study and motivation, and is definitely not as obvious and simple as this series, but I'll surely look into it later on.
Raag
Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · Raag Jadav
In a wider effort to improve build speeds, we're attempting to split/cleanup core headers.
This series attempts to cleanup
io.hwith "include what you need" approach.Quoted 7 lines
This depends on earlier modifications available in immutable tag[1]. Feel free to carry your subsystem patches with it, or let Andy know if you'd rather let him carry them.
[1] https://lore.kernel.org/r/[email protected]/
v2: Fix
drm_draw.cbuild errorsHi Raag,
I think your patch is to
linux/io.his correct and we should eventually apply it, but I think the header file cleanup needs to be done in a little more structured way or it ends up causing a lot of extra work for very little gain.
Quoted 6 lines
As you already found, removing an old indirect #include that is no longer needed usually leads to some files breaking. The more impactful your change is in terms of build speed, the more things break! I think in this case, removing
linux/err.handlinux/bug.hmade very little difference because they are very small files in terms of what else they include.
While this is all true, removing unneeded inclusions rarely can lead to the "extra work with a little gain". When there is a replacement to the low level ones, it's also an improvement in my opinion and won't be harmful in the future. But I agree, that the stuff is way too tangled already and requires an enormous work to untangle it, even if doing it structurally.
...
Do you have your scripts for the showed statistics being published somewhere?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Arnd Bergmann
As you already found, removing an old indirect #include that is no longer needed usually leads to some files breaking. The more impactful your change is in terms of build speed, the more things break! I think in this case, removing
linux/err.handlinux/bug.hmade very little difference because they are very small files in terms of what else they include.
Quoted 5 lines
While this is all true, removing unneeded inclusions rarely can lead to the "extra work with a little gain". When there is a replacement to the low level ones, it's also an improvement in my opinion and won't be harmful in the future. But I agree, that the stuff is way too tangled already and requires an enormous work to untangle it, even if doing it structurally.
The problem I see with prematurely applying small improvements like this one is that they always cause build regressions, at least if the change is any good. If we can find some more impactful changes like this one, we can group them together in a branch and test them a lot better before they even reach linux-next.
I mainly want to avoid people getting angry at Raag for repeatedly breaking their subsystems by pushing small patches one at a time.
Quoted 1 line
Do you have your scripts for the showed statistics being published somewhere?
I had a good set of scripts on an older machine and might still have some backups of that somewhere, but just hacked up something ad-hoc today beased on what I remembered from that time. Here are the snippets that you might find useful.
A patch to Kbuild to create a list of each included header for each object file built in a given configuration (similar to the .filename.o.d files, but in a format I found more convenient):
scripts/Makefile.lib +2 -1
@@ -307,7 +307,8 @@ cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) - endif quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ - cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \ + cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< ; \ + $(CC) $(c_flags) -E -o - $< | grep ^\#.*include | cut -f 2 -d\" | sort -u > [email protected] \ $(cmd_ld_single) \ $(cmd_objtool)
shell oneliner to find the header files that are most commonly included from those files:
$ find -name \*includes | xargs cat | sort | uniq -c | sed -e 's:\./\|\././::g' | sort -rn | head -n 1000 > mostincluded
oneliner to preprocess each of those headers
$ cat mostincluded | grep include/linux | while read a i ; do gcc -E $i -o ${i%.h}.i ${GCCARGS} ; doneoneliner to sort by product of includes and lines:
$ cat mostincluded | grep include/linux/ | while read a b ; do if [ -e ${b%.h}.i ] ; then echo $a `wc -l ${b%.h}.i` ; fi ; done | sort -n -k2 | while read a b c ; do echo $[$a * $b] $a $b $c ; done | sort -nr > fulllistIn the old days, I had cleaner versions of these in an automated script, and produced a .dot file to visualize the dependencies with graphviz. I did get to the point of more than doubling compile speed, so there was a clear incentive to continue. In fact, the further I got along the way, the better the savings. In the end I gave up when I could not get to a useful subset to upstream first that wouldn't already break hundreds of drivers.
The best idea I have to avoid that is to pick one header to clean up from my list and do all the prerequisites but not actually break anything at first.
Arnd
Quoted 24 lines · Arnd Bergmann
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Arnd Bergmann
As you already found, removing an old indirect #include that is no longer needed usually leads to some files breaking. The more impactful your change is in terms of build speed, the more things break! I think in this case, removing
linux/err.handlinux/bug.hmade very little difference because they are very small files in terms of what else they include.Quoted 5 lines
While this is all true, removing unneeded inclusions rarely can lead to the "extra work with a little gain". When there is a replacement to the low level ones, it's also an improvement in my opinion and won't be harmful in the future. But I agree, that the stuff is way too tangled already and requires an enormous work to untangle it, even if doing it structurally.
The problem I see with prematurely applying small improvements like this one is that they always cause build regressions, at least if the change is any good. If we can find some more impactful changes like this one, we can group them together in a branch and test them a lot better before they even reach linux-next.
I mainly want to avoid people getting angry at Raag for repeatedly breaking their subsystems by pushing small patches one at a time.
Quoted 6 lines
Quoted 1 line
Do you have your scripts for the showed statistics being published somewhere?
I had a good set of scripts on an older machine and might still have some backups of that somewhere, but just hacked up something ad-hoc today beased on what I remembered from that time. Here are the snippets that you might find useful.
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 10 lines · Raag Jadav
In a wider effort to improve build speeds, we're attempting to split/cleanup core headers.
This series attempts to cleanup
io.hwith "include what you need" approach.This depends on earlier modifications available in immutable tag[1]. Feel free to carry your subsystem patches with it, or let Andy know if you'd rather let him carry them.
Oh, you are fast! Please, read my comments in v1 as well an take them into account.
Signature · 2 lines
With Best Regards, Andy Shevchenko