From 2ca781518af41e76a448035ad51215ec12651f67 Mon Sep 17 00:00:00 2001 From: Alexandru Matei Date: Wed, 30 Aug 2023 15:29:59 +0300 Subject: [PATCH 1/2] clh: Direct IO support for block devices Clh suports direct i/o for disks. It doesn't offer any support for noflush, removed passing of option to cloud-hypervisor internal config Fixes: #7798 Signed-off-by: Alexandru Matei --- src/runtime/config/configuration-clh.toml.in | 9 +++++++++ src/runtime/pkg/katautils/config.go | 1 - src/runtime/virtcontainers/clh.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/runtime/config/configuration-clh.toml.in b/src/runtime/config/configuration-clh.toml.in index e3c584a53c..f2eca9b3d8 100644 --- a/src/runtime/config/configuration-clh.toml.in +++ b/src/runtime/config/configuration-clh.toml.in @@ -176,6 +176,15 @@ virtio_fs_cache = "@DEFVIRTIOFSCACHE@" # rootfs is backed by a block device. This is virtio-blk. block_device_driver = "virtio-blk" +# Specifies cache-related options will be set to block devices or not. +# Default false +#block_device_cache_set = true + +# Specifies cache-related options for block devices. +# Denotes whether use of O_DIRECT (bypass the host page cache) is enabled. +# Default false +#block_device_cache_direct = true + # Enable huge pages for VM RAM, default false # Enabling this will result in the VM memory # being allocated using huge pages. diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index 0e280de0e9..9dc0ff57c0 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -1082,7 +1082,6 @@ func newClhHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) { BlockDeviceDriver: blockDriver, BlockDeviceCacheSet: h.BlockDeviceCacheSet, BlockDeviceCacheDirect: h.BlockDeviceCacheDirect, - BlockDeviceCacheNoflush: h.BlockDeviceCacheNoflush, EnableIOThreads: h.EnableIOThreads, Msize9p: h.msize9p(), ColdPlugVFIO: h.coldPlugVFIO(), diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index b8e3abe89c..9ce491f00b 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -851,6 +851,9 @@ func (clh *cloudHypervisor) hotplugAddBlockDevice(drive *config.BlockDrive) erro clhDisk := *chclient.NewDiskConfig(drive.File) clhDisk.Readonly = &drive.ReadOnly clhDisk.VhostUser = func(b bool) *bool { return &b }(false) + if clh.config.BlockDeviceCacheSet { + clhDisk.Direct = &clh.config.BlockDeviceCacheDirect + } queues := int32(clh.config.NumVCPUs) queueSize := int32(1024) From d507d189bbfda69a26b2e1664e2b3428dbfe90ca Mon Sep 17 00:00:00 2001 From: Alexandru Matei Date: Fri, 1 Sep 2023 12:49:18 +0300 Subject: [PATCH 2/2] fc: Add support for noflush cache option Firecracker supports noflush semantic via Unsafe cache type. There is no support for direct i/o, remove it from config file Fixes: #7823 Signed-off-by: Alexandru Matei --- src/runtime/config/configuration-fc.toml.in | 5 ----- src/runtime/virtcontainers/fc.go | 11 +++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/runtime/config/configuration-fc.toml.in b/src/runtime/config/configuration-fc.toml.in index e28316cfad..28040aacc1 100644 --- a/src/runtime/config/configuration-fc.toml.in +++ b/src/runtime/config/configuration-fc.toml.in @@ -126,11 +126,6 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_FC@" # Default false #block_device_cache_set = true -# Specifies cache-related options for block devices. -# Denotes whether use of O_DIRECT (bypass the host page cache) is enabled. -# Default false -#block_device_cache_direct = true - # Specifies cache-related options for block devices. # Denotes whether flush requests for the device are ignored. # Default false diff --git a/src/runtime/virtcontainers/fc.go b/src/runtime/virtcontainers/fc.go index e3348f68dd..1ecf366b4f 100644 --- a/src/runtime/virtcontainers/fc.go +++ b/src/runtime/virtcontainers/fc.go @@ -835,6 +835,17 @@ func (fc *firecracker) createDiskPool(ctx context.Context) error { PathOnHost: &jailedDrive, } + if fc.config.BlockDeviceCacheSet { + var cacheOption string + if fc.config.BlockDeviceCacheNoflush { + cacheOption = models.DriveCacheTypeUnsafe + } else { + cacheOption = models.DriveCacheTypeWriteback + } + + drive.CacheType = &cacheOption + } + fc.fcConfig.Drives = append(fc.fcConfig.Drives, drive) }