Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add virtio-balloon device #255

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

add virtio-balloon device #255

wants to merge 3 commits into from

Conversation

iwinux
Copy link

@iwinux iwinux commented Feb 13, 2025

The virtio-balloon device is added to the VM when --device virtio-balloon is specified. However, I'm not sure how to verify it's actually working inside the VM.

$ find /sys -iname '*balloon*'
/sys/kernel/btf/virtio_balloon
/sys/bus/virtio/drivers/virtio_balloon
/sys/module/virtio_balloon
/sys/module/virtio_balloon/drivers/virtio:virtio_balloon

TODOs:

  • add test to vfkit/test/vm_test.go
  • add doc to usage.md
  • confirm behavior of adding multiple balloon device

Copy link

openshift-ci bot commented Feb 13, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign praveenkumar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

openshift-ci bot commented Feb 13, 2025

Hi @iwinux. Thanks for your PR.

I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@cfergeau
Copy link
Collaborator

However, I'm not sure how to verify it's actually working inside the VM.

https://developer.apple.com/documentation/virtualization/vzvirtiotraditionalmemoryballoondevice?language=objc has some explanations how to interact with the balloon device. I don't know if these properties are supported in Code-Hex/vz though

Copy link
Collaborator

@cfergeau cfergeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the patch!

Can you also add a balloon test to

vfkit/test/vm_test.go

Lines 201 to 230 in 9c685bc

var pciidTests = map[string]pciidTest{
"virtio-net": {
vendorID: 0x1af4, // Red Hat
deviceID: 0x1041,
createDev: func(_ *testing.T) (config.VirtioDevice, error) {
return config.VirtioNetNew("")
},
},
"virtio-serial": {
vendorID: 0x1af4, // Red Hat
deviceID: 0x1043,
createDev: func(t *testing.T) (config.VirtioDevice, error) {
return config.VirtioSerialNew(filepath.Join(t.TempDir(), "serial.log"))
},
},
"virtio-rng": {
vendorID: 0x1af4, // Red Hat
deviceID: 0x1044,
createDev: func(_ *testing.T) (config.VirtioDevice, error) {
return config.VirtioRngNew()
},
},
"virtio-fs": {
vendorID: 0x1af4, // Red Hat
deviceID: 0x105a,
createDev: func(_ *testing.T) (config.VirtioDevice, error) {
return config.VirtioFsNew("./", "vfkit-share-test")
},
},
}

?
And adding it to the documentation would also be useful, for example before/after virtio-rng https://github.com/crc-org/vfkit/blob/main/doc/usage.md#random-number-generator

Documentation for the virtualization framework says that it's only allowed to have one virtio-balloon device at a time in a VM, do you know if we get an error if we pass --device virtio-balloon multiple times?

@iwinux
Copy link
Author

iwinux commented Feb 14, 2025

https://developer.apple.com/documentation/virtualization/vzvirtiotraditionalmemoryballoondevice?language=objc has some explanations how to interact with the balloon device. I don't know if these properties are supported in Code-Hex/vz though

@cfergeau After reading the page I realize that this patch has only enabled the virtio-balloon device for guests, but hasn't utilized the device at the host side for memory allocation. The latter task seems a bit more complicated, should I leave it as a separate issue?

https://github.com/firecracker-microvm/firecracker/blob/main/docs/ballooning.md also provides some insights on how the device can be used.

@cfergeau
Copy link
Collaborator

The latter task seems a bit more complicated, should I leave it as a separate issue?

No objections to that, this definitely can be addressed later on, I was just trying to provide guidance as you were unsure how to test it.

@iwinux
Copy link
Author

iwinux commented Feb 18, 2025

Passing --device virtio-balloon multiple times has no observable effects:

Output of vfkit:

INFO[0000] &{1 512    {[efi variable-store=efi.vars create] true}  [virtio-blk,path=alpine-virt-3.21.2-aarch64.iso virtio-fs,sharedDir=test,mountTag=test virtio-net,nat,mac=ca:fe:00:00:00:97 virtio-gpu,width=1920,height=1080 virtio-input,keyboard virtio-input,pointing virtio-rng virtio-balloon virtio-balloon virtio-balloon virtio-balloon virtio-balloon] none://  true } 
INFO[0000] boot parameters: &{EFIVariableStorePath:efi.vars CreateVariableStore:true} 
INFO[0000]                                              
INFO[0000] virtual machine parameters:                  
INFO[0000]      vCPUs: 1                                    
INFO[0000]      memory: 512 MiB                             
INFO[0000]                                              
INFO[0000] Adding virtio-blk device (imagePath: alpine-virt-3.21.2-aarch64.iso) 
INFO[0000] Adding virtio-fs device                      
INFO[0000] Adding virtio-net device (nat: true macAddress: [ca:fe:00:00:00:97]) 
INFO[0000] Adding virtio-gpu device                     
INFO[0000] Adding virtio-input keyboard device          
INFO[0000] Adding virtio-input pointing device          
INFO[0000] Adding virtio-rng device                     
INFO[0000] Adding virtio-balloon device                 
INFO[0000] Adding virtio-balloon device                 
INFO[0000] Adding virtio-balloon device                 
INFO[0000] Adding virtio-balloon device                 
INFO[0000] Adding virtio-balloon device

Output of lspci inside VM:

00:00.0 Host bridge: Apple Inc. Device 1a05
00:01.0 Ethernet controller: Red Hat, Inc. Virtio 1.0 network device (rev 01)
00:05.0 Mass storage controller: Red Hat, Inc. Virtio 1.0 block device (rev 01)
00:06.0 Mass storage controller: Red Hat, Inc. Virtio file system (rev 01)
00:07.0 Display controller: Red Hat, Inc. Virtio 1.0 GPU (rev 01)
00:08.0 Network and computing encryption device: Red Hat, Inc. Virtio 1.0 RNG (rev 01)
00:09.0 Memory controller: Red Hat, Inc. Virtio 1.0 memory balloon (rev 01)
00:0a.0 USB controller: Apple Inc. Device 1a06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants