Skip to content
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
47 changes: 20 additions & 27 deletions src/vmm/src/devices/virtio/balloon/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::Deref;
use std::sync::Arc;
use std::time::Duration;

use log::{error, info, warn};
use log::{debug, error, info, warn};
use serde::{Deserialize, Serialize};
use utils::time::TimerFd;
use vmm_sys_util::eventfd::EventFd;
Expand Down Expand Up @@ -207,7 +207,7 @@ pub struct BalloonStats {
}

impl BalloonStats {
fn update_with_stat(&mut self, stat: &BalloonStat) -> Result<(), BalloonError> {
fn update_with_stat(&mut self, stat: &BalloonStat) {
let val = Some(stat.val);
match stat.tag {
VIRTIO_BALLOON_S_SWAP_IN => self.swap_in = val,
Expand All @@ -226,12 +226,8 @@ impl BalloonStats {
VIRTIO_BALLOON_S_DIRECT_SCAN => self.direct_scan = val,
VIRTIO_BALLOON_S_ASYNC_RECLAIM => self.async_reclaim = val,
VIRTIO_BALLOON_S_DIRECT_RECLAIM => self.direct_reclaim = val,
_ => {
return Err(BalloonError::MalformedPayload);
}
tag => debug!("balloon: unknown stats update tag: {tag}"),
}

Ok(())
}
}

Expand Down Expand Up @@ -503,10 +499,7 @@ impl Balloon {
let stat = mem
.read_obj::<BalloonStat>(addr)
.map_err(|_| BalloonError::MalformedDescriptor)?;
self.latest_stats.update_with_stat(&stat).map_err(|_| {
METRICS.stats_update_fails.inc();
BalloonError::MalformedPayload
})?;
self.latest_stats.update_with_stat(&stat);
}

self.stats_desc_index = Some(head.index);
Expand Down Expand Up @@ -1067,52 +1060,52 @@ pub(crate) mod tests {
val: 1,
};

stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.swap_in, Some(1));
stat.tag = VIRTIO_BALLOON_S_SWAP_OUT;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.swap_out, Some(1));
stat.tag = VIRTIO_BALLOON_S_MAJFLT;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.major_faults, Some(1));
stat.tag = VIRTIO_BALLOON_S_MINFLT;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.minor_faults, Some(1));
stat.tag = VIRTIO_BALLOON_S_MEMFREE;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.free_memory, Some(1));
stat.tag = VIRTIO_BALLOON_S_MEMTOT;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.total_memory, Some(1));
stat.tag = VIRTIO_BALLOON_S_AVAIL;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.available_memory, Some(1));
stat.tag = VIRTIO_BALLOON_S_CACHES;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.disk_caches, Some(1));
stat.tag = VIRTIO_BALLOON_S_HTLB_PGALLOC;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.hugetlb_allocations, Some(1));
stat.tag = VIRTIO_BALLOON_S_HTLB_PGFAIL;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.hugetlb_failures, Some(1));
stat.tag = VIRTIO_BALLOON_S_OOM_KILL;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.oom_kill, Some(1));
stat.tag = VIRTIO_BALLOON_S_ALLOC_STALL;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.alloc_stall, Some(1));
stat.tag = VIRTIO_BALLOON_S_ASYNC_SCAN;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.async_scan, Some(1));
stat.tag = VIRTIO_BALLOON_S_DIRECT_SCAN;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.direct_scan, Some(1));
stat.tag = VIRTIO_BALLOON_S_ASYNC_RECLAIM;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.async_reclaim, Some(1));
stat.tag = VIRTIO_BALLOON_S_DIRECT_RECLAIM;
stats.update_with_stat(&stat).unwrap();
stats.update_with_stat(&stat);
assert_eq!(stats.direct_reclaim, Some(1));
}

Expand Down
3 changes: 0 additions & 3 deletions src/vmm/src/devices/virtio/balloon/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ pub(super) struct BalloonDeviceMetrics {
pub inflate_count: SharedIncMetric,
// Number of balloon statistics updates from the driver.
pub stats_updates_count: SharedIncMetric,
// Number of balloon statistics update failures.
pub stats_update_fails: SharedIncMetric,
/// Number of balloon device deflations.
pub deflate_count: SharedIncMetric,
/// Number of times when handling events on a balloon device failed.
Expand All @@ -83,7 +81,6 @@ impl BalloonDeviceMetrics {
activate_fails: SharedIncMetric::new(),
inflate_count: SharedIncMetric::new(),
stats_updates_count: SharedIncMetric::new(),
stats_update_fails: SharedIncMetric::new(),
deflate_count: SharedIncMetric::new(),
event_fails: SharedIncMetric::new(),
free_page_report_count: SharedIncMetric::new(),
Expand Down
3 changes: 0 additions & 3 deletions src/vmm/src/devices/virtio/block/virtio/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ pub struct BlockDeviceMetrics {
pub rate_limiter_event_count: SharedIncMetric,
/// Number of update operation triggered on this block device.
pub update_count: SharedIncMetric,
/// Number of failures while doing update on this block device.
pub update_fails: SharedIncMetric,
/// Number of bytes read by this block device.
pub read_bytes: SharedIncMetric,
/// Number of bytes written by this block device.
Expand Down Expand Up @@ -215,7 +213,6 @@ impl BlockDeviceMetrics {
self.rate_limiter_event_count
.add(other.rate_limiter_event_count.fetch_diff());
self.update_count.add(other.update_count.fetch_diff());
self.update_fails.add(other.update_fails.fetch_diff());
self.read_bytes.add(other.read_bytes.fetch_diff());
self.write_bytes.add(other.write_bytes.fetch_diff());
self.read_count.add(other.read_count.fetch_diff());
Expand Down
6 changes: 6 additions & 0 deletions tests/integration_tests/functional/test_balloon.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ def test_stats(uvm_plain_any):
# Get another reading of the stats after the polling interval has passed.
deflated_stats = test_microvm.api.balloon_stats.get().json()

# Ensure that stats don't have unknown balloon stats fields
assert "balloon: unknown stats update tag:" not in test_microvm.log_data

# Ensure the stats reflect deflating the balloon.
assert inflated_stats["free_memory"] < deflated_stats["free_memory"]
assert inflated_stats["available_memory"] < deflated_stats["available_memory"]
Expand Down Expand Up @@ -372,6 +375,9 @@ def test_stats_update(uvm_plain_any):
final_stats = test_microvm.api.balloon_stats.get().json()
assert next_stats["available_memory"] != final_stats["available_memory"]

# Ensure that stats don't have unknown balloon stats fields
assert "balloon: unknown stats update tag:" not in test_microvm.log_data


def test_balloon_snapshot(uvm_plain_any, microvm_factory):
"""
Expand Down