Skip to content

Commit 47fbee9

Browse files
authored
fallback to preadv/pwritev when iouring inflight request over limit (#64)
Signed-off-by: charliecgxu <charliecgxu@tencent.com>
1 parent 2a9a663 commit 47fbee9

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

csrc/transfer_ssd.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,52 @@ static void _transfer_iouring_impl(
6565
reinterpret_cast<char *>(cpu_tensor_ptr) + cpu_k_block_offset;
6666
void *cpu_v_block_ptr =
6767
reinterpret_cast<char *>(cpu_tensor_ptr) + cpu_v_block_offset;
68+
ssize_t bytes_transfer = 0;
6869

6970
if (is_read) {
7071
rc = iouring.prep_read(fd, cpu_k_block_ptr, chunk_size_in_bytes,
7172
ssd_k_block_offset);
7273
if (rc < 0) {
73-
throw std::runtime_error("Failed to transfer K block");
74+
bytes_transfer = pread(fd, cpu_k_block_ptr, chunk_size_in_bytes,
75+
ssd_k_block_offset);
7476
}
7577
} else {
7678
rc = iouring.prep_write(fd, cpu_k_block_ptr, chunk_size_in_bytes,
7779
ssd_k_block_offset);
7880
if (rc < 0) {
79-
throw std::runtime_error("Failed to transfer K block");
81+
bytes_transfer = pwrite(fd, cpu_k_block_ptr, chunk_size_in_bytes,
82+
ssd_k_block_offset);
8083
}
8184
}
8285

86+
if (bytes_transfer && (bytes_transfer != chunk_size_in_bytes)) {
87+
throw std::runtime_error("Failed to transfer K block");
88+
}
89+
8390
if (is_mla) {
8491
continue;
8592
}
8693

94+
bytes_transfer = 0;
8795
if (is_read) {
8896
rc = iouring.prep_read(fd, cpu_v_block_ptr, chunk_size_in_bytes,
8997
ssd_v_block_offset);
9098
if (rc < 0) {
91-
throw std::runtime_error("Failed to transfer V block");
99+
bytes_transfer = pread(fd, cpu_v_block_ptr, chunk_size_in_bytes,
100+
ssd_v_block_offset);
92101
}
93102
} else {
94103
rc = iouring.prep_write(fd, cpu_v_block_ptr, chunk_size_in_bytes,
95104
ssd_v_block_offset);
96105
if (rc < 0) {
97-
throw std::runtime_error("Failed to transfer V block");
106+
bytes_transfer = pwrite(fd, cpu_v_block_ptr, chunk_size_in_bytes,
107+
ssd_v_block_offset);
98108
}
99109
}
110+
111+
if (bytes_transfer && (bytes_transfer != chunk_size_in_bytes)) {
112+
throw std::runtime_error("Failed to transfer K block");
113+
}
100114
} // end layer loop
101115
} // end block loop
102116

0 commit comments

Comments
 (0)