From 21620a479c44bbaa664faf30232bdc134882a48b Mon Sep 17 00:00:00 2001 From: Li Zebin Date: Sat, 29 Jul 2023 13:12:50 +0800 Subject: [PATCH] vsock: Move `iter` outside of the loop in `process_rx_queue` the iter() function is used for produce a queue iterator to iterate over the descriptors. But usually, it shouldn't be in the while loop, which might brings more unnecessary overhead. So move `iter` outside of the while loop. And the process_tx_queue has the same problem, maybe we can fix it, too. Signed-off-by: Li Zebin --- crates/vsock/src/vhu_vsock_thread.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/vsock/src/vhu_vsock_thread.rs b/crates/vsock/src/vhu_vsock_thread.rs index 726e2b64d..eae6f885d 100644 --- a/crates/vsock/src/vhu_vsock_thread.rs +++ b/crates/vsock/src/vhu_vsock_thread.rs @@ -453,11 +453,11 @@ impl VhostUserVsockThread { let queue = vring_mut.get_queue_mut(); - while let Some(mut avail_desc) = queue + let mut queue_iter = queue .iter(atomic_mem.memory()) - .map_err(|_| Error::IterateQueue)? - .next() - { + .map_err(|_| Error::IterateQueue)?; + + for mut avail_desc in queue_iter { used_any = true; let mem = atomic_mem.clone().memory();