Skip to content

dotnet-dump makes process to double its used memory and fails #71472

Open

Description

@afilatov-st

Description

In a Kubernetes environment, we have a process that normally consumes around 3.8 Gi.
When we run dotnet-dump collect, it causes the process to increase memory usage up to around 7.2 Gi.
Since we have a 6 Gi memory limit for the Pod, dotnet-dump cannot finish dump generation and fails with a System.IO.EndOfStreamException: Unable to read beyond the end of the stream exception.

If we set a higher memory limit, dotnet-dump collect succeeded, approximately doubling the used memory.
Is this expected behavior? Is it possible to make it just save the dump to the file without consuming more memory?

Reproduction Steps

Run dotnet-dump collect --process-id 1

Expected behavior

A dump file is created

Actual behavior

Dump file generation failed and the process may be crashed

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Jun 30, 2022
  2. changed the title [-]dotnet-dump makes process to double its used memory and fail[/-] [+]dotnet-dump makes process to double its used memory and fails[/+] on Jun 30, 2022
  3. tommcdon commented on Jun 30, 2022

    @tommcdon
    Member

    @afilatov-st Thanks for the bug report! I do not believe that memory doubling is expected in this scenario (though some memory usage is expected). Dotnet-Dump sends an IPC command using a domain socket on Linux to the target process to collect a dump. The target process will then launch createdump as a child process to collect a dump of the parent process. When the memory is doubled - is it the target process's memory that increases, createdump, or dotnet-dump itself that uses the extra memory?
    @mikem8361 @hoyosjs

  4. afilatov-st commented on Jun 30, 2022

    @afilatov-st
    Author

    @tommcdon thanks for the prompt response!
    the crash happens pretty quickly, so I had to run the following script in a parallel session

    while true                      
    do 
      ps aux;
      sleep 0.5;
    done
    

    it shows that the RSS of the target dotnet process is in its initial value of 3.6 Gb for around 5 seconds, then it quickly grows to 6.2 Gb before Kubernetes kills it.

  5. afilatov-st commented on Jun 30, 2022

    @afilatov-st
    Author

    For the context, the Docker image is based on mcr.microsoft.com/dotnet/aspnet:6.0.5-bullseye-slim-amd64

  6. added this to Runtime Infra and removed this from Runtime Infraon Jul 1, 2022
  7. self-assigned this
    on Jul 6, 2022
  8. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 7, 2022
  9. added this to the 7.0.0 milestone on Jul 7, 2022
  10. mikem8361 commented on Jul 12, 2022

    @mikem8361
    Contributor

    Can you try a heap dump by add --type Heap to the dotnet-dump collect command line?

    We think maybe when createdump is reading memory to write pages to the dump file that causes them to be "swapped" back in or read from the module files into the target process memory. A heap dump doesn't touch/read most of the module pages.

  11. added
    needs-author-actionAn issue or pull request that requires more info or actions from the author.
    on Jul 12, 2022
  12. afilatov-st commented on Jul 12, 2022

    @afilatov-st
    Author

    --type Heap behaves in the same way

  13. 59 remaining items

  14. added this to the 9.0.0 milestone on Jul 17, 2023
  15. ezgambac commented on Oct 31, 2023

    @ezgambac
    Contributor

    @tommcdon @hoyosjs Is there an eta for having heap analyzers fixed?
    This doubling memory issue makes dotnet dump unusable in the required scenarios, like debugging why is there high memory, as k8s will kill the pod.

  16. hoyosjs commented on Oct 31, 2023

    @hoyosjs
    Member

    @ezgambac Even in the case this got improved (the change wasn't backed out; it's just flagged off since it will make commands like verifyheap in SOS fail), it will still force memory swapping and some growth since the dumper itself runs in the cgroup of the container. For OOM, there's other options that could work since they are started in the init process's context if you have access to the host.

  17. ezgambac commented on Oct 31, 2023

    @ezgambac
    Contributor

    @hoyosjs What do you suggest doing then for the scenario where the pod is running at 80% memory then?
    We currently have dotnet monitor 6, which uses an older version of dotnet dump, but from what you are saying, even if we moved to latest, the dumper would generate enough extra memory that k8s will kill the process?
    From following this thread, it seemed like the change @ezsilmar had significantly reduced the memory consumption by dotnet dump while getting a dump. Would this dump be analyzable by perfview/visual studio?

  18. hoyosjs commented on Oct 31, 2023

    @hoyosjs
    Member

    It's analyzable, but you might get tooling telling you that the heap is inconsistent. You need to deploy the app with DOTNET_DbgDisablePagemapUse=0 and this is only there in .NET 8. Do you have access to the host (node)?

  19. modified the milestones: 9.0.0, 10.0.0 on Jul 23, 2024
  20. added
    enhancementProduct code improvement that does NOT require public API changes/additions
    on Apr 17, 2025
  21. modified the milestones: 10.0.0, 11.0.0 on Jul 30, 2025
  22. modified the milestones: 11.0.0, 12.0.0 on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Diagnostics-coreclrenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions