Skip to content

How to trace the fragmentation? #2850

Open

Description

@ChrisZcu

If there anyway to trace the fragmentation? In my application, only 8GB memory used (we record each malloc/free to count the total memory not released), but the process totally used 58GB memory (from RSS) and the "stats.mapped" shows totally 58GB. We think it may be caused by jemalloc cache, but how to trace the fragmentation source? Which memory using pattern causes this problem maybe?

Activity

  1. ylw510 commented on May 21, 2025

    @ylw510

    You can use malloc_stats_print to check Jemalloc memory statistics.

  2. ChrisZcu commented on May 21, 2025

    @ChrisZcu
    Author

    You can use malloc_stats_print to check Jemalloc memory statistics.

    We have tried but the report does not works because it only shows the bins or extents allocation information, without the fragmentation info. Or is there anything we missed in the report which releasted to the fragmentation address?

  3. ylw510 commented on May 21, 2025

    @ylw510

    You can use malloc_stats_print to check Jemalloc memory statistics.

    We have tried but the report does not works because it only shows the bins or extents allocation information, without the fragmentation info. Or is there anything we missed in the report which releasted to the fragmentation address?

    You can pay attention to the two fields:
    (1)stats.active
    (2)stats.allocated
    The difference between stats.active and stats.allocated is essentially the memory fragmentation.

    You can also pay attention to the util field of the bin.It represents the memory utilization rate of this bin.

  4. ChrisZcu commented on May 22, 2025

    @ChrisZcu
    Author

    You can use malloc_stats_print to check Jemalloc memory statistics.

    We have tried but the report does not works because it only shows the bins or extents allocation information, without the fragmentation info. Or is there anything we missed in the report which releasted to the fragmentation address?

    You can pay attention to the two fields: (1)stats.active (2)stats.allocated The difference between stats.active and stats.allocated is essentially the memory fragmentation.

    You can also pay attention to the util field of the bin.It represents the memory utilization rate of this bin.

    Thanks for reply.
    Below is the first util info in state report, is the rate means much low utilization of bin? Is this related to the process memory fragmentation? And can I say a small memory is held by process thus most larger memory is held by jemalloc due to this fragmentation, the total extent will not be released to os until process memory freed?

    Image

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions