Skip to contentSkip to conversation

coccicheck: process every source file at once

PATCH In review Jacob Keller 6 participants 20 messages Oct 2, 2018 – Oct 10, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 coccicheck: process every source file at once

From: Jacob Keller <[email protected]>

make coccicheck is used in order to apply coccinelle semantic patches, and see if any of the transformations found within contrib/coccinelle/ can be applied to the current code base.

Pass every file to a single invocation of spatch, instead of running spatch once per source file.

This reduces the time required to run make coccicheck by a significant amount of time:

Prior timing of make coccicheck

  real    6m14.090s
  user    25m2.606s
  sys     1m22.919s

New timing of make coccicheck

  real    1m36.580s
  user    7m55.933s
  sys     0m18.219s

This is nearly a 4x decrease in the time required to run make coccicheck. This is due to the overhead of restarting spatch for every file. By processing all files at once, we can amortize this startup cost across the total number of files, rather than paying it once per file.

---
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +2 -4
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
 	@echo '    ' SPATCH $<; \
 	ret=0; \
-	for f in $(COCCI_SOURCES); do \
-		$(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-			{ ret=$$?; break; }; \
-	done >$@+ 2>[email protected]; \
+	$(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+	ret=$$?; \
 	if test $$ret != 0; \
 	then \
 		cat [email protected]; \
Signature · 1 line
2.18.0.219.gaf81d287a9da
#1 lore raw
Quoted 23 lines · Jacob Keller

From: Jacob Keller <[email protected]>

make coccicheck is used in order to apply coccinelle semantic patches, and see if any of the transformations found within contrib/coccinelle/ can be applied to the current code base.

Pass every file to a single invocation of spatch, instead of running spatch once per source file.

This reduces the time required to run make coccicheck by a significant amount of time:

Prior timing of make coccicheck

  real    6m14.090s
  user    25m2.606s
  sys     1m22.919s

New timing of make coccicheck

  real    1m36.580s
  user    7m55.933s
  sys     0m18.219s
Quoted 7 lines

This is nearly a 4x decrease in the time required to run make coccicheck. This is due to the overhead of restarting spatch for every file. By processing all files at once, we can amortize this startup cost across the total number of files, rather than paying it once per file.

---

Forgot to add what changed. I dropped the subshell and "||" bit around invoking spatch.

Thanks,
Jake

Quoted 23 lines
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +2 -5
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
+       $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+       ret=$$?; \
        if test $$ret != 0; \
        then \
                cat [email protected]; \
--

2.18.0.219.gaf81d287a9da

#2 lore raw
Quoted 30 lines · Jacob Keller
Quoted 28 lines · Jacob Keller

From: Jacob Keller <[email protected]>

make coccicheck is used in order to apply coccinelle semantic patches, and see if any of the transformations found within contrib/coccinelle/ can be applied to the current code base.

Pass every file to a single invocation of spatch, instead of running spatch once per source file.

This reduces the time required to run make coccicheck by a significant amount of time:

Prior timing of make coccicheck

  real    6m14.090s
  user    25m2.606s
  sys     1m22.919s

New timing of make coccicheck

  real    1m36.580s
  user    7m55.933s
  sys     0m18.219s

This is nearly a 4x decrease in the time required to run make coccicheck. This is due to the overhead of restarting spatch for every file. By processing all files at once, we can amortize this startup cost across the total number of files, rather than paying it once per file.

Quoted 9 lines
Quoted 2 lines

---

Forgot to add what changed. I dropped the subshell and "||" bit around invoking spatch.

Thanks,
Jake

Junio, do you want me to update the commit message on my side with the memory concerns? Or could you update it to mention memory as a noted trade off.

Thanks,
Jake

Quoted 24 lines
Quoted 24 lines
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +2 -5
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
+       $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+       ret=$$?; \
        if test $$ret != 0; \
        then \
                cat [email protected]; \
--

2.18.0.219.gaf81d287a9da

#3 lore raw
Quoted 3 lines · Jacob Keller

Junio, do you want me to update the commit message on my side with the memory concerns? Or could you update it to mention memory as a noted trade off.

We have been running 'make -j2 coccicheck' in the static analysis build job on Travis CI, which worked just fine so far. The Travis CI build environments have 3GB of memory available [1], but, as shown in [2], with this patch the memory consumption jumps up to about 1.3-1.8GB for each of those jobs. So with two parallel jobs we will very likely bump into this limit.

So this patch should definitely change that build script to run only a single job.

1 - https://docs.travis-ci.com/user/common-build-problems/#my-build-script-is-killed-without-any-error
2 - https://public-inbox.org/git/20181003101658.GM23446@localhost/

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +2 -5
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
+       $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+       ret=$$?; \
        if test $$ret != 0; \
        then \
                cat [email protected]; \
--

2.18.0.219.gaf81d287a9da

#4 lore raw
Quoted 12 lines · SZEDER Gábor
Quoted 3 lines · Jacob Keller

Junio, do you want me to update the commit message on my side with the memory concerns? Or could you update it to mention memory as a noted trade off.

We have been running 'make -j2 coccicheck' in the static analysis build job on Travis CI, which worked just fine so far. The Travis CI build environments have 3GB of memory available [1], but, as shown in [2], with this patch the memory consumption jumps up to about 1.3-1.8GB for each of those jobs. So with two parallel jobs we will very likely bump into this limit.

Quoted 2 lines

So this patch should definitely change that build script to run only a single job.

It should still be a net win, since the total CPU seems to drop by a factor of 3-4.

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

#5 lore raw
Quoted 28 lines

-----Original Message-----
From: Jeff King [mailto:[email protected]]
Sent: Friday, October 05, 2018 9:25 AM
To: SZEDER Gábor <[email protected]>
Cc: Jacob Keller <[email protected]>; Keller, Jacob E <[email protected]>; Git mailing list <[email protected]>
Subject: Re: [PATCH v3] coccicheck: process every source file at once

Quoted 12 lines · SZEDER Gábor
Quoted 3 lines · Jacob Keller

Junio, do you want me to update the commit message on my side with the memory concerns? Or could you update it to mention memory as a noted trade off.

We have been running 'make -j2 coccicheck' in the static analysis build job on Travis CI, which worked just fine so far. The Travis CI build environments have 3GB of memory available [1], but, as shown in [2], with this patch the memory consumption jumps up to about 1.3-1.8GB for each of those jobs. So with two parallel jobs we will very likely bump into this limit.

Quoted 2 lines

So this patch should definitely change that build script to run only a single job.

It should still be a net win, since the total CPU seems to drop by a factor of 3-4.

Quoted 6 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

It's probably not worth trying to make this more complicated and scale up how many files we do at once based on the amount of available memory on the system...

Thanks,
Jake

#6 lore raw
Quoted 10 lines · Jacob E
Quoted 6 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

It's probably not worth trying to make this more complicated and scale up how many files we do at once based on the amount of available memory on the system...

Yeah, that sounds too complicated. At most I'd give a Makefile knob to say "spatch in batches of $(N)". But I'd prefer to avoid even that complexity if we can.

-Peff

#12 lore raw
In reply to Jeff King
Quoted 14 lines · Jeff King
Quoted 12 lines · SZEDER Gábor
Quoted 3 lines · Jacob Keller

Junio, do you want me to update the commit message on my side with the memory concerns? Or could you update it to mention memory as a noted trade off.

We have been running 'make -j2 coccicheck' in the static analysis build job on Travis CI, which worked just fine so far. The Travis CI build environments have 3GB of memory available [1], but, as shown in [2], with this patch the memory consumption jumps up to about 1.3-1.8GB for each of those jobs. So with two parallel jobs we will very likely bump into this limit.

Quoted 5 lines
Quoted 2 lines

So this patch should definitely change that build script to run only a single job.

It should still be a net win, since the total CPU seems to drop by a factor of 3-4.

Well, that's true when you have unlimited resources... :) or it's true even then, when I have just enough resources, but not much contention. After all, Coccinelle doesn't have to parse the same header files over and over again. However, on Travis CI, where who knows how many other build jobs are running next to our static analysis, it doesn't seem to be the case.

On current master with an additional 'time' in front:

  time make --jobs=2 coccicheck
  <...>
  695.70user 50.27system 6:27.88elapsed 192%CPU (0avgtext+0avgdata 91448maxresident)k
  5976inputs+2536outputs (42major+18411888minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437733874#L574

With this patch, but without -j2 to fit into 3GB:

960.50user 22.59system 16:23.74elapsed 99%CPU (0avgtext+0avgdata 1606156maxresident)k 5976inputs+1320outputs (26major+4548440minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437734003#L575

Note that both the runtime and the CPU time increased. (and RSS, of course)

Quoted 6 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

#7 lore raw
In reply to Jeff King
Quoted 9 lines · Jeff King
Quoted 7 lines · Jacob E
Quoted 6 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

Quoted 7 lines
Quoted 3 lines

It's probably not worth trying to make this more complicated and scale up how many files we do at once based on the amount of available memory on the system...

Yeah, that sounds too complicated. At most I'd give a Makefile knob to say "spatch in batches of $(N)". But I'd prefer to avoid even that complexity if we can.

But perhaps one more if-else, e.g.:

  if test -n "$(COCCICHECK_ALL_AT_ONCE)"; then \
      <all at once from Jacob>
  else
      <old for loop>
  fi

would be an acceptable compromise? Dunno.

#8 lore raw
Quoted 20 lines · SZEDER Gábor
Quoted 9 lines · Jeff King
Quoted 7 lines · Jacob E
Quoted 6 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

Quoted 7 lines
Quoted 3 lines

It's probably not worth trying to make this more complicated and scale up how many files we do at once based on the amount of available memory on the system...

Yeah, that sounds too complicated. At most I'd give a Makefile knob to say "spatch in batches of $(N)". But I'd prefer to avoid even that complexity if we can.

But perhaps one more if-else, e.g.:

Quoted 7 lines
  if test -n "$(COCCICHECK_ALL_AT_ONCE)"; then \
      <all at once from Jacob>
  else
      <old for loop>
  fi

would be an acceptable compromise? Dunno.

That's OK, too, assuming people would actually want to use it. I'm also OK shipping this (with the "make -j" fix you suggested) and seeing if anybody actually complains. I assume there are only a handful of people running coccicheck in the first place.

-Peff

#13 lore raw
In reply to SZEDER Gábor
Quoted 21 lines · SZEDER Gábor
Quoted 2 lines

It should still be a net win, since the total CPU seems to drop by a factor of 3-4.

Well, that's true when you have unlimited resources... :) or it's true even then, when I have just enough resources, but not much contention. After all, Coccinelle doesn't have to parse the same header files over and over again. However, on Travis CI, where who knows how many other build jobs are running next to our static analysis, it doesn't seem to be the case.

On current master with an additional 'time' in front:

  time make --jobs=2 coccicheck
  <...>
  695.70user 50.27system 6:27.88elapsed 192%CPU (0avgtext+0avgdata 91448maxresident)k
  5976inputs+2536outputs (42major+18411888minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437733874#L574

With this patch, but without -j2 to fit into 3GB:

Quoted 7 lines

960.50user 22.59system 16:23.74elapsed 99%CPU (0avgtext+0avgdata 1606156maxresident)k 5976inputs+1320outputs (26major+4548440minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437734003#L575

Note that both the runtime and the CPU time increased. (and RSS, of course)

I'm not sure what to make of those results. Was the jump in CPU _caused_ by the patch, or does it independently fluctuate based on other things happening on the Travis servers?

I.e., in the second run, do we know that the time would not have actually been worse with the first patch?

-Peff

#14 lore raw
Quoted 31 lines · Jeff King
Quoted 21 lines · SZEDER Gábor
Quoted 2 lines

It should still be a net win, since the total CPU seems to drop by a factor of 3-4.

Well, that's true when you have unlimited resources... :) or it's true even then, when I have just enough resources, but not much contention. After all, Coccinelle doesn't have to parse the same header files over and over again. However, on Travis CI, where who knows how many other build jobs are running next to our static analysis, it doesn't seem to be the case.

On current master with an additional 'time' in front:

  time make --jobs=2 coccicheck
  <...>
  695.70user 50.27system 6:27.88elapsed 192%CPU (0avgtext+0avgdata 91448maxresident)k
  5976inputs+2536outputs (42major+18411888minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437733874#L574

With this patch, but without -j2 to fit into 3GB:

Quoted 7 lines

960.50user 22.59system 16:23.74elapsed 99%CPU (0avgtext+0avgdata 1606156maxresident)k 5976inputs+1320outputs (26major+4548440minor)pagefaults 0swaps

https://travis-ci.org/szeder/git/jobs/437734003#L575

Note that both the runtime and the CPU time increased. (and RSS, of course)

Quoted 6 lines

I'm not sure what to make of those results. Was the jump in CPU _caused_ by the patch, or does it independently fluctuate based on other things happening on the Travis servers?

I.e., in the second run, do we know that the time would not have actually been worse with the first patch?

Runtimes tend to fluctuate quite a bit more on Travis CI compared to my machine, but not this much, and it seems to be consistent so far.

After scripting/querying the Travis CI API a bit, I found that from the last 100 static analysis build jobs 78 did actully run 'make coccicheck' [1], avaraging 470s for the whole build job, with only 4 build job exceeding the 10min mark.

I had maybe 6-8 build jobs running this patch over the last 2-3 days, I think all of them were over 15min. (I restarted some of them, so I don't have separate logs for all of them, hence the uncertainty.)

1 - There are a couple of canceled build jobs, and we skip the build
job of branches when they happen to match a tags.

#9 lore raw
In reply to Jeff King
Quoted 6 lines · Jeff King

That's OK, too, assuming people would actually want to use it. I'm also OK shipping this (with the "make -j" fix you suggested) and seeing if anybody actually complains. I assume there are only a handful of people running coccicheck in the first place.

-Peff

Ok. I can go this route if we have consensus on the "break it and see if someone complains" route.

Regards,
Jake

#10 lore raw
In reply to Jeff King

Am 05.10.2018 um 21:00 schrieb Jeff King:

Quoted 28 lines · SZEDER Gábor
Quoted 27 lines · Jeff King
Quoted 9 lines · Jacob E
Quoted 8 lines
Quoted 7 lines

Are we OK with saying 1.3-1.8GB is necessary to run coccicheck? That doesn't feel like an exorbitant request for a developer-only tool these days, but I have noticed some people on the list tend to have lousier machines than I do. ;)

-Peff

Quoted 7 lines
Quoted 3 lines

It's probably not worth trying to make this more complicated and scale up how many files we do at once based on the amount of available memory on the system...

Yeah, that sounds too complicated. At most I'd give a Makefile knob to say "spatch in batches of $(N)". But I'd prefer to avoid even that complexity if we can.

But perhaps one more if-else, e.g.:

  if test -n "$(COCCICHECK_ALL_AT_ONCE)"; then \
      <all at once from Jacob>
  else
      <old for loop>
  fi
Quoted 6 lines
Quoted 1 line

would be an acceptable compromise? Dunno.

That's OK, too, assuming people would actually want to use it. I'm also OK shipping this (with the "make -j" fix you suggested) and seeing if anybody actually complains. I assume there are only a handful of people running coccicheck in the first place.

FWIW, my development environment is a virtual machine with 1200MB RAM and 900MB swap space. coccicheck takes almost eight minutes sequentially, and four and a half minutes with -j4.

Unsurprisingly, it fails after almost three minutes with the patch, reporting that it ran out of memory. With 2900MB it fails after almost two minutes, with 3000MB it succeeds after a good two minutes.

time(1) says (for -j1):

433.30user 36.17system 7:49.84elapsed 99%CPU (0avgtext+0avgdata 108212maxresident)k 192inputs+1512outputs (0major+16409056minor)pagefaults 0swaps

129.74user 2.06system 2:13.27elapsed 98%CPU (0avgtext+0avgdata 1884568maxresident)k 236896inputs+1096outputs (795major+462129minor)pagefaults 0swaps

So with the patch it's more than three times faster, but needs more than seventeen times more memory. And I need a bigger VM. :-/

René

#18 lore raw
In reply to Jacob Keller
Quoted 54 lines · Jacob Keller
Quoted 23 lines · Jacob Keller

From: Jacob Keller <[email protected]>

make coccicheck is used in order to apply coccinelle semantic patches, and see if any of the transformations found within contrib/coccinelle/ can be applied to the current code base.

Pass every file to a single invocation of spatch, instead of running spatch once per source file.

This reduces the time required to run make coccicheck by a significant amount of time:

Prior timing of make coccicheck

  real    6m14.090s
  user    25m2.606s
  sys     1m22.919s

New timing of make coccicheck

  real    1m36.580s
  user    7m55.933s
  sys     0m18.219s
Quoted 7 lines

This is nearly a 4x decrease in the time required to run make coccicheck. This is due to the overhead of restarting spatch for every file. By processing all files at once, we can amortize this startup cost across the total number of files, rather than paying it once per file.

---

Forgot to add what changed. I dropped the subshell and "||" bit around invoking spatch.

Thanks,
Jake

Quoted 15 lines
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +0 -4
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
Quoted 8 lines
Quoted 8 lines
Makefile +2 -1
+       $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+       ret=$$?; \
        if test $$ret != 0; \
        then \
                cat [email protected]; \
--

2.18.0.219.gaf81d287a9da

Wouldn't the following be even simpler?

Makefile +1 -6
index 5c8307b7c479..a37b2724d526 100644
@@ -2701,12 +2701,7 @@ endif
 
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
-       ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
-       if test $$ret != 0; \
+       if ! $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS)
Quoted 1 line

$@+ 2>[email protected]; \

        then \
                cat [email protected]; \
                exit 1; \

Cheers,
Beat

#19 lore raw
Quoted 72 lines · Beat Bolli
Quoted 54 lines · Jacob Keller
Quoted 23 lines · Jacob Keller

From: Jacob Keller <[email protected]>

make coccicheck is used in order to apply coccinelle semantic patches, and see if any of the transformations found within contrib/coccinelle/ can be applied to the current code base.

Pass every file to a single invocation of spatch, instead of running spatch once per source file.

This reduces the time required to run make coccicheck by a significant amount of time:

Prior timing of make coccicheck

  real    6m14.090s
  user    25m2.606s
  sys     1m22.919s

New timing of make coccicheck

  real    1m36.580s
  user    7m55.933s
  sys     0m18.219s
Quoted 7 lines

This is nearly a 4x decrease in the time required to run make coccicheck. This is due to the overhead of restarting spatch for every file. By processing all files at once, we can amortize this startup cost across the total number of files, rather than paying it once per file.

---

Forgot to add what changed. I dropped the subshell and "||" bit around invoking spatch.

Thanks,
Jake

Quoted 15 lines
 Makefile | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Makefile +0 -4
index df1df9db78da..da692ece9e12 100644
@@ -2715,10 +2715,8 @@ endif
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
        ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
Quoted 8 lines
Quoted 8 lines
Makefile +2 -1
+       $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) >$@+ 2>[email protected]; \
+       ret=$$?; \
        if test $$ret != 0; \
        then \
                cat [email protected]; \
--

2.18.0.219.gaf81d287a9da

Wouldn't the following be even simpler?

Makefile +0 -0
index 5c8307b7c479..a37b2724d526 100644
@@ -2701,12 +2701,7 @@ endif
 

Makefile endif · line 2705

Quoted 10 lines
Makefile +1 -6
 %.cocci.patch: %.cocci $(COCCI_SOURCES)
        @echo '    ' SPATCH $<; \
-       ret=0; \
-       for f in $(COCCI_SOURCES); do \
-               $(SPATCH) --sp-file $< $$f $(SPATCH_FLAGS) || \
-                       { ret=$$?; break; }; \
-       done >$@+ 2>[email protected]; \
-       if test $$ret != 0; \
+       if ! $(SPATCH) --sp-file $< $(COCCI_SOURCES) $(SPATCH_FLAGS) 
 > $@+ 2>[email protected]; \

The "If !" and the output redirection should be on one line, obviously... Sorry about this.

Beat

#11 lore raw
In reply to René Scharfe
Quoted 15 lines · René Scharfe
Quoted 4 lines

That's OK, too, assuming people would actually want to use it. I'm also OK shipping this (with the "make -j" fix you suggested) and seeing if anybody actually complains. I assume there are only a handful of people running coccicheck in the first place.

FWIW, my development environment is a virtual machine with 1200MB RAM and 900MB swap space. coccicheck takes almost eight minutes sequentially, and four and a half minutes with -j4.

Unsurprisingly, it fails after almost three minutes with the patch, reporting that it ran out of memory. With 2900MB it fails after almost two minutes, with 3000MB it succeeds after a good two minutes.

time(1) says (for -j1):

Quoted 8 lines

433.30user 36.17system 7:49.84elapsed 99%CPU (0avgtext+0avgdata 108212maxresident)k 192inputs+1512outputs (0major+16409056minor)pagefaults 0swaps

129.74user 2.06system 2:13.27elapsed 98%CPU (0avgtext+0avgdata 1884568maxresident)k 236896inputs+1096outputs (795major+462129minor)pagefaults 0swaps

So with the patch it's more than three times faster, but needs more than seventeen times more memory. And I need a bigger VM. :-/

Yuck. :) So if we want to take this as a complaint, then I guess we can jump straight to implementing the fallback to the existing behavior (though it may be worth it for you to expand your VM to get the decreased CPU time).

I'm still puzzled by Gábor's counter-intuitive CI numbers, though.

-Peff

#15 lore raw
In reply to SZEDER Gábor
Quoted 11 lines · SZEDER Gábor

Runtimes tend to fluctuate quite a bit more on Travis CI compared to my machine, but not this much, and it seems to be consistent so far.

After scripting/querying the Travis CI API a bit, I found that from the last 100 static analysis build jobs 78 did actully run 'make coccicheck' [1], avaraging 470s for the whole build job, with only 4 build job exceeding the 10min mark.

I had maybe 6-8 build jobs running this patch over the last 2-3 days, I think all of them were over 15min. (I restarted some of them, so I don't have separate logs for all of them, hence the uncertainty.)

So that's really weird and counter-intuitive, since we should be doing strictly less work. I know that spatch tries to parallelize itself, though from my tests, 1.0.4 does not. I wonder if the version in Travis differs in that respect and starts too many threads, and the extra time is going to contention and context switches.

Have you tried passing "-j1" to spatch? My 1.0.4 does not even recognize it.

That seems like a pretty unlikely explanation to me, but I am having trouble coming up with another one.

I guess the other plausible thing is that the extra memory is forcing us into some slower path. E.g., a hypervisor may even be swapping, unbeknownst to the child OS, and it gets accounted in the child OS as "boy, that memory load was really slow", which becomes used CPU.

That actually sounds more credible to me.

-Peff

#16 lore raw
Quoted 14 lines · Jeff King
Quoted 11 lines · SZEDER Gábor

Runtimes tend to fluctuate quite a bit more on Travis CI compared to my machine, but not this much, and it seems to be consistent so far.

After scripting/querying the Travis CI API a bit, I found that from the last 100 static analysis build jobs 78 did actully run 'make coccicheck' [1], avaraging 470s for the whole build job, with only 4 build job exceeding the 10min mark.

I had maybe 6-8 build jobs running this patch over the last 2-3 days, I think all of them were over 15min. (I restarted some of them, so I don't have separate logs for all of them, hence the uncertainty.)

Quoted 5 lines

So that's really weird and counter-intuitive, since we should be doing strictly less work. I know that spatch tries to parallelize itself, though from my tests, 1.0.4 does not. I wonder if the version in Travis differs in that respect and starts too many threads, and the extra time is going to contention and context switches.

I don't think it does any parallel work.

Here is the timing again from my previous email:

960.50user 22.59system 16:23.74elapsed 99%CPU (0avgtext+0avgdata 1606156maxresident)k

Notice that 16:23 is 983s, and that it matches the sum of the user and system times. I usually saw this kind of timing with CPU-intensive single-threaded programs, and if there were any parallelization, then I would expect the elapsed time to be at least somewhat smaller than the other two.

Quoted 2 lines

Have you tried passing "-j1" to spatch? My 1.0.4 does not even recognize it.

I have just gave it a try, but the v1.0.0 on Travis CI errored out with "unknown option `-j'.

https://travis-ci.org/szeder/git/jobs/439532822#L566

Quoted 11 lines

That seems like a pretty unlikely explanation to me, but I am having trouble coming up with another one.

I guess the other plausible thing is that the extra memory is forcing us into some slower path. E.g., a hypervisor may even be swapping, unbeknownst to the child OS, and it gets accounted in the child OS as "boy, that memory load was really slow", which becomes used CPU.

That actually sounds more credible to me.

-Peff

#17 lore raw
Quoted 10 lines · SZEDER Gábor
Quoted 5 lines

So that's really weird and counter-intuitive, since we should be doing strictly less work. I know that spatch tries to parallelize itself, though from my tests, 1.0.4 does not. I wonder if the version in Travis differs in that respect and starts too many threads, and the extra time is going to contention and context switches.

I don't think it does any parallel work.

Here is the timing again from my previous email:

Quoted 7 lines

960.50user 22.59system 16:23.74elapsed 99%CPU (0avgtext+0avgdata 1606156maxresident)k

Notice that 16:23 is 983s, and that it matches the sum of the user and system times. I usually saw this kind of timing with CPU-intensive single-threaded programs, and if there were any parallelization, then I would expect the elapsed time to be at least somewhat smaller than the other two.

Ah, right, I should have been able to figure that out myself. So scratch that theory. My "hypervisor stalling our memory reads" theory is still plausible, but I don't know how we would test it.

I guess in some sense it doesn't matter. If it's slower, we're not likely to be able to fix that. So I guess we just need the fallback to the current behavior.

-Peff