firecracker-microvm / firecracker

Secure and fast microVMs for serverless computing.
http://firecracker-microvm.io
Apache License 2.0
25.5k stars 1.78k forks source link

[Feature Request] Snapshot loading after VM has been configured #3285

Closed jkrshnmenon closed 1 year ago

jkrshnmenon commented 1 year ago

Feature Request

Currently, firecracker does not support loading snapshots after a micro-VM has been configured. Therefore, in order to load snapshots, a user has to create a new VM every time. This can be prevented by modifying firecracker to allow loading a snapshot after the micro-VM has been configured

Describe the desired solution

The load snapshot functionality in firecracker should be able to load a micro-VM from a snapshot at any point during the micro-VM lifecycle except the Running state. Therefore, it should be possible for a user to load a micro-VM from a snapshot if the micro-VM has been configured or is in the Paused state.

Describe possible alternatives

I am not aware of any alternatives for this feature request.

Currently, users have to create a new micro-VM in order to load a snapshot.

Additional context

I am currently working on a project where I would like to reset the state of a virtual machine very quickly to a fixed state. I had planned on using firecracker for this purpose due to its lightweight nature. I have tried implementing this functionality in my fork of firecracker. The relevant commit can be found here

Checks

luminitavoicu commented 1 year ago

Hi! Thanks for your suggestion.

Snapshots are only loaded on fresh microVMs because the snapshot file could present a device configuration different that the one already configured in the running microVM. This would cause problems with the current Firecracker design, as Firecracker doesn't yet support dynamically attaching/detaching devices at runtime.

Could you provide more information on your usecase?

jkrshnmenon commented 1 year ago

Hi, thanks for letting me know.

My usecase involves running a single application inside the microVM with a fixed configuration for testing this application. Therefore I do not foresee any changes being made to the configurations. Also, speed is a important factor in my usecase. Therefore, creating a fresh microVM and loading the snapshot into this microVM might add quite a bit of unnecessary overhead.

Perhaps this feature can be implemented along with a check that compares the configuration of the current microVM with that being restored from the snapshot ?

Please let me know what you think of this.

luminitavoicu commented 1 year ago

Snapshot loading is actually pretty fast. See here and here our performance baselines for 4.14 and 5.10 kernel on your microVM configuration and platform of choice. If you are thinking of the overhead of starting a new firecracker process, I would find that negligible up to the point that the API server is listening on the API socket. No "fresh microVM" is created before loading the snapshot, the microVM is created as you load the snapshot.

jkrshnmenon commented 1 year ago

That is very impressive indeed! I tried looking into the time taken to for the API server to start listening and it was close to 1 ms. Alternatively, specifying a config file and the --no-api option reduces the time to start the firecracker process to 700 us.

I believe with the current functionalities in firecracker, my usecase is satisfied. Although it would have been simpler if I could specify the snapshot to be loaded on the command line or in the config file.

Thank you for your help.