vmm: use RateLimiterGroup for virtio-blk devices

Add a 'rate_limit_groups' field to VmConfig that defines a set of
named RateLimiterGroups.

When the 'rate_limit_group' field of DiskConfig is defined, all
virtio-blk queues will be rate-limited by a shared RateLimiterGroup.
The lifecycle of all RateLimiterGroups is tied to the Vm.
A RateLimiterGroup may exist even if no Disks are configured to use
the RateLimiterGroup. Disks may be hot-added or hot-removed from the
RateLimiterGroup.

When the 'rate_limiter' field of DiskConfig is defined, we construct
an anonymous RateLimiterGroup whose lifecycle is tied to the Disk.
This is primarily done for api backwards compatability. Importantly,
the behavior is not the same! This implementation rate_limits the
aggregate bandwidth / iops of an individual disk rather than the
bandwidth / iops of an individual queue of a disk.

When neither the 'rate_limit_group' or the 'rate_limiter' fields of
DiskConfig is defined, the Disk is not rate-limited.

Signed-off-by: Thomas Barrett <tbarrett@crusoeenergy.com>
This commit is contained in:
Thomas Barrett
2023-12-07 19:45:08 +00:00
committed by Bo Chen
parent c71da496c0
commit c297d8d796
10 changed files with 358 additions and 18 deletions
+21
View File
@@ -195,6 +195,23 @@ pub enum VhostMode {
Server,
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct RateLimiterGroupConfig {
#[serde(default)]
pub id: String,
#[serde(default)]
pub rate_limiter_config: RateLimiterConfig,
}
impl Default for RateLimiterGroupConfig {
fn default() -> Self {
RateLimiterGroupConfig {
id: "".to_string(),
rate_limiter_config: RateLimiterConfig::default(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct DiskConfig {
pub path: Option<PathBuf>,
@@ -212,6 +229,8 @@ pub struct DiskConfig {
pub vhost_user: bool,
pub vhost_socket: Option<String>,
#[serde(default)]
pub rate_limit_group: Option<String>,
#[serde(default)]
pub rate_limiter_config: Option<RateLimiterConfig>,
#[serde(default)]
pub id: Option<String>,
@@ -253,6 +272,7 @@ impl Default for DiskConfig {
id: None,
disable_io_uring: false,
disable_aio: false,
rate_limit_group: None,
rate_limiter_config: None,
pci_segment: 0,
serial: None,
@@ -591,6 +611,7 @@ pub struct VmConfig {
#[serde(default)]
pub memory: MemoryConfig,
pub payload: Option<PayloadConfig>,
pub rate_limit_groups: Option<Vec<RateLimiterGroupConfig>>,
pub disks: Option<Vec<DiskConfig>>,
pub net: Option<Vec<NetConfig>>,
#[serde(default)]