diff --git a/ctriface/iface.go b/ctriface/iface.go index d6e79a114..498261a7e 100644 --- a/ctriface/iface.go +++ b/ctriface/iface.go @@ -64,6 +64,8 @@ type StartVMResponse struct { const ( testImageName = "ghcr.io/ease-lab/helloworld:var_workload" + fileBackend = "File" + uffdBackend = "Uffd" ) // StartVM Boots a VM if it does not exist @@ -104,7 +106,7 @@ func (o *Orchestrator) StartVMWithEnvironment(ctx context.Context, vmID, imageNa tStart = time.Now() conf := o.getVMConfig(vm) - _, err = o.fcClient.CreateVM(ctx, conf) + resp, err := o.fcClient.CreateVM(ctx, conf) startVMMetric.MetricMap[metrics.FcCreateVM] = metrics.ToUS(time.Since(tStart)) if err != nil { return nil, nil, errors.Wrap(err, "failed to create the microVM in firecracker-containerd") @@ -214,7 +216,7 @@ func (o *Orchestrator) StartVMWithEnvironment(ctx context.Context, vmID, imageNa VMMStatePath: o.getSnapshotFile(vmID), WorkingSetPath: o.getWorkingSetFile(vmID), // FIXME (gh-807) - //InstanceSockAddr: resp.UPFSockPath, + InstanceSockAddr: resp.GetSocketPath(), } if err := o.memoryManager.RegisterVM(stateCfg); err != nil { return nil, nil, errors.Wrap(err, "failed to register VM with memory manager") @@ -497,7 +499,19 @@ func (o *Orchestrator) LoadSnapshot(ctx context.Context, vmID string, snap *snap conf.MemFilePath = snap.GetMemFilePath() conf.ContainerSnapshotPath = containerSnap.GetDevicePath() + if conf.MemBackend == nil { + conf.MemBackend = &proto.MemoryBackend{} + } + conf.MemBackend.BackendType = fileBackend + conf.MemBackend.BackendPath = snap.GetMemFilePath() + if o.GetUPFEnabled() { + conf.MemBackend.BackendType = uffdBackend + conf.MemBackend.BackendPath, err = o.memoryManager.GetUPFSockPath(vmID) + if err != nil { + return nil, nil, errors.Wrapf(err, "failed to get UPF socket path for uffd backend") + } + if err := o.memoryManager.FetchState(vmID); err != nil { return nil, nil, err } diff --git a/memory/manager/manager.go b/memory/manager/manager.go index c1f9464aa..1c9a755fe 100644 --- a/memory/manager/manager.go +++ b/memory/manager/manager.go @@ -351,6 +351,35 @@ func (m *MemoryManager) GetUPFLatencyStats(vmID string) ([]*metrics.Metric, erro return state.latencyMetrics, nil } +func (m *MemoryManager) GetUPFSockPath(vmID string) (string, error) { + logger := log.WithFields(log.Fields{"vmID": vmID}) + + logger.Debug("Get the path of firecracker unix domain socket") + + m.Lock() + + state, ok := m.instances[vmID] + if !ok { + m.Unlock() + logger.Error("VM not registered with the memory manager") + return "", errors.New("VM not registered with the memory manager") + } + + m.Unlock() + + if state.isActive { + logger.Error("Cannot get stats while VM is active") + return "", errors.New("Cannot get stats while VM is active") + } + + if !m.MetricsModeOn || !state.metricsModeOn { + logger.Error("Metrics mode is not on") + return "", errors.New("Metrics mode is not on") + } + + return m.instances[vmID].SnapshotStateCfg.InstanceSockAddr, nil +} + func getLazyHeaderStats(state *SnapshotState, functionName string) ([]string, []string) { header := []string{ "FuncName",