Skip to content

runtime: expose total stack usage in MemStats #7468

Closed

Description

@randall77
Non-standard-sized stack allocations should be accounted under StackSys.  Right now they
are treated as regular malloc'd memory.

Activity

  1. dvyukov commented on Mar 6, 2014

    @dvyukov
    Member

    Comment 1:

    > Right now they are treated as regular malloc'd memory.
    They are not profiled by mprof.
    > Non-standard-sized stack allocations should be accounted under StackSys.
    If we just account it in StackSys, then part of stacks (std size) will be accounted only
    in StackSys, and some part will be accounted both in StackSys and HeapSys. Since you
    don't know what is the proportion between these parts, you can't make sense out of
    HeapSys and heap profile -- heap profile shows less than HeapSys, but you don't know
    what part of that difference is stacks.
    mprof profile and memstats must be consistent and allow to verify sanity (tell whether
    mprof lies or not).

    Labels changed: added release-go1.3, repo-main.

  2. randall77 commented on Mar 8, 2014

    @randall77
    ContributorAuthor

    Comment 2:

    Dmitry, did your change https://golang.org/cl/72440043 fix this?
  3. dvyukov commented on Mar 11, 2014

    @dvyukov
    Member

    Comment 3:

    No, it did not. That change only fixes g->stacksize, which is an internal counter used
    to detect infinite recursion.
  4. dvyukov commented on Mar 11, 2014

    @dvyukov
    Member

    Comment 4:

    StackInuse is also broken (StackInuse decreases during function execution):
    go version devel +3cd546ac3a99 Tue Mar 11 16:36:14 2014 +1100 linux/amd64
    $ go test -v -cpu 1,1,1,1 runtime -test.run=TestStack
    === RUN TestStackOverflow
    --- PASS: TestStackOverflow (0.68 seconds)
    === RUN TestStackSplit
    --- PASS: TestStackSplit (0.01 seconds)
    === RUN TestStackMem
    --- PASS: TestStackMem (3.09 seconds)
        stack_test.go:1576: Consumed 2MB for stack mem
        stack_test.go:1582: Inuse 0MB for stack mem
    === RUN TestStackOverflow
    --- PASS: TestStackOverflow (0.67 seconds)
    === RUN TestStackSplit
    --- PASS: TestStackSplit (0.01 seconds)
    === RUN TestStackMem
    --- FAIL: TestStackMem (3.10 seconds)
        stack_test.go:1576: Consumed 0MB for stack mem
        stack_test.go:1582: Inuse 17592186044415MB for stack mem
        stack_test.go:1584: Stack inuse: want 4194304, got 18446744073709547520
  5. rsc commented on Mar 11, 2014

    @rsc
    Contributor

    Comment 5:

    StackSys is listed as one of a collection under "Low-level fixed-size structure
    allocator statistics." More generally the Sys numbers are supposed to correspond 1:1
    with mmap requests made to the system. I don't think we should redefine what
    StackSys/StackInuse mean to be different than the other Sys/Inuse pairs. In particular
    the sum of all the XxxSys fields needs to match the Sys field.
    Maybe instead we can add a new field that counts total stack usage? Maybe just
    StackAlloc.
    It's fine for Go 1.3 if this is a noninvasive change.

    Labels changed: added release-go1.3maybe, removed release-go1.3.

    Status changed to Accepted.

  6. dvyukov commented on Mar 11, 2014

    @dvyukov
    Member

    Comment 6:

    > Maybe instead we can add a new field that counts total stack usage? Maybe just
    StackAlloc.
    We also must be able to understand what is heap size w/o stacks.
    There is already StackInuse which currently counts only fixed-size cache allocations.
    Maybe we can make StackInuse represent total stack memory (cache + mallocgc), and then
    subtract malloced stacks from HeapAlloc?
    But this introduces another problem: HeapAlloc and HeapSys won't match...
  7. rsc commented on Mar 11, 2014

    @rsc
    Contributor

    Comment 7:

    It's too confusing to redefine existing counters. Maybe add StackAlloc (all
    stack in use) and StackHeap (all stack in use from heap). Then you can use
    HeapAlloc - StackHeap to get "heap size without stacks".
  8. dvyukov commented on Mar 11, 2014

    @dvyukov
    Member

    Comment 8:

    For now #7 sounds like the best option... and we will need to introduce mstats paid
    certification for developers :)
  9. dvyukov commented on Mar 12, 2014

    @dvyukov
    Member

    Comment 9:

    This issue was updated by revision 00e6fc1.

    LGTM=rsc
    R=golang-codereviews, bradfitz
    CC=golang-codereviews, khr, rsc
    https://golang.org/cl/74010043
  10. rsc commented on May 9, 2014

    @rsc
    Contributor

    Comment 10:

    Labels changed: added release-go1.4, removed release-go1.3maybe.

  11. gopherbot commented on Jun 24, 2014

    @gopherbot
    Contributor

    Comment 11:

    CL https://golang.org/cl/104200047 mentions this issue.
  12. randall77 commented on Jul 1, 2014

    @randall77
    ContributorAuthor

    Comment 12:

    This issue was closed by revision 7c13860.

    Status changed to Fixed.

  13. randall77 commented on Jul 1, 2014

    @randall77
    ContributorAuthor

    Comment 13:

    This issue was closed by revision 3cf83c1.

  14. gopherbot commented on Jul 17, 2014

    @gopherbot
    Contributor

    Comment 14:

    CL https://golang.org/cl/112240044 mentions this issue.
  15. randall77 commented on Jul 17, 2014

    @randall77
    ContributorAuthor

    Comment 15:

    This issue was closed by revision f378f30.

  16. added this to the Go1.4 milestone on Apr 14, 2015
  17. locked and limited conversation to collaborators on Jun 25, 2016
  18. added 3 commits that reference this issue on Jun 25, 2018
    2b6d63e
    e7d126b
    6244e9f
  19. added 3 commits that reference this issue on Jul 9, 2018
    8ba83e3
    63d493d
    ca6ee87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions