From 4a714d91c637245fad1462f970c27c43b80b50a4 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Tue, 6 Aug 2024 16:58:02 +0200 Subject: pkg/corpus: prefer smaller programs during minimization Occasionally, deflake() and minimize() fail and we end up with huge programs in the syzkaller corpus. Huge programs in the corpus, in turn, lead to slower corpus triage and slower exec/sec overall, since many of the executed programs are based on the ones from the corpus. A slightly bigger corpus with on average shorter and more focused programs sounds like a more desirable outcome. Give preference to smaller programs during minimization. It should hopefully improve the situation over time. --- pkg/corpus/minimize.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'pkg') diff --git a/pkg/corpus/minimize.go b/pkg/corpus/minimize.go index b23f9f29e..8eac96122 100644 --- a/pkg/corpus/minimize.go +++ b/pkg/corpus/minimize.go @@ -25,10 +25,16 @@ func (corpus *Corpus) Minimize(cover bool) { // This gives some intentional non-determinism during minimization. // However, we want to give preference to non-squashed inputs, // so let's sort by this criteria. + // We also want to give preference to smaller corpus programs: + // - they are faster to execute, + // - minimization occasionally fails, so we need to clean it up over time. sort.SliceStable(inputs, func(i, j int) bool { - firstAny := inputs[i].Context.(*Item).HasAny - secondAny := inputs[j].Context.(*Item).HasAny - return !firstAny && secondAny + first := inputs[i].Context.(*Item) + second := inputs[j].Context.(*Item) + if first.HasAny != second.HasAny { + return !first.HasAny + } + return len(first.Prog.Calls) < len(second.Prog.Calls) }) corpus.progs = make(map[string]*Item) -- cgit mrf-deployment