Skip to content

Conversation

@anakrish
Copy link
Collaborator

@anakrish anakrish commented Jan 15, 2026

Policy evaluation at scale needs to be able to set memory limits
so that a bad policy does not hog memory or to ensure that
policy evaluation itself does not use too much memory which could
cause other components to suffer.

This PR introduces capability to set and enforce global memory limits.
It also lays the groundwork for enabling per evaluation limits in future.

Once a global memory limit is set, Regorus maintains per thread counters
to track memory activity (allocation, deallocation) of a thread.
These counters are periodically flushed to global memory counters.
Per thread counters avoid the contention that updating global counters
on each alloc/free would cause.

Policy evaluation periodically checks these counters and raises errors
if allocated memory has exceeded the configured limit.

Currently memory limit capability is exposed only to FFI and C#.

Also update mimalloc to v2.2.6

@anakrish anakrish force-pushed the memory-limits branch 2 times, most recently from 0922e04 to 02b37bf Compare January 20, 2026 01:42
@anakrish anakrish changed the title chore: Update mimalloc to v2.2.6 feat(memory): Allocator-backed global memory limits Jan 20, 2026
@anakrish anakrish force-pushed the memory-limits branch 4 times, most recently from 2a37a03 to 7e6aba4 Compare January 20, 2026 15:10
@anakrish anakrish force-pushed the memory-limits branch 14 times, most recently from 20b68eb to 1023131 Compare January 21, 2026 14:53
@anakrish anakrish marked this pull request as ready for review January 21, 2026 14:59
Policy evaluation at scale needs to be able to set memory limits
so that a bad policy does not hog memory or to ensure that
policy evaluation itself does not use too much memory which could
cause other components to suffer.

This PR introduces capability to set and enforce global memory limits.
It also lays the groundwork for enabling per evaluation limits in future.

Once a global memory limit is set, Regorus maintains per thread counters
to track memory activity (allocation, deallocation) of a thread.
These counters are periodically flushed to global memory counters.
Per thread counters avoid the contention that updating global counters
on each alloc/free would cause.

Policy evaluation periodically checks these counters and raises errors
if allocated memory has exceeded the configured limit.

Currently memory limit capability is exposed only to FFI and C#.

Also update mimalloc to v2.2.6

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
Copy link

@dpokluda dpokluda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@anakrish anakrish merged commit fd59bb5 into microsoft:main Jan 24, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants