Skip to content

feature: extreme low memory mode BB #1456

@ludamad

Description

@ludamad

Title
Add mmap-backed Polynomial allocation gated on BB_SLOW_LOW_MEMORY


Motivation

On memory-constrained mobile targets (e.g. zkPassport on iOS/Android) the RAM footprint of large proving keys and working polynomials is the main source of crashes. We already proved in a local PoC that mapping polynomials to disk with mmap slashes resident memory while keeping the API intact.

What & How

  • Compile-time gate:

    #ifdef BB_SLOW_LOW_MEMORY
    // new mmap-backed storage
    #else
    // current heap allocation path
    #endif
  • Behavior:

    • When BB_SLOW_LOW_MEMORY is defined every Polynomial instance is backed by its own anonymous temporary file created with O_TMPFILE (or mkstemp + unlink fallback).
    • Outside that build flag nothing changes ― the class stays purely in-memory.
  • Details / Notes

    1. mmap(size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)
    2. RAII cleanup: munmap in the destructor; file closes automatically because it’s unlinked right after creation.
    3. Keep constructor, iterators, and operator[] unchanged so existing call-sites compile untouched.

Acceptance criteria

  • Allowing for significant slowdown, ability to run in a memory-constrained docker environment (e.g. say 1GB for a proving job that normally takes 2GB). This is a proxy for showing that mobile devices will evict pages as needed to keep our app within memory.

Potential followups

  • Use madvise? (dubious if needed, complicated)

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions