Skip to content

Commit

Permalink
[ISSUE mxsm#2310]🚀Implement MappedFile isLoaded method (mxsm#2311)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm authored Jan 17, 2025
1 parent 3049e47 commit 94d1532
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 4 deletions.
137 changes: 133 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions rocketmq-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ trait-variant.workspace = true
sysinfo = "0.33.1"
once_cell = { workspace = true }
cheetah-string = { workspace = true }


[target.'cfg(linux)'.dependencies]
libc = "0.2.169"

[target.'cfg(windows)'.dependencies]
windows = {version = "0.59.0",features = ["Win32_Security","Win32_System_Memory_NonVolatile"]}


[dev-dependencies]
tempfile = "3.14.0"
criterion = { version = "0.5", features = ["html_reports"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,55 @@ impl MappedFile for DefaultMappedFile {
}

#[inline]
#[cfg(target_os = "linux")]
fn is_loaded(&self, position: i64, size: usize) -> bool {
// use libc::c_void;
// use libc::mincore;
// use libc::EINVAL;
// let page_size = unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize };
// let page_count = (length + page_size - 1) / page_size;

// let mut vec = vec![0u8; page_count];
// let ret = unsafe { mincore(address as *mut c_void, length, vec.as_mut_ptr()) };

// if ret == -1 {
// return false;
// }

// !vec.iter().any(|&byte| byte & 1 == 0)
true
}

#[inline]
#[cfg(target_os = "windows")]
fn is_loaded(&self, position: i64, size: usize) -> bool {
/*use windows::Win32::Foundation::{BOOL, HANDLE};
use windows::Win32::System::Memory::{VirtualQuery, MEMORY_BASIC_INFORMATION, MEM_COMMIT};
let address = self.mmapped_file.as_ptr().wrapping_add(position as usize);
let mut info: MEMORY_BASIC_INFORMATION = unsafe { std::mem::zeroed() };
let mut offset = 0;
while offset < length {
let result = unsafe {
VirtualQuery(
address.add(offset) as *const _,
&mut info,
std::mem::size_of::<MEMORY_BASIC_INFORMATION>(),
)
};
if result == 0 {
return Err(std::io::Error::last_os_error());
}
if info.State != MEM_COMMIT {
return Ok(false);
}
offset += info.RegionSize;
}*/

true
}

Expand Down

0 comments on commit 94d1532

Please sign in to comment.