Skip to content

Commit d1d3ebd

Browse files
committed
more fixes to cleanup
1 parent b97dfcb commit d1d3ebd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/llama-mmap.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ struct llama_mmap::impl {
323323
char path[128];
324324
bool is_new_mem[] = { false, false };
325325
int i;
326+
327+
// Set addr to the first mapping for node 0
328+
addr = (void*)(GGML_MMAP_VIRTUAL_MEMORY_BASE_OFFSET + base_address_offset);
329+
326330
for (int node = 0; node < 2; ++node) {
327331
numa_set_preferred(node);
328332
LLAMA_LOG_INFO("numa_set_preferred(%d)\n", node);
@@ -348,6 +352,11 @@ struct llama_mmap::impl {
348352
LLAMA_LOG_INFO("mmap(%s) desire=%p size=%llu result=%p is_new_mem[%d]=%s\n",
349353
path, (void*)address, GGML_MMAP_HUGEPAGESZ, mm, node, is_new_mem[node] ? "yes" : "no");
350354
if (((uintptr_t)mm) != address) {
355+
// Clean up any mappings we've already created before throwing
356+
for (const auto& mapping : numa_mappings) {
357+
munmap(mapping.addr, mapping.size);
358+
unlink(mapping.path.c_str());
359+
}
351360
LLAMA_LOG_WARN("unable to mmap memory: %d %s\n", errno, strerror(errno));
352361
throw std::runtime_error(format("mmap failed: %s", strerror(errno)));
353362
}

0 commit comments

Comments
 (0)