Skip to content

Large Object Heap Fragmentation #301

@indy-singh

Description

@indy-singh

Hi,

Recently we have noticed a lot of LOH allocations since migrating our platform serializer to protobuf and after spending a bit of time on it we have managed to narrow down the problem to the BufferPool.cs.

We used dotMemory and dotTrace to help us identifier the source of the issue; dotTrace points to the method ResizeAndFlushLeft:-

https://github.com/mgravell/protobuf-net/blob/a978575b9e8bc281f7341237cace35220ef0ff35/src/protobuf-net/BufferPool.cs#L49

It looks like we have certain responses that require a buffer larger than 65,536 bytes and when it goes into ResizeAndFlushLeft it gets doubled to 131,072 which is automatically allocated on the LOH as it is greater than 85,000 bytes.

We don't think the size of the buffer is a problem per-se it is the fact that they aren't being re-used. This causes repeated allocations on the LOH and causes a high frequency of fragmentation.

We managed to replicate the problem in a test harness.

protobuf-net_loh_allocations

We would appreciate any guidance on this issue.

Cheers,
Indy

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