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

[DNM] PoC for huge pages in libvirt domain definition #698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/libvirttools/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ func (ds *domainSettings) createDomain(config *types.VMConfig) *libvirtxml.Domai
},
}

if len(config.ParsedAnnotations.HugePagesSettings) > 0 {
domain.MemoryBacking = &libvirtxml.DomainMemoryBacking{
MemoryHugePages: &libvirtxml.DomainMemoryHugepages{},
}
for _, el := range config.ParsedAnnotations.HugePagesSettings {
domain.MemoryBacking.MemoryHugePages.Hugepages = append(domain.MemoryBacking.MemoryHugePages.Hugepages, libvirtxml.DomainMemoryHugepage{
Size: el.Size,
Unit: el.Unit,
Nodeset: el.NodeSet,
})
}
}

if ds.enableSriov {
domain.QEMUCommandline.Envs = append(domain.QEMUCommandline.Envs,
libvirtxml.DomainQEMUCommandlineEnv{Name: "VMWRAPPER_KEEP_PRIVS", Value: "1"})
Expand Down
40 changes: 39 additions & 1 deletion pkg/metadata/types/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
cloudInitUserDataKeyName = "VirtletCloudInitUserData"
cloudInitUserDataScriptKeyName = "VirtletCloudInitUserDataScript"
cloudInitImageType = "VirtletCloudInitImageType"
hugePagesSetupKeyName = "VirtletHugePages"
sshKeysKeyName = "VirtletSSHKeys"
// CloudInitUserDataSourceKeyName is the name of user data source key in the pod annotations.
CloudInitUserDataSourceKeyName = "VirtletCloudInitUserDataSource"
Expand Down Expand Up @@ -62,6 +63,12 @@ const (
DiskDriverScsi DiskDriverName = "scsi"
)

type HugePagesEntry struct {
Size uint
Unit string
NodeSet string
}

// VirtletAnnotations contains parsed values for pod annotations supported
// by Virtlet.
type VirtletAnnotations struct {
Expand All @@ -80,7 +87,8 @@ type VirtletAnnotations struct {
// SSHKets specifies ssh public keys to use.
SSHKeys []string
// DiskDriver specifies the disk driver to use.
DiskDriver DiskDriverName
DiskDriver DiskDriverName
HugePagesSettings []HugePagesEntry
}

// ExternalDataLoader is a function that loads external data that's specified
Expand Down Expand Up @@ -197,5 +205,35 @@ func (va *VirtletAnnotations) parsePodAnnotations(ns string, podAnnotations map[
va.CDImageType = CloudInitImageType(strings.ToLower(podAnnotations[cloudInitImageType]))
va.DiskDriver = DiskDriverName(podAnnotations[diskDriverKeyName])

if hpEntryStr, found := podAnnotations[hugePagesSetupKeyName]; found {
for _, el := range strings.Split(hpEntryStr, ";") {
entry := strings.Split(el, " ")
if len(entry) != 3 {
return fmt.Errorf("huge pages entry expected to have 3 fields has incorrect number of them: %v", entry)
}

size := 0
var err error
if size, err = strconv.Atoi(entry[0]); err != nil {
return fmt.Errorf("huge pages entry has %q as size while expected int: %v", entry[0], err)
}

switch entry[1] {
case "K":
case "M":
case "G":
default:
return fmt.Errorf("huge pages entry have %q as unit while expected 'K', 'M', or 'G'", entry[1])
}

// TODO: nodeset validation (string contains only digits, minus sign or comma character)
va.HugePagesSettings = append(va.HugePagesSettings, HugePagesEntry{
Size: uint(size),
Unit: entry[1],
NodeSet: entry[2],
})
}
}

return nil
}