[PW_SID:1129404] RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask#2304
[PW_SID:1129404] RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask#2304linux-riscv-bot wants to merge 2 commits into
Conversation
The existing kvm_riscv_gstage_wp_range() walks the entire [start, end) range to apply write protection for dirty log clearing, even when the provided mask has zero bits (i.e., many GFNs do not need protection). This leads to unnecessary page table walks when the mask is sparse. Replace the range-based approach with a new function kvm_riscv_gstage_wp_pt_masked() that iterates only over the set bits in the mask. For each set bit, it looks up the leaf PTE and applies write protection. Once a huge page is encountered, the entire huge-page range is processed in one go, and the corresponding bits in the mask are cleared using bitmap_clear(). Performance was measured with KVM selftests dirty_log_perf_test on a Spacemit k3 host with the following configuration: - vCPUs: 2 (-v 2) - Memory: 1GB (-b 1G) - Iterations: 3 (-i 3) - Write percentage varied via -w parameter to simulate different dirty mask densities. The following data shows the time spent in the clear-dirty-log phase (i.e., the KVM_CLEAR_DIRTY_LOG ioctl) under each configuration. +------------------+------------------+------------------+-------------+ | Write Percentage | Original (s) | Patched (s) | Improvement | +------------------+------------------+------------------+-------------+ | 10% | 0.012905 | 0.009213 | +28.6% | | 30% | 0.014217 | 0.010287 | +27.6% | | 50% | 0.014606 | 0.011772 | +19.4% | | 70% | 0.014735 | 0.013199 | +10.4% | | 100% | 0.014759 | 0.015294 | -3.6% | +------------------+------------------+------------------+-------------+ The performance improvement is most significant when the dirty mask is sparse (low write percentage), which is common in real-world scenarios with low to moderate memory write intensity. In the worst-case scenario where the mask is fully set (100% write), the optimization introduces a slight 3.6% overhead due to the additional bit operations, which is acceptable given the substantial gains in common cases. This change significantly reduces the number of page-table walks when the dirty mask has many zero bits, improving the efficiency of KVM_CLEAR_DIRTY_LOG and related ioctls. Signed-off-by: Wang Yechao <wang.yechao255@zte.com.cn> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
|
Patch 1: "RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask" |
8ca72ef to
60e0882
Compare
PR for series 1129404 applied to workflow__riscv__fixes
Name: RISC-V: KVM: Improve dirty log clearing by skipping zero bits in mask
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1129404
Version: 1