You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
testing: why AllocsPerRun tests fails when GOMAXPROCS>1 #5000
revision cb98d0bcf923 skips allocation tests if GOMAXPROCS > 1, however,
AllocsPerRun already set GOMAXPROCS to 1 before starting tests, so the
extra allocations shouldn't be from other goroutines (or the scheduler is
not obeying GOMAXPROCS).
Dig deeper. What does the extra allocations come from?
I expect it's a bug somewhere in the runtime because the allocation test failures
don't come up until recently so this perhaps is a regression.
See also comments in the original issue report: issue #4974.
I have only 1 idea:
I've removed flush of per-P mcache's after GC (because there are fewer caches and they
are constantly in use). Perhaps it's somehow increases/decreases number of mallocs in
the beginning/end of the test.
This issue is simple to solve if we omit efficiency considerations. The fix would be to
pass "true" as argument to settype_flush() in mgc0.c. However, I don't recommend this
fix because it wastes memory and increases the number of system calls.
The efficient solution appears to be a new memory allocator for internal use by Go's
runtime with support for explicit deallocation only (like malloc+free in C, although
simpler code). The allocated memory would be completely separate from garbage-collected
memory. Work on this allocator cannot start before Go1.1 is released.
>This issue is simple to solve if we omit efficiency considerations. The fix would be to
pass "true" as argument to settype_flush() in mgc0.c.
Yeah it does not look like a good solution.
I have a very dirty "solution":
https://golang.org/cl/7625044/diff/5001/src/pkg/testing/allocs.go
It fixes ./fmt.test -test.v -test.run=Mallocs
-test.cpu=1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
on my machine.
I can think of other hacky solutions:
1. Provide testing.runtime_allocTestStart/End() which will somehow offset the stats (use
system memory in settype_flush(), explicitly offset stats, etc).
2. Just explicitly offset mem stats in settype_flush, i.e. pretend that it does not
allocate.
What if we add a field to MemStats that counts the number of allocations for internal
runtime reasons. Then we let testing.AllocsPerRun ignore that, perhaps with a
parameter. AllocsPerRun was not in Go 1 so we can still change it.
It's ugly but it could work reasonably well if we are careful about what consider an
internal runtime reason--e.g., we would have to be sure that it doesn't correlate with
something the program is doing.
I have some ideas on how to eliminate settype_flush() entirely (as part of making
malloc/GC faster), so perhaps it easier/simple to "undo" memstats in settype_flush()
after mallocgc() pretending that it does not allocate. (but we must be careful to redo
them again when the memory is freed, to not cause persistent slant)
1. By eliminating settype_flush() entirely do you mean to set the typeinfo in function
mallocgc()?
2. I do not see how to implement the redo operation when the memory is freed.
> 1. By eliminating settype_flush() entirely do you mean to set the typeinfo
> in function mallocgc()?
Yes, but I don't have the exact plan.
> 2. I do not see how to implement the redo operation when the memory is
> freed.
Won't settype_sysfree() do?
I mean we must know when the span is freed/reused.
My input, copied from the mailing list:
AllocsPerRun is inherently flaky. There could be background stuff
going on we'll never control. Perhaps we should instead write our
tests not to be so sensitive (and build-breaking). I suggest all
AllocsPerRun tests should be skipped if -test.short is true, so they
are evaluated by the test owners but not in every build configuration
in the world.
The problem comes in with automated builds that regularly run all the tests. Flakiness
causes noise that constantly needs to be triaged. Should automated builds not run the
long tests? Is there some third class of tests? -test.flaky=true?
In my simplistic world view, tests should either pass with any and all values of
GOMAXPROCS, GOGC, GOGCTRACE, test.cpu, etc., or control for these variables, or get
fixed or get deleted.
Should reduce the flakiness a little. Malloc counting is important
to general testing but not to the build dashboard, which uses -short.
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12866047
Activity
dvyukov commentedon Mar 7, 2013
Comment 1:
dvyukov commentedon Mar 8, 2013
Comment 2:
It is flaky with old scheduler as well, here is what I've just observed on revision 15951 from Wed Feb 27 11:59:36 2013 -0800: $ ./fmt.test -test.v -test.run=Mallocs -test.cpu=1,2,3,4,5,6,7,8,9,10 === RUN TestCountMallocs --- PASS: TestCountMallocs (0.00 seconds) === RUN TestCountMallocs-2 --- PASS: TestCountMallocs-2 (0.00 seconds) === RUN TestCountMallocs-3 --- PASS: TestCountMallocs-3 (0.00 seconds) === RUN TestCountMallocs-4 --- PASS: TestCountMallocs-4 (0.00 seconds) === RUN TestCountMallocs-5 --- PASS: TestCountMallocs-5 (0.00 seconds) === RUN TestCountMallocs-6 --- PASS: TestCountMallocs-6 (0.00 seconds) === RUN TestCountMallocs-7 --- FAIL: TestCountMallocs-7 (0.00 seconds) fmt_test.go:607: Fprintf(buf, "%s"): got 1.19 allocs, want <=1 === RUN TestCountMallocs-8 --- PASS: TestCountMallocs-8 (0.00 seconds) === RUN TestCountMallocs-9 --- PASS: TestCountMallocs-9 (0.00 seconds) === RUN TestCountMallocs-10 --- PASS: TestCountMallocs-10 (0.00 seconds) FAILdvyukov commentedon Mar 8, 2013
Comment 3:
dvyukov commentedon Mar 8, 2013
Comment 4:
gopherbot commentedon Mar 8, 2013
Comment 6:
dvyukov commentedon Mar 8, 2013
Comment 7:
ianlancetaylor commentedon Mar 8, 2013
Comment 8:
dvyukov commentedon Mar 8, 2013
Comment 9:
gopherbot commentedon Mar 8, 2013
Comment 10:
dvyukov commentedon Mar 8, 2013
Comment 11:
gopherbot commentedon Mar 8, 2013
Comment 12:
rsc commentedon Mar 12, 2013
Comment 13:
Labels changed: added go1.1maybe, removed go1.1.
alberts commentedon Mar 13, 2013
Comment 14:
robpike commentedon May 18, 2013
Comment 15:
Labels changed: added go1.2maybe, removed go1.1maybe.
dvyukov commentedon May 28, 2013
Comment 16:
robpike commentedon May 28, 2013
Comment 17:
alberts commentedon May 28, 2013
Comment 18:
robpike commentedon Aug 21, 2013
Comment 19:
This issue was updated by revision f578726.
rsc commentedon Sep 9, 2013
Comment 20:
Labels changed: removed go1.2maybe.
Status changed to Fixed.