Skip to content

Commit 3c81673

Browse files
RoyceDavisonplamenmpetrov
authored andcommitted
Memory ballooning support on firecracker-containerd
Implement the memory ballooning APIs on firecracker-containerd Signed-off-by: Royce Zhao <[email protected]>
1 parent 1c349c5 commit 3c81673

File tree

11 files changed

+1074
-133
lines changed

11 files changed

+1074
-133
lines changed

firecracker-control/local.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,78 @@ func (s *local) GetVMMetadata(requestCtx context.Context, req *proto.GetVMMetada
377377
return resp, nil
378378
}
379379

380+
// GetBalloonConfig get balloon configuration, before or after machine startup.
381+
func (s *local) GetBalloonConfig(requestCtx context.Context, req *proto.GetBalloonConfigRequest) (*proto.GetBalloonConfigResponse, error) {
382+
client, err := s.shimFirecrackerClient(requestCtx, req.VMID)
383+
if err != nil {
384+
return nil, err
385+
}
386+
387+
defer client.Close()
388+
resp, err := client.GetBalloonConfig(requestCtx, req)
389+
if err != nil {
390+
err = errors.Wrap(err, "shim client failed to get balloon config")
391+
s.logger.WithError(err).Error()
392+
return nil, err
393+
}
394+
395+
return resp, nil
396+
}
397+
398+
// UpdateBalloon updates memory size for an existing balloon device, before or after machine startup.
399+
func (s *local) UpdateBalloon(requestCtx context.Context, req *proto.UpdateBalloonRequest) (*empty.Empty, error) {
400+
client, err := s.shimFirecrackerClient(requestCtx, req.VMID)
401+
if err != nil {
402+
return nil, err
403+
}
404+
405+
defer client.Close()
406+
resp, err := client.UpdateBalloon(requestCtx, req)
407+
if err != nil {
408+
err = errors.Wrap(err, "shim client failed to update balloon")
409+
s.logger.WithError(err).Error()
410+
return nil, err
411+
}
412+
413+
return resp, nil
414+
}
415+
416+
// GetBalloonStats will return the latest balloon device statistics, only if enabled pre-boot.
417+
func (s *local) GetBalloonStats(requestCtx context.Context, req *proto.GetBalloonStatsRequest) (*proto.GetBalloonStatsResponse, error) {
418+
client, err := s.shimFirecrackerClient(requestCtx, req.VMID)
419+
if err != nil {
420+
return nil, err
421+
}
422+
423+
defer client.Close()
424+
resp, err := client.GetBalloonStats(requestCtx, req)
425+
if err != nil {
426+
err = errors.Wrap(err, "shim client failed to get balloon statistics")
427+
s.logger.WithError(err).Error()
428+
return nil, err
429+
}
430+
431+
return resp, nil
432+
}
433+
434+
// UpdateBalloonStats updates an existing balloon device statistics interval, before or after machine startup.
435+
func (s *local) UpdateBalloonStats(requestCtx context.Context, req *proto.UpdateBalloonStatsRequest) (*empty.Empty, error) {
436+
client, err := s.shimFirecrackerClient(requestCtx, req.VMID)
437+
if err != nil {
438+
return nil, err
439+
}
440+
441+
defer client.Close()
442+
resp, err := client.UpdateBalloonStats(requestCtx, req)
443+
if err != nil {
444+
err = errors.Wrap(err, "shim client failed to update balloon interval")
445+
s.logger.WithError(err).Error()
446+
return nil, err
447+
}
448+
449+
return resp, nil
450+
}
451+
380452
func (s *local) newShim(ns, vmID, containerdAddress string, shimSocket *net.UnixListener, fcSocket *net.UnixListener) (*exec.Cmd, error) {
381453
logger := s.logger.WithField("vmID", vmID)
382454

firecracker-control/service.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,23 @@ func (s *service) GetVMMetadata(ctx context.Context, req *proto.GetVMMetadataReq
106106
log.G(ctx).Debug("Getting vm metadata")
107107
return s.local.GetVMMetadata(ctx, req)
108108
}
109+
110+
func (s *service) GetBalloonConfig(ctx context.Context, req *proto.GetBalloonConfigRequest) (*proto.GetBalloonConfigResponse, error) {
111+
log.G(ctx).Debug("Getting balloon configuration")
112+
return s.local.GetBalloonConfig(ctx, req)
113+
}
114+
115+
func (s *service) UpdateBalloon(ctx context.Context, req *proto.UpdateBalloonRequest) (*empty.Empty, error) {
116+
log.G(ctx).Debug("Updating balloon memory size")
117+
return s.local.UpdateBalloon(ctx, req)
118+
}
119+
120+
func (s *service) GetBalloonStats(ctx context.Context, req *proto.GetBalloonStatsRequest) (*proto.GetBalloonStatsResponse, error) {
121+
log.G(ctx).Debug("Getting balloon statistics")
122+
return s.local.GetBalloonStats(ctx, req)
123+
}
124+
125+
func (s *service) UpdateBalloonStats(ctx context.Context, req *proto.UpdateBalloonStatsRequest) (*empty.Empty, error) {
126+
log.G(ctx).Debug("Updating balloon device statistics polling interval")
127+
return s.local.UpdateBalloonStats(ctx, req)
128+
}

0 commit comments

Comments
 (0)