Skip to content

Commit fd59bb5

Browse files
authored
feat(memory): Allocator-backed global memory limits (microsoft#544)
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>
1 parent 80686d6 commit fd59bb5

93 files changed

Lines changed: 9722 additions & 3729 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test-csharp.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- cron: "0 8 * * *"
1212

1313
env:
14-
VersionSuffix: ${{ github.event_name == 'workflow_dispatch' && 'manualtrigger' || null }}
14+
VersionSuffix: ${{ github.run_id }}
1515

1616
jobs:
1717
build-ffi:
@@ -95,11 +95,11 @@ jobs:
9595

9696
# Note that we need to supply the target folder within the folder where artifacts are downloaded.
9797
- name: Build Regorus binding
98-
run: dotnet build /p:Configuration=Release /p:RegorusFFIArtifactsDir=./tmp/bindings/ffi/target
98+
run: dotnet build /p:Configuration=Release /p:RegorusFFIArtifactsDir=./tmp/bindings/ffi/target /p:VersionSuffix=${{ env.VersionSuffix }}
9999
working-directory: ./bindings/csharp/Regorus
100100

101101
- name: Pack
102-
run: dotnet pack /p:RegorusFFIArtifactsDir=./tmp/bindings/ffi/target
102+
run: dotnet pack /p:RegorusFFIArtifactsDir=./tmp/bindings/ffi/target /p:VersionSuffix=${{ env.VersionSuffix }}
103103
working-directory: ./bindings/csharp/Regorus
104104

105105
- name: Upload Regorus nuget
@@ -144,15 +144,15 @@ jobs:
144144
path: ./bindings/csharp/regorus-nuget/
145145

146146
- name: Restore Regorus.Tests
147-
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget /p:UseLocalRegorus=false
147+
run: dotnet restore /p:UseLocalRegorus=false /p:VersionSuffix=${{ env.VersionSuffix }} /p:RestoreAdditionalProjectSources=../regorus-nuget
148148
working-directory: ./bindings/csharp/Regorus.Tests
149149

150150
- name: Run Regorus.Tests
151-
run: dotnet test --no-restore -p:UseLocalRegorus=false
151+
run: dotnet test --no-restore /p:UseLocalRegorus=false /p:VersionSuffix=${{ env.VersionSuffix }}
152152
working-directory: ./bindings/csharp/Regorus.Tests
153153

154154
- name: Restore TestApp
155-
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget
155+
run: dotnet restore /p:VersionSuffix=${{ env.VersionSuffix }} /p:RestoreAdditionalProjectSources=../regorus-nuget
156156
working-directory: ./bindings/csharp/TestApp
157157

158158
- name: Build TestApp
@@ -164,7 +164,7 @@ jobs:
164164
working-directory: ./bindings/csharp/TestApp
165165

166166
- name: Restore TargetExampleApp
167-
run: dotnet restore /p:RestoreAdditionalProjectSources=../regorus-nuget
167+
run: dotnet restore /p:VersionSuffix=${{ env.VersionSuffix }} /p:RestoreAdditionalProjectSources=../regorus-nuget
168168
working-directory: ./bindings/csharp/TargetExampleApp
169169

170170
- name: Build TargetExampleApp
@@ -174,5 +174,3 @@ jobs:
174174
- name: Run TargetExampleApp
175175
run: dotnet run --no-build --framework net8.0
176176
working-directory: ./bindings/csharp/TargetExampleApp
177-
178-

0 commit comments

Comments
 (0)