Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid mixing std::ptr::read/write_volatile() and std::ptr::copy() #111

Open
jiangliu opened this issue Aug 25, 2020 · 0 comments
Open

Avoid mixing std::ptr::read/write_volatile() and std::ptr::copy() #111

jiangliu opened this issue Aug 25, 2020 · 0 comments

Comments

@jiangliu
Copy link
Member

The copy_slice() wrapper is used to access guest memory for most VolatileMemory methods, but there's an exception that copy_to_volatile_slice() uses std::ptr::copy(). The copy_to_volatile_slice() method should be refined to use copy_slice() so we never mix std::ptr::read/write_volatile() and std::ptr::copy()

jiangliu added a commit to jiangliu/vm-memory that referenced this issue Aug 25, 2020
Replace std::ptr::copy() with copy_slice(). With this change applied,
most accesses to guest memory are wrapped by copy_slice() to avoid
mixing read/write_volatile() and memcpy(). The file related interfaces,
read_from()/read_exact_from()/write_to()/write_all_to(), may still
use normal memory operations.

The change causes more than 50% performance drop of
copy_to_volatile_slice() when copying 10K data buffer. The performance
drop is caused by non-optimal implemantation of copy_slice(), which
should be tracked as a dedicate issue.

Benchmarking VolatileSlice::copy_to_volatile_slice:
	Collecting 200 samples in estimated 10.000 s
	VolatileSlice::copy_to_volatile_slice
        	time:   [684.24 ns 687.08 ns 691.81 ns]
                change: [+134.93% +136.04% +137.32%] (p = 0.00 < 0.05)
                Performance has regressed.
Found 11 outliers among 200 measurements (5.50%)
  1 (0.50%) low mild
  4 (2.00%) high mild
  6 (3.00%) high severe

Fixes: rust-vmm#111

Signed-off-by: Liu Jiang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant