From 2c9910cd992646d658c979e4c34b446143a7db04 Mon Sep 17 00:00:00 2001 From: trollkotze Date: Tue, 4 Apr 2023 01:52:15 +0200 Subject: [PATCH 1/2] Change mmap parameters to avoid much swap thrashing --- llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama.cpp b/llama.cpp index 854bb8993fbc5..80f89183fa45d 100644 --- a/llama.cpp +++ b/llama.cpp @@ -331,7 +331,7 @@ static void *mmap_file(const char *fname, uint64_t *mm_length) { int fd = open(fname, O_RDONLY); if (fd == -1) return 0; int64_t length = lseek(fd, 0, SEEK_END); - void *addr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); + void *addr = mmap(NULL, length, PROT_READ, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, fd, 0); close(fd); if (addr == MAP_FAILED) return 0; #endif From 6a4f137805404a550fef538b49155050c05a3db8 Mon Sep 17 00:00:00 2001 From: trollkotze Date: Tue, 4 Apr 2023 03:19:09 +0200 Subject: [PATCH 2/2] Fix wrongly copy-pasted mmap flags --- llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama.cpp b/llama.cpp index 80f89183fa45d..5e817a6f12dfb 100644 --- a/llama.cpp +++ b/llama.cpp @@ -331,7 +331,7 @@ static void *mmap_file(const char *fname, uint64_t *mm_length) { int fd = open(fname, O_RDONLY); if (fd == -1) return 0; int64_t length = lseek(fd, 0, SEEK_END); - void *addr = mmap(NULL, length, PROT_READ, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, fd, 0); + void *addr = mmap(NULL, length, PROT_READ, MAP_SHARED | MAP_ANONYMOUS | MAP_POPULATE, fd, 0); close(fd); if (addr == MAP_FAILED) return 0; #endif