Skip to content

Commit f8c6acd

Browse files
committed
Merge branch 'dev' into dev3
2 parents 54cedbd + 2451b56 commit f8c6acd

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

doc/mimalloc-doc.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,9 @@ Further options for large workloads and services:
12301230
the actual NUMA nodes is fine and will only cause threads to potentially allocate more memory across actual NUMA
12311231
nodes (but this can happen in any case as NUMA local allocation is always a best effort but not guaranteed).
12321232
- `MIMALLOC_ALLOW_LARGE_OS_PAGES=1`: use large OS pages (2 or 4MiB) when available; for some workloads this can significantly
1233-
improve performance. When this option is disabled, it also disables transparent huge pages (THP) for the process
1234-
(on Linux and Android). Use `MIMALLOC_VERBOSE` to check if the large OS pages are enabled -- usually one needs
1233+
improve performance. When this option is disabled (default), it also disables transparent huge pages (THP) for the process
1234+
(on Linux and Android). On Linux the default setting is 2 -- this enables the use of large pages through THP only.
1235+
Use `MIMALLOC_VERBOSE` to check if the large OS pages are enabled -- usually one needs
12351236
to explicitly give permissions for large OS pages (as on [Windows][windows-huge] and [Linux][linux-huge]). However, sometimes
12361237
the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that
12371238
can have fragmented memory (for that reason, we generally recommend to use `MIMALLOC_RESERVE_HUGE_OS_PAGES` instead whenever possible).

readme.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ is a general purpose allocator with excellent [performance](#performance) charac
1212
Initially developed by Daan Leijen for the runtime systems of the
1313
[Koka](https://koka-lang.github.io) and [Lean](https://github.com/leanprover/lean) languages.
1414

15-
Latest release tag: `v2.1.8` (2025-01-03).
16-
Latest v1 tag: `v1.8.8` (2024-01-03).
15+
Latest release tag: `v2.1.9` (2025-01-03).
16+
Latest v1 tag: `v1.8.9` (2024-01-03).
1717

1818
mimalloc is a drop-in replacement for `malloc` and can be used in other programs
1919
without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as:
@@ -81,7 +81,7 @@ Enjoy!
8181

8282
### Releases
8383

84-
* 2025-01-03, `v1.8.8`, `v2.1.8`, `v3.0-alpha`: Interim release. Support Windows arm64. New [guarded](#guarded) build that can place OS
84+
* 2025-01-03, `v1.8.9`, `v2.1.9`, `v3.0-alpha`: Interim release. Support Windows arm64. New [guarded](#guarded) build that can place OS
8585
guard pages behind objects to catch buffer overflows as they occur.
8686
Many small fixes: build on Windows arm64, cygwin, riscV, and dragonfly; fix Windows static library initialization to account for
8787
thread local destructors (in Rust/C++); macOS tag change; macOS TLS slot fix; improve stats;
@@ -342,9 +342,10 @@ Further options for large workloads and services:
342342
at runtime. Setting `N` to 1 may avoid problems in some virtual environments. Also, setting it to a lower number than
343343
the actual NUMA nodes is fine and will only cause threads to potentially allocate more memory across actual NUMA
344344
nodes (but this can happen in any case as NUMA local allocation is always a best effort but not guaranteed).
345-
- `MIMALLOC_ALLOW_LARGE_OS_PAGES=1`: use large OS pages (2 or 4MiB) when available; for some workloads this can significantly
346-
improve performance. When this option is disabled, it also disables transparent huge pages (THP) for the process
347-
(on Linux and Android). Use `MIMALLOC_VERBOSE` to check if the large OS pages are enabled -- usually one needs
345+
- `MIMALLOC_ALLOW_LARGE_OS_PAGES=0`: Set to 1 to use large OS pages (2 or 4MiB) when available; for some workloads this can significantly
346+
improve performance. When this option is disabled (default), it also disables transparent huge pages (THP) for the process
347+
(on Linux and Android). On Linux the default setting is 2 -- this enables the use of large pages through THP only.
348+
Use `MIMALLOC_VERBOSE` to check if the large OS pages are enabled -- usually one needs
348349
to explicitly give permissions for large OS pages (as on [Windows][windows-huge] and [Linux][linux-huge]). However, sometimes
349350
the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that
350351
can have fragmented memory (for that reason, we generally recommend to use `MIMALLOC_RESERVE_HUGE_OS_PAGES` instead whenever possible).

src/options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct mi_option_desc_s {
8080

8181
#ifndef MI_DEFAULT_ALLOW_LARGE_OS_PAGES
8282
#if defined(__linux__) && !defined(__ANDROID__)
83-
#define MI_DEFAULT_ALLOW_LARGE_OS_PAGES 1
83+
#define MI_DEFAULT_ALLOW_LARGE_OS_PAGES 2 // enabled, but only use transparent huge pages through madvise
8484
#else
8585
#define MI_DEFAULT_ALLOW_LARGE_OS_PAGES 0
8686
#endif

src/prim/unix/prim.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static void* unix_mmap(void* addr, size_t size, size_t try_alignment, int protec
273273
protect_flags |= PROT_MAX(PROT_READ | PROT_WRITE); // BSD
274274
#endif
275275
// huge page allocation
276-
if ((large_only || _mi_os_use_large_page(size, try_alignment)) && allow_large) {
276+
if (allow_large && (large_only || (_mi_os_use_large_page(size, try_alignment) && mi_option_get(mi_option_allow_large_os_pages) == 1))) {
277277
static _Atomic(size_t) large_page_try_ok; // = 0;
278278
size_t try_ok = mi_atomic_load_acquire(&large_page_try_ok);
279279
if (!large_only && try_ok > 0) {
@@ -294,7 +294,7 @@ static void* unix_mmap(void* addr, size_t size, size_t try_alignment, int protec
294294
#endif
295295
#ifdef MAP_HUGE_1GB
296296
static bool mi_huge_pages_available = true;
297-
if ((size % MI_GiB) == 0 && mi_huge_pages_available) {
297+
if (large_only && (size % MI_GiB) == 0 && mi_huge_pages_available) {
298298
lflags |= MAP_HUGE_1GB;
299299
}
300300
else
@@ -314,7 +314,9 @@ static void* unix_mmap(void* addr, size_t size, size_t try_alignment, int protec
314314
#ifdef MAP_HUGE_1GB
315315
if (p == NULL && (lflags & MAP_HUGE_1GB) == MAP_HUGE_1GB) {
316316
mi_huge_pages_available = false; // don't try huge 1GiB pages again
317-
_mi_warning_message("unable to allocate huge (1GiB) page, trying large (2MiB) pages instead (errno: %i)\n", errno);
317+
if (large_only) {
318+
_mi_warning_message("unable to allocate huge (1GiB) page, trying large (2MiB) pages instead (errno: %i)\n", errno);
319+
}
318320
lflags = ((lflags & ~MAP_HUGE_1GB) | MAP_HUGE_2MB);
319321
p = unix_mmap_prim(addr, size, try_alignment, protect_flags, lflags, lfd);
320322
}

0 commit comments

Comments
 (0)