Skip to content

Commit 4d197e4

Browse files
committed
feat: enable free page reporting
Balloon devices provide memory reclamation facilities through free page reporting, as a more efficient mechanism (in terms of latency and CPU time) than traditional ballooning. Free page reporting instructs the guest to periodically report memory that has been freed, so that we can reclaim it in the host side. It is enabled before starting the sandbox and does not require any further host-side orchestration. This commit enables free page reporting unconditionally in our sandboxes by setting up a balloon device configured to enable free page reporting. Traditional ballooning is **not** used here. Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
1 parent 6114076 commit 4d197e4

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

packages/orchestrator/internal/sandbox/fc/client.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,30 @@ func (c *apiClient) startVM(ctx context.Context) error {
296296
return nil
297297
}
298298

299+
func (c *apiClient) enableFreePageReporting(ctx context.Context) error {
300+
ctx, span := tracer.Start(ctx, "enable-free-page-reporting")
301+
defer span.End()
302+
303+
amountMib := int64(0)
304+
deflateOnOom := false
305+
306+
balloonConfig := operations.PutBalloonParams{
307+
Context: ctx,
308+
Body: &models.Balloon{
309+
AmountMib: &amountMib,
310+
DeflateOnOom: &deflateOnOom,
311+
FreePageReporting: true,
312+
},
313+
}
314+
315+
_, err := c.client.Operations.PutBalloon(&balloonConfig)
316+
if err != nil {
317+
return fmt.Errorf("error setting up balloon device: %w", err)
318+
}
319+
320+
return nil
321+
}
322+
299323
func (c *apiClient) memoryMapping(ctx context.Context) (*memory.Mapping, error) {
300324
params := operations.GetMemoryMappingsParams{
301325
Context: ctx,

packages/orchestrator/internal/sandbox/fc/process.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ func (p *Process) Create(
343343
}
344344
telemetry.ReportEvent(ctx, "set fc entropy config")
345345

346+
err = p.client.enableFreePageReporting(ctx)
347+
if err != nil {
348+
fcStopErr := p.Stop(ctx)
349+
350+
return errors.Join(fmt.Errorf("error enabling free page reporting: %w", err), fcStopErr)
351+
}
352+
telemetry.ReportEvent(ctx, "enabled free page reporting")
353+
346354
err = p.client.startVM(ctx)
347355
if err != nil {
348356
fcStopErr := p.Stop(ctx)

0 commit comments

Comments
 (0)