Commit 39039aa27 for llama.cpp
commit 39039aa27fe65244913d8a07303b8733f614fe20
Author: Adrien Gallouët <angt@huggingface.co>
Date: Thu Nov 19 07:50:33 2026 +0100
llama : fall back to buffered I/O on EIO (#32545)
* llama : fall back to buffered I/O on EIO
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
* Preserve bytes already read, resumes at the current file offset
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
---------
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp
index 9688a7ed4..93496c3b7 100644
--- a/src/llama-mmap.cpp
+++ b/src/llama-mmap.cpp
@@ -513,7 +513,7 @@ struct llama_file::impl {
if (errno == EINTR) {
continue;
}
- if (errno == EFAULT || errno == EINVAL) {
+ if (errno == EFAULT || errno == EINVAL || errno == EIO) {
LLAMA_LOG_WARN("%s: file '%s' falling back to buffered I/O due to %s\n",
__func__, fname.c_str(), strerror(errno));
const size_t read_offset = tell();
@@ -522,7 +522,7 @@ struct llama_file::impl {
alignment = 1;
init_fp("rb");
seek(read_offset, SEEK_SET);
- read_raw_unsafe(ptr, len);
+ read_raw_unsafe(static_cast<char *>(ptr) + bytes_read, to_read);
return;
}
throw std::runtime_error(format("read error: %s", strerror(errno)));