From 0146c02882cc2ef6a9dbb7b8aaebe032c64d1b60 Mon Sep 17 00:00:00 2001 From: "John W. Leimgruber III" Date: Sat, 22 Mar 2025 14:52:25 -0400 Subject: [PATCH] Set posix_madvise(..., MADV_HUGEPAGE) for THP --- src/llama.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/llama.cpp b/src/llama.cpp index 54e0bb012..56307732d 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -1870,6 +1870,11 @@ struct llama_mmap { strerror(errno)); } } + LLAMA_LOG_INFO("Setting posix_madvise(MADV_HUGEPAGE) in an attempt to enable THP for correct system configurations!\n"); + if (posix_madvise(addr, file->size, MADV_HUGEPAGE)) { + LLAMA_LOG_WARN("warning: posix_madvise(.., MADV_HUGEPAGE) failed: %s\n", + strerror(errno)); + } // initialize list of mapped_fragments mapped_fragments.emplace_back(0, file->size);