Skip to content

Jemalloc malloc_stats_print doesn't match RSS/VSZ #2785

Closed

Description

@priesto

Hello,

We're using an app named Varnish, which is an HTTP cache, this app comes with jemalloc (5.3.0).

We recently got multiple OOM kill due to Varnish using too much memory, so we started digging a bit about this issue, and we've found that the stats returned by malloc_stats_print doesn't match the RSS/VSZ reported by the kernel (Linux) :

$ ps aux | grep varnish
vcache   1356086  0.5  4.7 464724 187536 ?       SLl  Jan20   9:34 /usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T 127.0.0.1:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,1024m
Allocated: 68531016, active: 72781824, metadata: 7129520 (n_thp 0), resident: 82313216, mapped: 93626368, retained: 143351808

So you can see that the kernel reports ~183MB of resident memory, while Jemalloc says there is ~69MB of active memory.

External fragmentation is quite low : 68531016 / 72781824 = 0,941595198, so that shouldn't cause this issue.

Is this a normal behaviour? Is there any overhead that I could have missed?

Bear in mind that I am in no way a developer, but a sysadmin, so sorry if I missed something obvious.

Here is the full malloc_stats_print report : malloc_stats_print.txt

Here is also a pmap of the running process in case that could be helpful : pmap.txt

Thanks.

Activity

  1. interwq commented on Jan 22, 2025

    @interwq
    Contributor

    The jemalloc stats will only account for heap memory allocated through jemalloc (in this case <100MB like you mentioned), while there are still other mappings not through malloc in the process, e.g. directly mmaped regions and thread stacks.

    Closing but feel free to ask questions.

  2. priesto commented on Jan 24, 2025

    @priesto
    Author

    You're right, totally forgot about the other memory regions... 🤦

    Thank you for the reply.

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