Skip to content

Commit 21bba95

Browse files
committed
fixes
Signed-off-by: Olga Andreeva <[email protected]>
1 parent d382123 commit 21bba95

File tree

1 file changed

+18
-14
lines changed
  • lib/llm/src/block_manager/storage

1 file changed

+18
-14
lines changed

lib/llm/src/block_manager/storage/disk.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl AlignedBuffer {
4848
/// Size will be rounded up to the nearest page boundary.
4949
fn new(size: usize) -> anyhow::Result<Self> {
5050
// Round up to nearest page size to ensure alignment requirements
51-
let aligned_size = (size + PAGE_SIZE - 1) / PAGE_SIZE * PAGE_SIZE;
51+
let aligned_size = size.div_ceil(PAGE_SIZE) * PAGE_SIZE;
5252

5353
let layout = std::alloc::Layout::from_size_align(aligned_size, PAGE_SIZE)
5454
.context("Failed to create aligned layout")?;
@@ -133,8 +133,7 @@ fn allocate_file(fd: RawFd, size: u64) -> anyhow::Result<()> {
133133
buf.len()
134134
} else {
135135
// Last partial write - round up to page size for O_DIRECT
136-
let aligned =
137-
((remaining as usize + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE;
136+
let aligned = (remaining as usize).div_ceil(PAGE_SIZE) * PAGE_SIZE;
138137
std::cmp::min(aligned, buf.len())
139138
};
140139

@@ -476,7 +475,6 @@ impl StorageAllocator<DiskStorage> for DiskAllocator {
476475
#[cfg(test)]
477476
mod tests {
478477
use super::*;
479-
use std::os::unix::fs::FileExt;
480478

481479
/// Mock writer that enforces strict O_DIRECT alignment rules like Lustre.
482480
/// This allows us to test the alignment logic without needing an actual Lustre filesystem.
@@ -647,7 +645,9 @@ mod tests {
647645
#[test]
648646
#[ignore]
649647
fn test_zerofill_with_o_direct() {
650-
std::env::set_var(DISK_ZEROFILL_FALLBACK_KEY, "1");
648+
unsafe {
649+
std::env::set_var(DISK_ZEROFILL_FALLBACK_KEY, "1");
650+
}
651651

652652
// Test various sizes including non-page-aligned sizes that would fail with
653653
// unaligned buffers on Lustre
@@ -673,10 +673,8 @@ mod tests {
673673
let fd = storage.fd() as RawFd;
674674
let mut buf = vec![0u8; std::cmp::min(size, 4096)];
675675

676-
let bytes_read = unsafe {
677-
nix::sys::uio::pread(fd, &mut buf, 0)
678-
.unwrap_or_else(|e| panic!("Failed to read back data for {}: {:?}", name, e))
679-
};
676+
let bytes_read = unsafe { nix::sys::uio::pread(fd, &mut buf, 0) }
677+
.unwrap_or_else(|e| panic!("Failed to read back data for {}: {:?}", name, e));
680678

681679
assert!(bytes_read > 0, "No data read back for {}", name);
682680
assert!(
@@ -688,22 +686,28 @@ mod tests {
688686
eprintln!("✓ {} passed", name);
689687
}
690688

691-
std::env::remove_var(DISK_ZEROFILL_FALLBACK_KEY);
689+
unsafe {
690+
std::env::remove_var(DISK_ZEROFILL_FALLBACK_KEY);
691+
}
692692
}
693693

694694
/// Test that O_DIRECT can be disabled and allocation still works.
695695
#[test]
696696
#[ignore]
697697
fn test_disable_o_direct() {
698-
std::env::set_var(DISK_DISABLE_O_DIRECT_KEY, "1");
699-
std::env::set_var(DISK_ZEROFILL_FALLBACK_KEY, "1");
698+
unsafe {
699+
std::env::set_var(DISK_DISABLE_O_DIRECT_KEY, "1");
700+
std::env::set_var(DISK_ZEROFILL_FALLBACK_KEY, "1");
701+
}
700702

701703
let size = 1024 * 1024;
702704
let storage = DiskStorage::new(size).expect("Failed to allocate with O_DIRECT disabled");
703705

704706
assert_eq!(storage.size(), size);
705707

706-
std::env::remove_var(DISK_DISABLE_O_DIRECT_KEY);
707-
std::env::remove_var(DISK_ZEROFILL_FALLBACK_KEY);
708+
unsafe {
709+
std::env::remove_var(DISK_DISABLE_O_DIRECT_KEY);
710+
std::env::remove_var(DISK_ZEROFILL_FALLBACK_KEY);
711+
}
708712
}
709713
}

0 commit comments

Comments
 (0)