Skip to content

Feature request: clamp heap doubling to the maximum allowed (leaking GC, wasip1) #5598

Description

@joeshaw

I recently ran into a side effect of reducing the memory usage in a wasip1 app using the leaking GC: the effective usable RAM went down.

My environment has a hard 128 MB RAM limit. With a 3 MB initial allocation, the growth goes 3 -> 6 -> 12 -> 24 -> 48 -> 96 -> (attempted) 192. The program will crash if it attempts to allocate more than 96 MB.

Through optimizations I recently reduced the initial allocation in my app to 2.5 MB and I started seeing more out-of-memory errors than I did previously. That's because the growth is now 2.5 -> 5 -> 10 -> 20 -> 40 -> 80 -> (attempted) 160. The ceiling of my program has effectively gone from 96 MB to 80 MB, and that is enough to see an increase in out-of-memory errors.

My workaround has been to set --initial-memory=4194304 when compiling. This ensures we're always growing by a power of 2 and can allocate the full 128 MB.

What I'd like to do instead is set --max-memory=134217728 and have the heap growth behavior clamp to that, so growth would be ...40 -> 80 -> 128. Only once we're already at 128 would we try to allocate more and crash. That'd let me always use the full amount, while still keeping low usage (2.5 MB -> 4 MB) when possible.

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