From 770c74241b73e82af7ece6cd1211fc1a1fce40a2 Mon Sep 17 00:00:00 2001 From: Alexander Droste Date: Tue, 27 Oct 2026 14:20:24 +0000 Subject: [PATCH] fix(cuda): restore 4 MiB chunks for mapped file copies #10716 copied cached file pages in 4 MiB chunks, alternating filling one chunk's page tables with copying the previous one, and kept that size independent of #10715, which grew staged file reads to 8 MiB chunks. Both used `FILE_READ_CHUNK_BYTES`, so #10715 silently doubled the mapped copy chunks as well, delaying the first copy of every mapped read. Give mapped copies their own 4 MiB chunk size. Signed-off-by: Alexander Droste --- vortex-cuda/src/pooled_read_at/file.rs | 8 ++++++-- vortex-cuda/src/pooled_read_at/file/tests.rs | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/vortex-cuda/src/pooled_read_at/file.rs b/vortex-cuda/src/pooled_read_at/file.rs index 237a3bb91fc..49db6b6d31f 100644 --- a/vortex-cuda/src/pooled_read_at/file.rs +++ b/vortex-cuda/src/pooled_read_at/file.rs @@ -58,6 +58,10 @@ pub const DEFAULT_FILE_CONCURRENCY: usize = 32; // to limit blocking read sizes and start transfers before the whole segment is read. const FILE_READ_CHUNK_BYTES: usize = 8 << 20; +/// Mapped copies alternate filling a chunk's page tables with copying the previous chunk, so +/// smaller chunks start the device sooner, independently of the staged read size. +const MAPPED_COPY_CHUNK_BYTES: usize = 4 << 20; + /// Upper bound on blocks per mapped copy launch: a few per SM saturates host-memory reads. const MAPPED_COPY_BLOCKS_MAX: u64 = 1024; const MAPPED_COPY_THREADS: u32 = 256; @@ -386,8 +390,8 @@ impl MappedFile { // The guard records the queued copies as the output's write when this scope ends, // including on error, so frees and readers on other streams wait for them. let (base, write) = output.device_ptr_mut(&self.stream); - for chunk in (0..length).step_by(FILE_READ_CHUNK_BYTES) { - let size = (length - chunk).min(FILE_READ_CHUNK_BYTES); + for chunk in (0..length).step_by(MAPPED_COPY_CHUNK_BYTES) { + let size = (length - chunk).min(MAPPED_COPY_CHUNK_BYTES); #[cfg(target_os = "linux")] { let _fill = MAPPED_FILL.lock(); diff --git a/vortex-cuda/src/pooled_read_at/file/tests.rs b/vortex-cuda/src/pooled_read_at/file/tests.rs index d75440e6c5c..bd42dc2c911 100644 --- a/vortex-cuda/src/pooled_read_at/file/tests.rs +++ b/vortex-cuda/src/pooled_read_at/file/tests.rs @@ -316,7 +316,7 @@ async fn cancelled_reads_keep_slots_and_buffers_until_blocking_io_finishes() -> Ok(()) } -const MAPPED_FILE_BYTES: usize = 2 * FILE_READ_CHUNK_BYTES + 4096; +const MAPPED_FILE_BYTES: usize = 2 * MAPPED_COPY_CHUNK_BYTES + 4096; /// Opens a real buffered file of `file_byte` content with the device-side mapped copy enabled. fn mapped_reader() -> VortexResult<( @@ -346,8 +346,8 @@ fn mapped_reader() -> VortexResult<( #[case::empty(37, 0)] #[case::single_byte_unaligned(5, 1)] #[case::short_unaligned(15, 17)] -#[case::chunk_aligned(0, FILE_READ_CHUNK_BYTES - 1)] -#[case::chunks_with_tail(4091, 2 * FILE_READ_CHUNK_BYTES + 3)] +#[case::chunk_aligned(0, MAPPED_COPY_CHUNK_BYTES - 1)] +#[case::chunks_with_tail(4091, 2 * MAPPED_COPY_CHUNK_BYTES + 3)] #[case::through_file_end(0, MAPPED_FILE_BYTES)] #[crate::test] async fn mapped_reads_preserve_bytes_and_offsets( @@ -423,9 +423,9 @@ async fn concurrent_mapped_reads_preserve_bytes_and_offsets() -> VortexResult<() reader.read_slots.close(); let reads = [ - (4091, 2 * FILE_READ_CHUNK_BYTES + 3), + (4091, 2 * MAPPED_COPY_CHUNK_BYTES + 3), (0, MAPPED_FILE_BYTES), - (FILE_READ_CHUNK_BYTES as u64 - 7, 3 * 4096), + (MAPPED_COPY_CHUNK_BYTES as u64 - 7, 3 * 4096), ]; let buffers = wait_for( "concurrent mapped reads did not finish",